@power-bots/powerbotlibrary 0.2.1 → 0.4.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/commands/other/config.d.ts +1 -0
- package/dist/commands/other/config.js +62 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +75 -0
- package/dist/main.d.ts +3 -1
- package/dist/main.js +45 -30
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const discord_js_1 = require("discord.js");
|
|
13
|
+
const main_1 = require("../../main");
|
|
14
|
+
const config_1 = require("../../config");
|
|
15
|
+
module.exports = {
|
|
16
|
+
data: new discord_js_1.SlashCommandBuilder()
|
|
17
|
+
.setName('config')
|
|
18
|
+
.setDescription('Manage config')
|
|
19
|
+
.addSubcommand(subcommand => subcommand
|
|
20
|
+
.setName("set")
|
|
21
|
+
.setDescription("Set config for a server or yourself (user)")
|
|
22
|
+
.addStringOption(option => option
|
|
23
|
+
.setName("setting")
|
|
24
|
+
.setDescription("The setting to set")
|
|
25
|
+
.setRequired(true))
|
|
26
|
+
.addStringOption(option => option
|
|
27
|
+
.setName("value")
|
|
28
|
+
.setDescription("The value of setting")
|
|
29
|
+
.setRequired(true))),
|
|
30
|
+
execute(interaction) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const subCommand = interaction.options.getSubcommand();
|
|
34
|
+
switch (subCommand) {
|
|
35
|
+
case "set":
|
|
36
|
+
const key = interaction.options.getString("setting");
|
|
37
|
+
const keyShort = key.substring(key.indexOf(".") + 1);
|
|
38
|
+
const value = interaction.options.getString("value");
|
|
39
|
+
const botConfigValues = (_a = main_1.bot.info) === null || _a === void 0 ? void 0 : _a.configs;
|
|
40
|
+
const scope = key.split(".")[0];
|
|
41
|
+
if (!scope ||
|
|
42
|
+
!botConfigValues ||
|
|
43
|
+
!((_b = botConfigValues[scope]) === null || _b === void 0 ? void 0 : _b.includes(keyShort)))
|
|
44
|
+
return yield interaction.reply({ content: `❌ Invalid Setting` });
|
|
45
|
+
let id;
|
|
46
|
+
switch (scope) {
|
|
47
|
+
case config_1.ConfigTypes.Guild:
|
|
48
|
+
id = interaction.guildId;
|
|
49
|
+
break;
|
|
50
|
+
case config_1.ConfigTypes.User:
|
|
51
|
+
id = interaction.user.id;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
config_1.Config.set(scope, id, key, value);
|
|
55
|
+
yield interaction.reply({ content: `✅ Set \`${key}\` to \`${value}\`` });
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
};
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Snowflake } from "discord.js";
|
|
2
|
+
export declare enum ConfigTypes {
|
|
3
|
+
Guild = "guild",
|
|
4
|
+
User = "user"
|
|
5
|
+
}
|
|
6
|
+
export declare class Config {
|
|
7
|
+
static setEvents: Map<string, Function>;
|
|
8
|
+
static getRaw(scope: ConfigTypes, id: Snowflake | string | number, key: string): Promise<any>;
|
|
9
|
+
static get(scope: ConfigTypes, id: Snowflake | string | number, key: string): Promise<any>;
|
|
10
|
+
static set(scope: ConfigTypes, id: Snowflake | string | number, key: string, value: string): Promise<void>;
|
|
11
|
+
static onSet(key: string, func: Function): Promise<void>;
|
|
12
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Config = exports.ConfigTypes = void 0;
|
|
13
|
+
const main_1 = require("./main");
|
|
14
|
+
var ConfigTypes;
|
|
15
|
+
(function (ConfigTypes) {
|
|
16
|
+
ConfigTypes["Guild"] = "guild";
|
|
17
|
+
ConfigTypes["User"] = "user";
|
|
18
|
+
})(ConfigTypes || (exports.ConfigTypes = ConfigTypes = {}));
|
|
19
|
+
class Config {
|
|
20
|
+
static getRaw(scope, id, key) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const valueRaw = yield (0, main_1.knex)("config").where({
|
|
23
|
+
scope: scope,
|
|
24
|
+
id: id,
|
|
25
|
+
key: key
|
|
26
|
+
}).first();
|
|
27
|
+
return valueRaw;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static get(scope, id, key) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const valueRaw = yield this.getRaw(scope, id, key);
|
|
33
|
+
const value = valueRaw === null || valueRaw === void 0 ? void 0 : valueRaw.value;
|
|
34
|
+
if (!value)
|
|
35
|
+
return null;
|
|
36
|
+
return value;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
static set(scope, id, key, value) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
const valueRaw = yield this.getRaw(scope, id, key);
|
|
42
|
+
if (valueRaw) {
|
|
43
|
+
yield (0, main_1.knex)("config").where({
|
|
44
|
+
scope: scope,
|
|
45
|
+
id: id,
|
|
46
|
+
key: key
|
|
47
|
+
}).update({
|
|
48
|
+
value: value
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
yield (0, main_1.knex)("config").insert({
|
|
53
|
+
scope: scope,
|
|
54
|
+
id: id,
|
|
55
|
+
key: key,
|
|
56
|
+
value: value
|
|
57
|
+
});
|
|
58
|
+
const event = this.setEvents.get(key);
|
|
59
|
+
if (event)
|
|
60
|
+
yield event({
|
|
61
|
+
scope: scope,
|
|
62
|
+
id: id,
|
|
63
|
+
key: key,
|
|
64
|
+
value: value
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
static onSet(key, func) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
this.setEvents.set(key, func);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.Config = Config;
|
|
75
|
+
Config.setEvents = new Map();
|
package/dist/main.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { knex } from "./db";
|
|
2
|
-
export
|
|
2
|
+
export { Config, ConfigTypes } from "./config";
|
|
3
|
+
declare class Bot {
|
|
3
4
|
log: any;
|
|
4
5
|
client: any;
|
|
5
6
|
commands: any;
|
|
6
7
|
commandsArray: any;
|
|
7
8
|
dirname: any;
|
|
9
|
+
info: any;
|
|
8
10
|
setup(dirname: any): Promise<void>;
|
|
9
11
|
run(): Promise<void>;
|
|
10
12
|
}
|
package/dist/main.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.bot = exports.
|
|
15
|
+
exports.bot = exports.ConfigTypes = exports.Config = exports.knex = void 0;
|
|
16
16
|
// IMPORTS
|
|
17
17
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
18
18
|
dotenv_1.default.config();
|
|
@@ -23,7 +23,42 @@ const log_1 = require("./log");
|
|
|
23
23
|
const db_1 = require("./db");
|
|
24
24
|
var db_2 = require("./db");
|
|
25
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
|
+
}
|
|
26
58
|
class Bot {
|
|
59
|
+
constructor() {
|
|
60
|
+
this.info = {};
|
|
61
|
+
}
|
|
27
62
|
setup(dirname) {
|
|
28
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
64
|
this.dirname = dirname;
|
|
@@ -51,6 +86,13 @@ class Bot {
|
|
|
51
86
|
process.exit();
|
|
52
87
|
}
|
|
53
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
|
+
}
|
|
54
96
|
// CREATE CLIENT
|
|
55
97
|
this.client = new discord_js_1.Client({ intents: [
|
|
56
98
|
discord_js_1.GatewayIntentBits.Guilds,
|
|
@@ -60,34 +102,8 @@ class Bot {
|
|
|
60
102
|
// IMPORT COMMANDS
|
|
61
103
|
this.commands = new discord_js_1.Collection();
|
|
62
104
|
this.commandsArray = [];
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const commandFolders = node_fs_1.default.readdirSync(foldersPath);
|
|
66
|
-
for (const folder of commandFolders) {
|
|
67
|
-
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
68
|
-
let commandFiles;
|
|
69
|
-
if (node_fs_1.default.statSync(commandsPath).isDirectory()) {
|
|
70
|
-
commandFiles = node_fs_1.default.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
commandFiles = [""];
|
|
74
|
-
}
|
|
75
|
-
for (const file of commandFiles) {
|
|
76
|
-
const filePath = node_path_1.default.join(commandsPath, file);
|
|
77
|
-
const command = require(filePath);
|
|
78
|
-
if ('data' in command && 'execute' in command) {
|
|
79
|
-
this.commands.set(command.data.name, command);
|
|
80
|
-
this.commandsArray.push(command.data.toJSON());
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
84
|
-
}
|
|
85
|
-
;
|
|
86
|
-
}
|
|
87
|
-
;
|
|
88
|
-
}
|
|
89
|
-
;
|
|
90
|
-
}
|
|
105
|
+
addCommandsFromPath(this, node_path_1.default.join(this.dirname, 'commands'));
|
|
106
|
+
addCommandsFromPath(this, node_path_1.default.join(__dirname, 'commands'));
|
|
91
107
|
// LOGIN CLIENT
|
|
92
108
|
this.client.once(discord_js_1.Events.ClientReady, (readyClient) => {
|
|
93
109
|
this.log.info(`Logged in as ${readyClient.user.tag}`);
|
|
@@ -141,5 +157,4 @@ class Bot {
|
|
|
141
157
|
});
|
|
142
158
|
}
|
|
143
159
|
}
|
|
144
|
-
exports.Bot = Bot;
|
|
145
160
|
exports.bot = new Bot();
|