@spatulox/simplediscordbot 1.0.30 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore_old +23 -0
- package/dist/index.d.mts +915 -0
- package/dist/index.d.ts +915 -17
- package/dist/index.js +2576 -36
- package/dist/index.mjs +2554 -0
- package/package.json +3 -2
- package/dist/SimpleDiscordBotInfo.d.ts +0 -8
- package/dist/SimpleDiscordBotInfo.js +0 -14
- package/dist/bot/Bot.d.ts +0 -35
- package/dist/bot/Bot.js +0 -92
- package/dist/bot/BotEnv.d.ts +0 -6
- package/dist/bot/BotEnv.js +0 -24
- package/dist/bot/BotInteraction.d.ts +0 -21
- package/dist/bot/BotInteraction.js +0 -74
- package/dist/bot/BotLog.d.ts +0 -52
- package/dist/bot/BotLog.js +0 -134
- package/dist/bot/BotMessage.d.ts +0 -20
- package/dist/bot/BotMessage.js +0 -110
- package/dist/manager/FileManager.d.ts +0 -37
- package/dist/manager/FileManager.js +0 -136
- package/dist/manager/builder/SendableComponentBuilder.d.ts +0 -3
- package/dist/manager/builder/SendableComponentBuilder.js +0 -63
- package/dist/manager/direct/BasicUserManager.d.ts +0 -28
- package/dist/manager/direct/BasicUserManager.js +0 -81
- package/dist/manager/direct/UserManager.d.ts +0 -6
- package/dist/manager/direct/UserManager.js +0 -18
- package/dist/manager/guild/ChannelManager/ForumChannelManager.d.ts +0 -9
- package/dist/manager/guild/ChannelManager/ForumChannelManager.js +0 -33
- package/dist/manager/guild/ChannelManager/GuildChannelList.d.ts +0 -17
- package/dist/manager/guild/ChannelManager/GuildChannelList.js +0 -20
- package/dist/manager/guild/ChannelManager/GuildChannelManager.d.ts +0 -18
- package/dist/manager/guild/ChannelManager/GuildChannelManager.js +0 -91
- package/dist/manager/guild/ChannelManager/GuildMessageManager.d.ts +0 -23
- package/dist/manager/guild/ChannelManager/GuildMessageManager.js +0 -93
- package/dist/manager/guild/ChannelManager/GuildTextChannelManager.d.ts +0 -9
- package/dist/manager/guild/ChannelManager/GuildTextChannelManager.js +0 -33
- package/dist/manager/guild/ChannelManager/GuildVoiceChannelManager.d.ts +0 -9
- package/dist/manager/guild/ChannelManager/GuildVoiceChannelManager.js +0 -33
- package/dist/manager/guild/ChannelManager/NewsChannelManager.d.ts +0 -9
- package/dist/manager/guild/ChannelManager/NewsChannelManager.js +0 -33
- package/dist/manager/guild/ChannelManager/StageChannelManager.d.ts +0 -9
- package/dist/manager/guild/ChannelManager/StageChannelManager.js +0 -33
- package/dist/manager/guild/ChannelManager/ThreadChannelManager.d.ts +0 -13
- package/dist/manager/guild/ChannelManager/ThreadChannelManager.js +0 -49
- package/dist/manager/guild/GuildManager.d.ts +0 -32
- package/dist/manager/guild/GuildManager.js +0 -144
- package/dist/manager/guild/GuildUserManager.d.ts +0 -49
- package/dist/manager/guild/GuildUserManager.js +0 -251
- package/dist/manager/guild/InviteManager.d.ts +0 -21
- package/dist/manager/guild/InviteManager.js +0 -68
- package/dist/manager/guild/InviteManager_old.d.ts +0 -24
- package/dist/manager/guild/InviteManager_old.js +0 -89
- package/dist/manager/guild/RoleManager.d.ts +0 -24
- package/dist/manager/guild/RoleManager.js +0 -83
- package/dist/manager/interactions/ModalManager.d.ts +0 -23
- package/dist/manager/interactions/ModalManager.js +0 -113
- package/dist/manager/interactions/SelectMenuManager.d.ts +0 -58
- package/dist/manager/interactions/SelectMenuManager.js +0 -123
- package/dist/manager/messages/EmbedManager.d.ts +0 -97
- package/dist/manager/messages/EmbedManager.js +0 -161
- package/dist/manager/messages/ReactionManager.d.ts +0 -26
- package/dist/manager/messages/ReactionManager.js +0 -99
- package/dist/manager/messages/WebhookManager.d.ts +0 -33
- package/dist/manager/messages/WebhookManager.js +0 -108
- package/dist/test/client.d.ts +0 -3
- package/dist/test/client.js +0 -15
- package/dist/test/index.d.ts +0 -2
- package/dist/test/index.js +0 -31
- package/dist/test/randomActivityList.d.ts +0 -3
- package/dist/test/randomActivityList.js +0 -9
- package/dist/type/FolderName.d.ts +0 -2
- package/dist/type/FolderName.js +0 -10
- package/dist/utils/DiscordRegex.d.ts +0 -66
- package/dist/utils/DiscordRegex.js +0 -117
- package/dist/utils/Log.d.ts +0 -9
- package/dist/utils/Log.js +0 -28
- package/dist/utils/SimpleMutex.d.ts +0 -16
- package/dist/utils/SimpleMutex.js +0 -39
- package/dist/utils/network/InternetChecker.d.ts +0 -10
- package/dist/utils/network/InternetChecker.js +0 -54
- package/dist/utils/times/UnitTime.d.ts +0 -187
- package/dist/utils/times/UnitTime.js +0 -85
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { TextChannel, Message, ThreadChannel, WebhookMessageCreateOptions } from 'discord.js';
|
|
2
|
-
import { SendableComponent } from "../builder/SendableComponentBuilder";
|
|
3
|
-
export declare class WebhookManager {
|
|
4
|
-
private readonly channel;
|
|
5
|
-
private readonly name;
|
|
6
|
-
private readonly avatarURL?;
|
|
7
|
-
private webhook;
|
|
8
|
-
constructor(channel: TextChannel | ThreadChannel, name?: string, avatarURL?: string | undefined);
|
|
9
|
-
private get textChannel();
|
|
10
|
-
/**
|
|
11
|
-
* Get or create webhook (lazy initialization)
|
|
12
|
-
*/
|
|
13
|
-
private getWebhook;
|
|
14
|
-
/**
|
|
15
|
-
* Send message/text/component !
|
|
16
|
-
*/
|
|
17
|
-
send(content: string): Promise<Message | null>;
|
|
18
|
-
send(content: SendableComponent): Promise<Message | null>;
|
|
19
|
-
send(content: WebhookMessageCreateOptions): Promise<Message | null>;
|
|
20
|
-
/**
|
|
21
|
-
* Quick success embed
|
|
22
|
-
*/
|
|
23
|
-
success(message: string): Promise<Message | null>;
|
|
24
|
-
/**
|
|
25
|
-
* Quick error embed
|
|
26
|
-
*/
|
|
27
|
-
error(message: string): Promise<Message | null>;
|
|
28
|
-
/**
|
|
29
|
-
* Delete webhook
|
|
30
|
-
*/
|
|
31
|
-
delete(reason?: string): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=WebhookManager.d.ts.map
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebhookManager = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
const EmbedManager_1 = require("./EmbedManager");
|
|
6
|
-
const Log_1 = require("../../utils/Log");
|
|
7
|
-
const Bot_1 = require("../../bot/Bot");
|
|
8
|
-
const SendableComponentBuilder_1 = require("../builder/SendableComponentBuilder");
|
|
9
|
-
class WebhookManager {
|
|
10
|
-
constructor(channel, name = Bot_1.Bot.config.botName || "", avatarURL) {
|
|
11
|
-
this.channel = channel;
|
|
12
|
-
this.name = name;
|
|
13
|
-
this.avatarURL = avatarURL;
|
|
14
|
-
this.webhook = null;
|
|
15
|
-
}
|
|
16
|
-
get textChannel() {
|
|
17
|
-
return this.channel instanceof discord_js_1.ThreadChannel
|
|
18
|
-
? this.channel.parent
|
|
19
|
-
: this.channel;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Get or create webhook (lazy initialization)
|
|
23
|
-
*/
|
|
24
|
-
async getWebhook() {
|
|
25
|
-
if (this.webhook)
|
|
26
|
-
return this.webhook;
|
|
27
|
-
try {
|
|
28
|
-
const webhooks = await this.textChannel.fetchWebhooks();
|
|
29
|
-
this.webhook = webhooks.find(h => h.name === this.name) ??
|
|
30
|
-
await this.textChannel.createWebhook({
|
|
31
|
-
name: this.name,
|
|
32
|
-
avatar: this.avatarURL,
|
|
33
|
-
reason: 'Auto-created by WebhookManager'
|
|
34
|
-
});
|
|
35
|
-
Log_1.Log.info(`Webhook ${this.webhook.id} ready for ${this.textChannel.id}`);
|
|
36
|
-
return this.webhook;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
Log_1.Log.error(`Failed to setup webhook: ${error}`);
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async send(content) {
|
|
44
|
-
const webhook = await this.getWebhook();
|
|
45
|
-
const options = {};
|
|
46
|
-
if (SendableComponentBuilder_1.SendableComponentBuilder.isSendableComponent(content)) {
|
|
47
|
-
const t = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content);
|
|
48
|
-
options.embeds = t.embeds;
|
|
49
|
-
options.components = t.components;
|
|
50
|
-
}
|
|
51
|
-
else if (typeof content == 'string') {
|
|
52
|
-
options.content = content;
|
|
53
|
-
}
|
|
54
|
-
else if (typeof content === 'object') {
|
|
55
|
-
Object.assign(options, content);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
options.content = content;
|
|
59
|
-
}
|
|
60
|
-
if (this.channel instanceof discord_js_1.ThreadChannel) {
|
|
61
|
-
options.threadId = this.channel.id;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const message = await webhook.send(options);
|
|
65
|
-
Log_1.Log.info(`Webhook sent to ${this.channel.id}: ${content}`);
|
|
66
|
-
return message;
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
Log_1.Log.error(`Webhook send failed ${this.channel.id}: ${error}`);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Quick success embed
|
|
75
|
-
*/
|
|
76
|
-
async success(message) {
|
|
77
|
-
return await this.send(EmbedManager_1.EmbedManager.success(message));
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Quick error embed
|
|
81
|
-
*/
|
|
82
|
-
async error(message) {
|
|
83
|
-
return await this.send(EmbedManager_1.EmbedManager.error(message));
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Delete webhook
|
|
87
|
-
*/
|
|
88
|
-
async delete(reason) {
|
|
89
|
-
if (!this.webhook)
|
|
90
|
-
return;
|
|
91
|
-
try {
|
|
92
|
-
await this.webhook.delete(reason ?? 'Deleted by WebhookManager');
|
|
93
|
-
Log_1.Log.info(`Webhook ${this.webhook.id} deleted`);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
if (error.message.includes('Unknown Webhook')) {
|
|
97
|
-
Log_1.Log.warn('Webhook already deleted');
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
Log_1.Log.error(`Failed to delete webhook: ${error}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
finally {
|
|
104
|
-
this.webhook = null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.WebhookManager = WebhookManager;
|
package/dist/test/client.d.ts
DELETED
package/dist/test/client.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.client = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
exports.client = new discord_js_1.Client({ intents: [
|
|
6
|
-
discord_js_1.GatewayIntentBits.Guilds,
|
|
7
|
-
discord_js_1.GatewayIntentBits.GuildMembers,
|
|
8
|
-
discord_js_1.GatewayIntentBits.GuildMessages,
|
|
9
|
-
discord_js_1.GatewayIntentBits.MessageContent,
|
|
10
|
-
discord_js_1.GatewayIntentBits.GuildMessageReactions,
|
|
11
|
-
discord_js_1.GatewayIntentBits.DirectMessageReactions,
|
|
12
|
-
discord_js_1.GatewayIntentBits.DirectMessages
|
|
13
|
-
],
|
|
14
|
-
partials: [discord_js_1.Partials.Channel]
|
|
15
|
-
});
|
package/dist/test/index.d.ts
DELETED
package/dist/test/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
|
-
const index_1 = require("../index");
|
|
8
|
-
const client_1 = require("./client");
|
|
9
|
-
const discord_js_1 = require("discord.js");
|
|
10
|
-
const randomActivityList_1 = require("./randomActivityList");
|
|
11
|
-
dotenv_1.default.config();
|
|
12
|
-
async function main() {
|
|
13
|
-
const config = {
|
|
14
|
-
defaultEmbedColor: index_1.EmbedColor.blue, // (When embed are created with EmbedManager)
|
|
15
|
-
botName: "Simple Discord Bot", // The name of the bot
|
|
16
|
-
log: {
|
|
17
|
-
logChannelId: "1162047096220827831",
|
|
18
|
-
errorChannelId: "1162047096220827831",
|
|
19
|
-
info: { console: true, discord: true },
|
|
20
|
-
error: { console: true, discord: true },
|
|
21
|
-
warn: { console: true, discord: true },
|
|
22
|
-
debug: { console: true, discord: true },
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const bot = new index_1.Bot(client_1.client, config);
|
|
26
|
-
bot.client.on(discord_js_1.Events.ClientReady, async () => {
|
|
27
|
-
index_1.Bot.setRandomActivity(randomActivityList_1.randomActivityList, index_1.Time.minute.MIN_10.toMilliseconds());
|
|
28
|
-
});
|
|
29
|
-
// After that, you can implement what you want
|
|
30
|
-
}
|
|
31
|
-
main();
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.randomActivityList = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
exports.randomActivityList = [
|
|
6
|
-
{ type: discord_js_1.ActivityType.Playing, message: "a normal game" },
|
|
7
|
-
{ type: discord_js_1.ActivityType.Playing, message: "a hard game" },
|
|
8
|
-
{ type: discord_js_1.ActivityType.Playing, message: "a weird game" }
|
|
9
|
-
];
|
package/dist/type/FolderName.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FolderName = void 0;
|
|
4
|
-
/** @internal */
|
|
5
|
-
var FolderName;
|
|
6
|
-
(function (FolderName) {
|
|
7
|
-
FolderName["SLASH_COMMANDS"] = "commands";
|
|
8
|
-
FolderName["CONTEXT_MENU"] = "context_menu";
|
|
9
|
-
FolderName["MODAL"] = "modals";
|
|
10
|
-
})(FolderName || (exports.FolderName = FolderName = {}));
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Classe utilitaire pour valider tous les formats Discord avec regex
|
|
3
|
-
*/
|
|
4
|
-
export declare class DiscordRegex {
|
|
5
|
-
static readonly SPACE = "\u200B";
|
|
6
|
-
static readonly URL_REGEX: RegExp;
|
|
7
|
-
static readonly USER_REGEX: RegExp;
|
|
8
|
-
static readonly BOT_REGEX: RegExp;
|
|
9
|
-
static readonly CHANNEL_REGEX: RegExp;
|
|
10
|
-
static readonly ROLE_REGEX: RegExp;
|
|
11
|
-
/**
|
|
12
|
-
* Mention a User
|
|
13
|
-
* Mention a Role
|
|
14
|
-
*/
|
|
15
|
-
static readonly DISCORD_PING_REGEX: RegExp;
|
|
16
|
-
/**
|
|
17
|
-
* Mention a User
|
|
18
|
-
* Mention a Role
|
|
19
|
-
* Mention a Channel
|
|
20
|
-
*/
|
|
21
|
-
static readonly DISCORD_MENTION_REGEX: RegExp;
|
|
22
|
-
static readonly USER_ID: RegExp;
|
|
23
|
-
static readonly CHANNEL_ID: RegExp;
|
|
24
|
-
static readonly GUILD_ID: RegExp;
|
|
25
|
-
static readonly BOT_ID: RegExp;
|
|
26
|
-
static readonly USERNAME: RegExp;
|
|
27
|
-
static readonly USERNAME_DISCRIM: RegExp;
|
|
28
|
-
static readonly CHANNEL_MENTION: RegExp;
|
|
29
|
-
static readonly USER_MENTION: RegExp;
|
|
30
|
-
static readonly ROLE_MENTION: RegExp;
|
|
31
|
-
static readonly INVITE: RegExp;
|
|
32
|
-
static readonly EMOJI: RegExp;
|
|
33
|
-
/**
|
|
34
|
-
* Validate Discord ID Discord (18)
|
|
35
|
-
*/
|
|
36
|
-
static isDiscordId(id: string): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Validate a bot ID (19)
|
|
39
|
-
*/
|
|
40
|
-
static isBotMention(mention: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Validate a User ping
|
|
43
|
-
*/
|
|
44
|
-
static isUserMention(mention: string): boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Validate a Discord username
|
|
47
|
-
*/
|
|
48
|
-
static isUsername(username: string): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Type guard for Discord ID
|
|
51
|
-
*/
|
|
52
|
-
static isDiscordIdType(id: string): id is string;
|
|
53
|
-
/**
|
|
54
|
-
* Any Discord URL
|
|
55
|
-
*/
|
|
56
|
-
static isDiscordUrl(url: string): boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Any discord mention
|
|
59
|
-
*/
|
|
60
|
-
static isAnyMention(text: string): boolean;
|
|
61
|
-
/**
|
|
62
|
-
* List all regex
|
|
63
|
-
*/
|
|
64
|
-
static listAll(): Record<string, RegExp | string>;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=DiscordRegex.d.ts.map
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.DiscordRegex = void 0;
|
|
5
|
-
/**
|
|
6
|
-
* Classe utilitaire pour valider tous les formats Discord avec regex
|
|
7
|
-
*/
|
|
8
|
-
class DiscordRegex {
|
|
9
|
-
/**
|
|
10
|
-
* Validate Discord ID Discord (18)
|
|
11
|
-
*/
|
|
12
|
-
static isDiscordId(id) {
|
|
13
|
-
return this.USER_ID.test(id) || this.GUILD_ID.test(id) || this.CHANNEL_ID.test(id);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Validate a bot ID (19)
|
|
17
|
-
*/
|
|
18
|
-
static isBotMention(mention) {
|
|
19
|
-
return this.BOT_REGEX.test(mention);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Validate a User ping
|
|
23
|
-
*/
|
|
24
|
-
static isUserMention(mention) {
|
|
25
|
-
return this.USER_REGEX.test(mention);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Validate a Discord username
|
|
29
|
-
*/
|
|
30
|
-
static isUsername(username) {
|
|
31
|
-
return this.USERNAME.test(username);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Type guard for Discord ID
|
|
35
|
-
*/
|
|
36
|
-
static isDiscordIdType(id) {
|
|
37
|
-
return this.isDiscordId(id);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Any Discord URL
|
|
41
|
-
*/
|
|
42
|
-
static isDiscordUrl(url) {
|
|
43
|
-
return this.URL_REGEX.test(url) || this.INVITE.test(url);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Any discord mention
|
|
47
|
-
*/
|
|
48
|
-
static isAnyMention(text) {
|
|
49
|
-
return this.DISCORD_MENTION_REGEX.test(text);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* List all regex
|
|
53
|
-
*/
|
|
54
|
-
static listAll() {
|
|
55
|
-
return {
|
|
56
|
-
SPACE: this.SPACE,
|
|
57
|
-
URL_REGEX: this.URL_REGEX,
|
|
58
|
-
USER_REGEX: this.USER_REGEX,
|
|
59
|
-
BOT_REGEX: this.BOT_REGEX,
|
|
60
|
-
CHANNEL_REGEX: this.CHANNEL_REGEX,
|
|
61
|
-
ROLE_REGEX: this.ROLE_REGEX,
|
|
62
|
-
DISCORD_PING_REGEX: this.DISCORD_PING_REGEX,
|
|
63
|
-
DISCORD_MENTION_REGEX: this.DISCORD_MENTION_REGEX,
|
|
64
|
-
USER_ID: this.USER_ID,
|
|
65
|
-
CHANNEL_ID: this.CHANNEL_ID,
|
|
66
|
-
GUILD_ID: this.GUILD_ID,
|
|
67
|
-
USERNAME: this.USERNAME,
|
|
68
|
-
USERNAME_DISCRIM: this.USERNAME_DISCRIM,
|
|
69
|
-
CHANNEL_MENTION: this.CHANNEL_MENTION,
|
|
70
|
-
USER_MENTION: this.USER_MENTION,
|
|
71
|
-
ROLE_MENTION: this.ROLE_MENTION,
|
|
72
|
-
INVITE: this.INVITE,
|
|
73
|
-
EMOJI: this.EMOJI
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.DiscordRegex = DiscordRegex;
|
|
78
|
-
_a = DiscordRegex;
|
|
79
|
-
// Caractères spéciaux
|
|
80
|
-
DiscordRegex.SPACE = "\u200B";
|
|
81
|
-
// URLs basiques
|
|
82
|
-
DiscordRegex.URL_REGEX = /(https?:\/\/[^s]+)/;
|
|
83
|
-
/* DISCORD REGEX */
|
|
84
|
-
DiscordRegex.USER_REGEX = /<@\d{18}>/;
|
|
85
|
-
DiscordRegex.BOT_REGEX = /<@\d{19}>/;
|
|
86
|
-
DiscordRegex.CHANNEL_REGEX = /(<#\d{19}>)|(<id:(browse|customize|guide)>)/;
|
|
87
|
-
DiscordRegex.ROLE_REGEX = /<@&\d{19}>/;
|
|
88
|
-
/**
|
|
89
|
-
* Mention a User
|
|
90
|
-
* Mention a Role
|
|
91
|
-
*/
|
|
92
|
-
DiscordRegex.DISCORD_PING_REGEX = new RegExp(`(${_a.USER_REGEX.source})|(${_a.BOT_REGEX.source})|(${_a.ROLE_REGEX.source})`);
|
|
93
|
-
/**
|
|
94
|
-
* Mention a User
|
|
95
|
-
* Mention a Role
|
|
96
|
-
* Mention a Channel
|
|
97
|
-
*/
|
|
98
|
-
DiscordRegex.DISCORD_MENTION_REGEX = new RegExp(`(${_a.DISCORD_PING_REGEX.source})|(${_a.CHANNEL_REGEX.source})`);
|
|
99
|
-
// ID Discord (user, channel guild)
|
|
100
|
-
DiscordRegex.USER_ID = /^[0-9]{18}$/;
|
|
101
|
-
DiscordRegex.CHANNEL_ID = /^[0-9]{18}$/;
|
|
102
|
-
DiscordRegex.GUILD_ID = /^[0-9]{19}$/;
|
|
103
|
-
DiscordRegex.BOT_ID = /^[0-9]{19}$/;
|
|
104
|
-
// Username Discord (2-32 caractères alphanumériques + _ .)
|
|
105
|
-
DiscordRegex.USERNAME = /^[a-zA-Z0-9_]{2,32}$/;
|
|
106
|
-
// Username + discrim (ancien format)
|
|
107
|
-
DiscordRegex.USERNAME_DISCRIM = /^[a-zA-Z0-9_]{2,32}#\d{4}$/;
|
|
108
|
-
// Channel mention <#123456789012345678>
|
|
109
|
-
DiscordRegex.CHANNEL_MENTION = /^<#([0-9]{18})>$/;
|
|
110
|
-
// User mention <@123456789012345678> ou <@!123456789012345678>
|
|
111
|
-
DiscordRegex.USER_MENTION = /^<@!?([0-9]{18})>$/;
|
|
112
|
-
// Role mention <@&123456789012345678>
|
|
113
|
-
DiscordRegex.ROLE_MENTION = /^<@&([0-9]{18})>$/;
|
|
114
|
-
// URL Invite Discord
|
|
115
|
-
DiscordRegex.INVITE = /^discord(?:app\.com\/invite|gg)\/[a-zA-Z0-9]+$/;
|
|
116
|
-
// Emoji Discord (custom or unicode)
|
|
117
|
-
DiscordRegex.EMOJI = /^<a?:[a-zA-Z0-9_]{2,32}:[0-9]{18}>$|^[\u{1F300}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]+$/u;
|
package/dist/utils/Log.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare class Log {
|
|
2
|
-
private static getPrefix;
|
|
3
|
-
static info(message: string): void;
|
|
4
|
-
static warn(message: string): void;
|
|
5
|
-
static error(message: string): void;
|
|
6
|
-
static debug(message: string): void;
|
|
7
|
-
static table(data: Record<string, any>[]): void;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=Log.d.ts.map
|
package/dist/utils/Log.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Log = void 0;
|
|
4
|
-
class Log {
|
|
5
|
-
static getPrefix(level) {
|
|
6
|
-
const now = new Date();
|
|
7
|
-
const timestamp = `[${now.toLocaleDateString()} - ${now.toLocaleTimeString()}]`;
|
|
8
|
-
return `${timestamp} [${level.toUpperCase()}]`;
|
|
9
|
-
}
|
|
10
|
-
static info(message) {
|
|
11
|
-
console.info(`${this.getPrefix('info')} ${message}`);
|
|
12
|
-
}
|
|
13
|
-
static warn(message) {
|
|
14
|
-
console.warn(`${this.getPrefix('warn')} ${message}`);
|
|
15
|
-
}
|
|
16
|
-
static error(message) {
|
|
17
|
-
console.error(`${this.getPrefix('error')} ${message}`);
|
|
18
|
-
}
|
|
19
|
-
static debug(message) {
|
|
20
|
-
console.debug(`${this.getPrefix('debug')} ${message}`);
|
|
21
|
-
}
|
|
22
|
-
static table(data) {
|
|
23
|
-
const prefix = this.getPrefix('table');
|
|
24
|
-
console.info(`${prefix} Table output:`);
|
|
25
|
-
console.table(data);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.Log = Log;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare class SimpleMutex {
|
|
2
|
-
private _locked;
|
|
3
|
-
private queue;
|
|
4
|
-
constructor();
|
|
5
|
-
/**
|
|
6
|
-
* Verrouille le mutex. Si le mutex est déjà verrouillé, la méthode retourne une promesse qui sera résolue une fois que le mutex sera disponible.
|
|
7
|
-
* @returns Une promesse résolue lorsque le mutex est verrouillé.
|
|
8
|
-
*/
|
|
9
|
-
lock(): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Déverrouille le mutex. Si une file d'attente existe, débloque le prochain élément dans la file.
|
|
12
|
-
*/
|
|
13
|
-
unlock(): void;
|
|
14
|
-
get locked(): boolean;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=SimpleMutex.d.ts.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleMutex = void 0;
|
|
4
|
-
class SimpleMutex {
|
|
5
|
-
constructor() {
|
|
6
|
-
this._locked = false;
|
|
7
|
-
this.queue = [];
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Verrouille le mutex. Si le mutex est déjà verrouillé, la méthode retourne une promesse qui sera résolue une fois que le mutex sera disponible.
|
|
11
|
-
* @returns Une promesse résolue lorsque le mutex est verrouillé.
|
|
12
|
-
*/
|
|
13
|
-
async lock() {
|
|
14
|
-
if (this._locked) {
|
|
15
|
-
return new Promise((resolve) => {
|
|
16
|
-
this.queue.push(resolve);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
this._locked = true;
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Déverrouille le mutex. Si une file d'attente existe, débloque le prochain élément dans la file.
|
|
24
|
-
*/
|
|
25
|
-
unlock() {
|
|
26
|
-
if (this.queue.length > 0) {
|
|
27
|
-
const nextResolve = this.queue.shift();
|
|
28
|
-
if (nextResolve) {
|
|
29
|
-
nextResolve(); // Résout la promesse du prochain élément dans la file
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this._locked = false; // Déverrouille complètement si la file d'attente est vide
|
|
34
|
-
}
|
|
35
|
-
get locked() {
|
|
36
|
-
return this._locked;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.SimpleMutex = SimpleMutex;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare class InternetChecker {
|
|
2
|
-
private static readonly TARGET;
|
|
3
|
-
private static readonly RETRY_TIME;
|
|
4
|
-
/**
|
|
5
|
-
* Check internet connection towards 1.1.1.1 (Cloudflare DNS)
|
|
6
|
-
* @param tries Number of attempts (0 = infini)
|
|
7
|
-
*/
|
|
8
|
-
static checkConnection(tries?: number): Promise<boolean>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=InternetChecker.d.ts.map
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InternetChecker = void 0;
|
|
4
|
-
const Log_1 = require("../Log");
|
|
5
|
-
const UnitTime_1 = require("../times/UnitTime");
|
|
6
|
-
class InternetChecker {
|
|
7
|
-
/**
|
|
8
|
-
* Check internet connection towards 1.1.1.1 (Cloudflare DNS)
|
|
9
|
-
* @param tries Number of attempts (0 = infini)
|
|
10
|
-
*/
|
|
11
|
-
static async checkConnection(tries = 0) {
|
|
12
|
-
let attempt = 0;
|
|
13
|
-
Log_1.Log.info(tries > 0
|
|
14
|
-
? `HTTP ping ${this.TARGET} (max ${tries} attempts)...`
|
|
15
|
-
: `HTTP ping ${this.TARGET} (infinite attempts)...`);
|
|
16
|
-
while (tries === 0 || attempt < tries) {
|
|
17
|
-
try {
|
|
18
|
-
const controller = new AbortController();
|
|
19
|
-
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5s timeout
|
|
20
|
-
const response = await fetch(this.TARGET, {
|
|
21
|
-
method: 'HEAD',
|
|
22
|
-
signal: controller.signal,
|
|
23
|
-
cache: 'no-store'
|
|
24
|
-
});
|
|
25
|
-
clearTimeout(timeoutId);
|
|
26
|
-
if (response.ok) {
|
|
27
|
-
const latency = response.headers.get('x-response-time') || '<1ms';
|
|
28
|
-
Log_1.Log.info(`Internet connection OK (${latency})`);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
attempt++;
|
|
34
|
-
const errorMsg = error.name === 'AbortError'
|
|
35
|
-
? 'Timeout (5s)'
|
|
36
|
-
: error.message || 'Unknown';
|
|
37
|
-
Log_1.Log.warn(tries > 0
|
|
38
|
-
? `Ping failed (${errorMsg}) - Attempt ${attempt}/${tries}`
|
|
39
|
-
: `Ping failed (${errorMsg}) - Retrying in ${this.RETRY_TIME.toSeconds()} seconds...`);
|
|
40
|
-
try {
|
|
41
|
-
await new Promise(resolve => setTimeout(resolve, this.RETRY_TIME.toMilliseconds()));
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
Log_1.Log.error('Retry delay failed.');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
Log_1.Log.error(`No response from ${this.TARGET} after all attempts.`);
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.InternetChecker = InternetChecker;
|
|
53
|
-
InternetChecker.TARGET = 'https://1.1.1.1'; // Cloudflare DNS HTTPS
|
|
54
|
-
InternetChecker.RETRY_TIME = UnitTime_1.Time.second.SEC_30;
|