@power-bots/powerbotlibrary 0.4.0 → 0.5.0
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/dist/bot.d.ts +17 -0
- package/dist/bot.js +211 -0
- package/dist/lang.d.ts +11 -0
- package/dist/lang.js +88 -0
- package/dist/main.d.ts +2 -10
- package/dist/main.js +8 -155
- package/package.json +1 -1
package/dist/bot.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Snowflake, Guild, Role, GuildBasedChannel } from 'discord.js';
|
|
2
|
+
export { knex } from "./db";
|
|
3
|
+
export { Config, ConfigTypes } from "./config";
|
|
4
|
+
export declare class Bot {
|
|
5
|
+
log: any;
|
|
6
|
+
client: any;
|
|
7
|
+
commands: any;
|
|
8
|
+
commandsArray: any;
|
|
9
|
+
dirname: any;
|
|
10
|
+
info: any;
|
|
11
|
+
setup(dirname: any): Promise<void>;
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
resolveGuild(guild: Guild | Snowflake): Promise<Guild | null>;
|
|
14
|
+
getGuild(id: Snowflake): Promise<Guild | null>;
|
|
15
|
+
getRole(id: Snowflake, guild: Guild | Snowflake): Promise<Role | null>;
|
|
16
|
+
getGuildChannel(id: Snowflake, guild: Guild | Snowflake): Promise<GuildBasedChannel | null>;
|
|
17
|
+
}
|
package/dist/bot.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Bot = exports.ConfigTypes = exports.Config = exports.knex = void 0;
|
|
16
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
17
|
+
dotenv_1.default.config();
|
|
18
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
19
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
20
|
+
const discord_js_1 = require("discord.js");
|
|
21
|
+
const log_1 = require("./log");
|
|
22
|
+
const db_1 = require("./db");
|
|
23
|
+
const lang_1 = require("./lang");
|
|
24
|
+
var db_2 = require("./db");
|
|
25
|
+
Object.defineProperty(exports, "knex", { enumerable: true, get: function () { return db_2.knex; } });
|
|
26
|
+
var config_1 = require("./config");
|
|
27
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
28
|
+
Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return config_1.ConfigTypes; } });
|
|
29
|
+
function addCommandsFromPath(bot, foldersPath) {
|
|
30
|
+
if (node_fs_1.default.existsSync(foldersPath)) {
|
|
31
|
+
const commandFolders = node_fs_1.default.readdirSync(foldersPath);
|
|
32
|
+
for (const folder of commandFolders) {
|
|
33
|
+
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
34
|
+
let commandFiles;
|
|
35
|
+
if (node_fs_1.default.statSync(commandsPath).isDirectory()) {
|
|
36
|
+
commandFiles = node_fs_1.default.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
commandFiles = [""];
|
|
40
|
+
}
|
|
41
|
+
for (const file of commandFiles) {
|
|
42
|
+
const filePath = node_path_1.default.join(commandsPath, file);
|
|
43
|
+
const command = require(filePath);
|
|
44
|
+
if ('data' in command && 'execute' in command) {
|
|
45
|
+
bot.commands.set(command.data.name, command);
|
|
46
|
+
bot.commandsArray.push(command.data.toJSON());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
bot.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
50
|
+
}
|
|
51
|
+
;
|
|
52
|
+
}
|
|
53
|
+
;
|
|
54
|
+
}
|
|
55
|
+
;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
class Bot {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.info = {};
|
|
61
|
+
}
|
|
62
|
+
setup(dirname) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
this.dirname = dirname;
|
|
65
|
+
yield (0, db_1.setupDatabase)();
|
|
66
|
+
yield (0, db_1.updateDatabase)();
|
|
67
|
+
yield lang_1.Lang.setup();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
run() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
this.log = new log_1.Log();
|
|
73
|
+
if (!this.dirname) {
|
|
74
|
+
this.log.error(`Bot was not setup.`);
|
|
75
|
+
process.exit();
|
|
76
|
+
}
|
|
77
|
+
this.log.info("Press Control+C to stop the bot");
|
|
78
|
+
// ENVIROMENT VARS
|
|
79
|
+
if (!node_fs_1.default.existsSync(".env")) {
|
|
80
|
+
this.log.error(`No .env file is in the directory. Please add one`);
|
|
81
|
+
process.exit();
|
|
82
|
+
}
|
|
83
|
+
;
|
|
84
|
+
const botToken = process.env.DISCORD_TOKEN;
|
|
85
|
+
if (botToken == undefined) {
|
|
86
|
+
this.log.error(`The \"DISCORD_TOKEN\" wasn't found in the .env file.\nIt can be added with: \"DISCORD_TOKEN=mytokenhere\"`);
|
|
87
|
+
process.exit();
|
|
88
|
+
}
|
|
89
|
+
;
|
|
90
|
+
// READ BOT.JSON
|
|
91
|
+
const botJsonLocation = node_path_1.default.join(this.dirname, "bot.json");
|
|
92
|
+
if (node_fs_1.default.existsSync(botJsonLocation)) {
|
|
93
|
+
node_fs_1.default.readFile(botJsonLocation, { encoding: "utf-8" }, (err, data) => {
|
|
94
|
+
this.info = JSON.parse(data);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// CREATE CLIENT
|
|
98
|
+
this.client = new discord_js_1.Client({ intents: [
|
|
99
|
+
discord_js_1.GatewayIntentBits.Guilds,
|
|
100
|
+
discord_js_1.GatewayIntentBits.GuildMessages,
|
|
101
|
+
discord_js_1.GatewayIntentBits.MessageContent
|
|
102
|
+
] });
|
|
103
|
+
// IMPORT COMMANDS
|
|
104
|
+
this.commands = new discord_js_1.Collection();
|
|
105
|
+
this.commandsArray = [];
|
|
106
|
+
addCommandsFromPath(this, node_path_1.default.join(this.dirname, 'commands'));
|
|
107
|
+
addCommandsFromPath(this, node_path_1.default.join(__dirname, 'commands'));
|
|
108
|
+
// LOGIN CLIENT
|
|
109
|
+
this.client.once(discord_js_1.Events.ClientReady, (readyClient) => {
|
|
110
|
+
this.log.info(`Logged in as ${readyClient.user.tag}`);
|
|
111
|
+
// REGISTER COMMANDS
|
|
112
|
+
if (this.commandsArray.length === 0)
|
|
113
|
+
return;
|
|
114
|
+
const rest = new discord_js_1.REST().setToken(botToken);
|
|
115
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
try {
|
|
117
|
+
this.log.info(`Started refreshing ${this.commandsArray.length} application (/) commands.`);
|
|
118
|
+
const data = yield rest.put(discord_js_1.Routes.applicationCommands(readyClient.user.id), { body: this.commandsArray });
|
|
119
|
+
this.log.info(`Successfully reloaded ${data.length} application (/) commands.`);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
this.log.error(`${error}`);
|
|
123
|
+
}
|
|
124
|
+
;
|
|
125
|
+
}))();
|
|
126
|
+
});
|
|
127
|
+
this.log.info("Logging in");
|
|
128
|
+
this.client.login(botToken);
|
|
129
|
+
// RECEIVE COMMANDS
|
|
130
|
+
this.client.on(discord_js_1.Events.InteractionCreate, (interaction) => __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
try {
|
|
132
|
+
if (interaction.isChatInputCommand()) {
|
|
133
|
+
const command = this.commands.get(interaction.commandName);
|
|
134
|
+
if (!command) {
|
|
135
|
+
this.log.error(`No command matching ${interaction.commandName} was found.`);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
;
|
|
139
|
+
yield command.execute(interaction);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.log.error(`${error}`);
|
|
146
|
+
const errorMessage = { content: 'There was an error while executing this command!', flags: [discord_js_1.MessageFlags.Ephemeral] };
|
|
147
|
+
if (interaction.replied || interaction.deferred) {
|
|
148
|
+
yield interaction.followUp(errorMessage);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
yield interaction.reply(errorMessage);
|
|
152
|
+
}
|
|
153
|
+
;
|
|
154
|
+
}
|
|
155
|
+
;
|
|
156
|
+
return;
|
|
157
|
+
}));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
resolveGuild(guild) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
let _guild;
|
|
163
|
+
if (typeof guild === "string") {
|
|
164
|
+
_guild = yield this.getGuild(guild);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
_guild = guild;
|
|
168
|
+
}
|
|
169
|
+
if (!_guild)
|
|
170
|
+
return null;
|
|
171
|
+
return _guild;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
getGuild(id) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
try {
|
|
177
|
+
return yield this.client.guilds.fetch(id);
|
|
178
|
+
}
|
|
179
|
+
catch (_a) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
getRole(id, guild) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
let _guild = yield this.resolveGuild(guild);
|
|
187
|
+
if (!_guild)
|
|
188
|
+
return null;
|
|
189
|
+
try {
|
|
190
|
+
return yield _guild.roles.fetch(id);
|
|
191
|
+
}
|
|
192
|
+
catch (_a) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
getGuildChannel(id, guild) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
let _guild = yield this.resolveGuild(guild);
|
|
200
|
+
if (!_guild)
|
|
201
|
+
return null;
|
|
202
|
+
try {
|
|
203
|
+
return yield _guild.channels.fetch(id);
|
|
204
|
+
}
|
|
205
|
+
catch (_a) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.Bot = Bot;
|
package/dist/lang.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommandInteraction } from "discord.js";
|
|
2
|
+
export declare function reply(interaction: CommandInteraction, text: string, args?: Record<string, any>): Promise<void>;
|
|
3
|
+
export declare class Lang {
|
|
4
|
+
texts: any;
|
|
5
|
+
static en: Lang;
|
|
6
|
+
static embed: Lang;
|
|
7
|
+
constructor(lang: string);
|
|
8
|
+
static get folder(): string;
|
|
9
|
+
static setup(): Promise<void>;
|
|
10
|
+
get(text: string, args?: Record<string, any>): Promise<any>;
|
|
11
|
+
}
|
package/dist/lang.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Lang = void 0;
|
|
16
|
+
exports.reply = reply;
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const main_1 = require("./main");
|
|
20
|
+
const discord_js_1 = require("discord.js");
|
|
21
|
+
function localize(obj, lang, args) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (typeof obj === "string") {
|
|
24
|
+
if (obj.startsWith("$"))
|
|
25
|
+
return lang.get(obj.replace("$", ""), args) || obj;
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(obj)) {
|
|
29
|
+
return obj.map((item) => __awaiter(this, void 0, void 0, function* () { return yield localize(item, lang, args); }));
|
|
30
|
+
}
|
|
31
|
+
if (typeof obj === "object" && obj !== null) {
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
34
|
+
if (key === "options")
|
|
35
|
+
break;
|
|
36
|
+
result[key] = yield localize(value, lang, args);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
return obj;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function reply(interaction, text, args) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
var _a;
|
|
46
|
+
const embed = yield Lang.embed.get(text);
|
|
47
|
+
let flags = [];
|
|
48
|
+
if ((_a = embed === null || embed === void 0 ? void 0 : embed.options) === null || _a === void 0 ? void 0 : _a.ephemeral)
|
|
49
|
+
flags.push(discord_js_1.MessageFlags.Ephemeral);
|
|
50
|
+
const newEmbed = yield localize(embed, Lang.en, args);
|
|
51
|
+
yield interaction.reply({ embeds: [newEmbed], flags: flags });
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
class Lang {
|
|
55
|
+
constructor(lang) {
|
|
56
|
+
const langFileLocation = path_1.default.join(Lang.folder, `${lang}.json`);
|
|
57
|
+
if (fs_1.default.existsSync(langFileLocation)) {
|
|
58
|
+
fs_1.default.readFile(langFileLocation, { encoding: "utf-8" }, (err, data) => {
|
|
59
|
+
this.texts = JSON.parse(data);
|
|
60
|
+
return;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
this.texts = null;
|
|
64
|
+
}
|
|
65
|
+
static get folder() {
|
|
66
|
+
return path_1.default.join(main_1.bot.dirname, "lang");
|
|
67
|
+
}
|
|
68
|
+
static setup() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
Lang.embed = new Lang("embed");
|
|
71
|
+
Lang.en = new Lang("en");
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
get(text, args) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
let newText = this.texts[text];
|
|
77
|
+
if (typeof newText === "string") {
|
|
78
|
+
if (args) {
|
|
79
|
+
for (const [name, value] of Object.entries(args)) {
|
|
80
|
+
newText = newText.replace(`{{${name}}}`, value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return newText;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.Lang = Lang;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
+
import { Bot } from "./bot";
|
|
1
2
|
export { knex } from "./db";
|
|
2
3
|
export { Config, ConfigTypes } from "./config";
|
|
3
|
-
|
|
4
|
-
log: any;
|
|
5
|
-
client: any;
|
|
6
|
-
commands: any;
|
|
7
|
-
commandsArray: any;
|
|
8
|
-
dirname: any;
|
|
9
|
-
info: any;
|
|
10
|
-
setup(dirname: any): Promise<void>;
|
|
11
|
-
run(): Promise<void>;
|
|
12
|
-
}
|
|
4
|
+
export { Lang, reply } from "./lang";
|
|
13
5
|
export declare const bot: Bot;
|
package/dist/main.js
CHANGED
|
@@ -1,160 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.bot = exports.ConfigTypes = exports.Config = exports.knex = void 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
20
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
21
|
-
const discord_js_1 = require("discord.js");
|
|
22
|
-
const log_1 = require("./log");
|
|
23
|
-
const db_1 = require("./db");
|
|
24
|
-
var db_2 = require("./db");
|
|
25
|
-
Object.defineProperty(exports, "knex", { enumerable: true, get: function () { return db_2.knex; } });
|
|
3
|
+
exports.bot = exports.reply = exports.Lang = exports.ConfigTypes = exports.Config = exports.knex = void 0;
|
|
4
|
+
const bot_1 = require("./bot");
|
|
5
|
+
var db_1 = require("./db");
|
|
6
|
+
Object.defineProperty(exports, "knex", { enumerable: true, get: function () { return db_1.knex; } });
|
|
26
7
|
var config_1 = require("./config");
|
|
27
8
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
28
9
|
Object.defineProperty(exports, "ConfigTypes", { enumerable: true, get: function () { return config_1.ConfigTypes; } });
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
34
|
-
let commandFiles;
|
|
35
|
-
if (node_fs_1.default.statSync(commandsPath).isDirectory()) {
|
|
36
|
-
commandFiles = node_fs_1.default.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
commandFiles = [""];
|
|
40
|
-
}
|
|
41
|
-
for (const file of commandFiles) {
|
|
42
|
-
const filePath = node_path_1.default.join(commandsPath, file);
|
|
43
|
-
const command = require(filePath);
|
|
44
|
-
if ('data' in command && 'execute' in command) {
|
|
45
|
-
bot.commands.set(command.data.name, command);
|
|
46
|
-
bot.commandsArray.push(command.data.toJSON());
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
bot.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
50
|
-
}
|
|
51
|
-
;
|
|
52
|
-
}
|
|
53
|
-
;
|
|
54
|
-
}
|
|
55
|
-
;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
class Bot {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.info = {};
|
|
61
|
-
}
|
|
62
|
-
setup(dirname) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
this.dirname = dirname;
|
|
65
|
-
yield (0, db_1.setupDatabase)();
|
|
66
|
-
yield (0, db_1.updateDatabase)();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
run() {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
this.log = new log_1.Log();
|
|
72
|
-
if (!this.dirname) {
|
|
73
|
-
this.log.error(`Bot was not setup.`);
|
|
74
|
-
process.exit();
|
|
75
|
-
}
|
|
76
|
-
this.log.info("Press Control+C to stop the bot");
|
|
77
|
-
// ENVIROMENT VARS
|
|
78
|
-
if (!node_fs_1.default.existsSync(".env")) {
|
|
79
|
-
this.log.error(`No .env file is in the directory. Please add one`);
|
|
80
|
-
process.exit();
|
|
81
|
-
}
|
|
82
|
-
;
|
|
83
|
-
const botToken = process.env.DISCORD_TOKEN;
|
|
84
|
-
if (botToken == undefined) {
|
|
85
|
-
this.log.error(`The \"DISCORD_TOKEN\" wasn't found in the .env file.\nIt can be added with: \"DISCORD_TOKEN=mytokenhere\"`);
|
|
86
|
-
process.exit();
|
|
87
|
-
}
|
|
88
|
-
;
|
|
89
|
-
// READ BOT.JSON
|
|
90
|
-
const botJsonLocation = node_path_1.default.join(this.dirname, "bot.json");
|
|
91
|
-
if (node_fs_1.default.existsSync(botJsonLocation)) {
|
|
92
|
-
node_fs_1.default.readFile(botJsonLocation, { encoding: "utf-8" }, (err, data) => {
|
|
93
|
-
this.info = JSON.parse(data);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
// CREATE CLIENT
|
|
97
|
-
this.client = new discord_js_1.Client({ intents: [
|
|
98
|
-
discord_js_1.GatewayIntentBits.Guilds,
|
|
99
|
-
discord_js_1.GatewayIntentBits.GuildMessages,
|
|
100
|
-
discord_js_1.GatewayIntentBits.MessageContent
|
|
101
|
-
] });
|
|
102
|
-
// IMPORT COMMANDS
|
|
103
|
-
this.commands = new discord_js_1.Collection();
|
|
104
|
-
this.commandsArray = [];
|
|
105
|
-
addCommandsFromPath(this, node_path_1.default.join(this.dirname, 'commands'));
|
|
106
|
-
addCommandsFromPath(this, node_path_1.default.join(__dirname, 'commands'));
|
|
107
|
-
// LOGIN CLIENT
|
|
108
|
-
this.client.once(discord_js_1.Events.ClientReady, (readyClient) => {
|
|
109
|
-
this.log.info(`Logged in as ${readyClient.user.tag}`);
|
|
110
|
-
// REGISTER COMMANDS
|
|
111
|
-
if (this.commandsArray.length === 0)
|
|
112
|
-
return;
|
|
113
|
-
const rest = new discord_js_1.REST().setToken(botToken);
|
|
114
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
try {
|
|
116
|
-
this.log.info(`Started refreshing ${this.commandsArray.length} application (/) commands.`);
|
|
117
|
-
const data = yield rest.put(discord_js_1.Routes.applicationCommands(readyClient.user.id), { body: this.commandsArray });
|
|
118
|
-
this.log.info(`Successfully reloaded ${data.length} application (/) commands.`);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
this.log.error(`${error}`);
|
|
122
|
-
}
|
|
123
|
-
;
|
|
124
|
-
}))();
|
|
125
|
-
});
|
|
126
|
-
this.log.info("Logging in");
|
|
127
|
-
this.client.login(botToken);
|
|
128
|
-
// RECEIVE COMMANDS
|
|
129
|
-
this.client.on(discord_js_1.Events.InteractionCreate, (interaction) => __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
try {
|
|
131
|
-
if (interaction.isChatInputCommand()) {
|
|
132
|
-
const command = this.commands.get(interaction.commandName);
|
|
133
|
-
if (!command) {
|
|
134
|
-
this.log.error(`No command matching ${interaction.commandName} was found.`);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
;
|
|
138
|
-
yield command.execute(interaction);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
;
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
this.log.error(`${error}`);
|
|
145
|
-
const errorMessage = { content: 'There was an error while executing this command!', flags: [discord_js_1.MessageFlags.Ephemeral] };
|
|
146
|
-
if (interaction.replied || interaction.deferred) {
|
|
147
|
-
yield interaction.followUp(errorMessage);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
yield interaction.reply(errorMessage);
|
|
151
|
-
}
|
|
152
|
-
;
|
|
153
|
-
}
|
|
154
|
-
;
|
|
155
|
-
return;
|
|
156
|
-
}));
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.bot = new Bot();
|
|
10
|
+
var lang_1 = require("./lang");
|
|
11
|
+
Object.defineProperty(exports, "Lang", { enumerable: true, get: function () { return lang_1.Lang; } });
|
|
12
|
+
Object.defineProperty(exports, "reply", { enumerable: true, get: function () { return lang_1.reply; } });
|
|
13
|
+
exports.bot = new bot_1.Bot();
|