reciple 1.0.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/bin/bin.js ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ const Config_1 = require("./reciple/classes/Config");
14
+ const Client_1 = require("./reciple/classes/Client");
15
+ const fs_1 = require("fs");
16
+ const fallout_utility_1 = require("fallout-utility");
17
+ if ((0, fs_1.readdirSync)('./').length > 0 && !(0, fs_1.existsSync)('./reciple.yml')) {
18
+ const ask = (0, fallout_utility_1.input)('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ');
19
+ if (ask !== 'y')
20
+ process.exit(0);
21
+ }
22
+ const config = new Config_1.RecipleConfig('./reciple.yml').parseConfig().getConfig();
23
+ const client = new Client_1.RecipleClient(Object.assign({ config: config }, config.client));
24
+ (() => __awaiter(void 0, void 0, void 0, function* () {
25
+ yield client.startModules();
26
+ client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
27
+ var _a;
28
+ client.logger.warn(`Logged in as ${((_a = client.user) === null || _a === void 0 ? void 0 : _a.tag) || 'Unknown'}!`);
29
+ yield client.loadModules();
30
+ client.addCommandListeners();
31
+ }));
32
+ client.login(config.token);
33
+ }))();
package/bin/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from './reciple/classes/Client';
2
+ export * from './reciple/classes/Config';
3
+ export * from './reciple/classes/builders/MessageCommandBuilder';
4
+ export * from './reciple/classes/builders/InteractionCommandBuilder';
5
+ export * from './reciple/commandPermissions';
6
+ export * from './reciple/flags';
7
+ export * from './reciple/logger';
8
+ export * from './reciple/modules';
9
+ export * from './reciple/registerInteractionCommands';
10
+ export * from './reciple/version';
package/bin/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./reciple/classes/Client"), exports);
18
+ __exportStar(require("./reciple/classes/Config"), exports);
19
+ __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
20
+ __exportStar(require("./reciple/classes/builders/InteractionCommandBuilder"), exports);
21
+ __exportStar(require("./reciple/commandPermissions"), exports);
22
+ __exportStar(require("./reciple/flags"), exports);
23
+ __exportStar(require("./reciple/logger"), exports);
24
+ __exportStar(require("./reciple/modules"), exports);
25
+ __exportStar(require("./reciple/registerInteractionCommands"), exports);
26
+ __exportStar(require("./reciple/version"), exports);
@@ -0,0 +1,34 @@
1
+ import { Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
2
+ import { Logger as LoggerConstructor } from 'fallout-utility';
3
+ import { MessageCommandBuilder, RecipleMessageCommandExecute } from './builders/MessageCommandBuilder';
4
+ import { InteractionCommandBuilder, RecipleInteractionCommandExecute } from './builders/InteractionCommandBuilder';
5
+ import { RecipleScript } from '../modules';
6
+ import { Config } from './Config';
7
+ export interface RecipleClientOptions extends ClientOptions {
8
+ config: Config;
9
+ }
10
+ export interface RecipleClientCommands {
11
+ MESSAGE_COMMANDS: {
12
+ [key: string]: MessageCommandBuilder;
13
+ };
14
+ INTERACTION_COMMANDS: {
15
+ [key: string]: InteractionCommandBuilder;
16
+ };
17
+ }
18
+ export interface RecipleClientEvents extends ClientEvents {
19
+ recipleMessageCommandCreate: [command: RecipleMessageCommandExecute];
20
+ recipleInteractionCommandCreate: [command: RecipleInteractionCommandExecute];
21
+ }
22
+ export declare class RecipleClient extends Client {
23
+ config?: Config;
24
+ commands: RecipleClientCommands;
25
+ modules: RecipleScript[];
26
+ logger: LoggerConstructor;
27
+ version: string;
28
+ constructor(options: RecipleClientOptions);
29
+ startModules(): Promise<RecipleClient>;
30
+ loadModules(): Promise<RecipleClient>;
31
+ addCommandListeners(): RecipleClient;
32
+ messageCommandExecute(message: Message): Promise<RecipleClient>;
33
+ interactionCommandExecute(interaction: Interaction): Promise<RecipleClient>;
34
+ }
@@ -0,0 +1,131 @@
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.RecipleClient = void 0;
13
+ const discord_js_1 = require("discord.js");
14
+ const fallout_utility_1 = require("fallout-utility");
15
+ const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
16
+ const InteractionCommandBuilder_1 = require("./builders/InteractionCommandBuilder");
17
+ const registerInteractionCommands_1 = require("../registerInteractionCommands");
18
+ const logger_1 = require("../logger");
19
+ const modules_1 = require("../modules");
20
+ const version_1 = require("../version");
21
+ const commandPermissions_1 = require("../commandPermissions");
22
+ class RecipleClient extends discord_js_1.Client {
23
+ constructor(options) {
24
+ super(options);
25
+ this.commands = { MESSAGE_COMMANDS: {}, INTERACTION_COMMANDS: {} };
26
+ this.modules = [];
27
+ this.logger = (0, logger_1.logger)(false);
28
+ this.version = version_1.version;
29
+ if (!options.config)
30
+ throw new Error('Config is not defined.');
31
+ this.config = options.config;
32
+ if (this.config.fileLogging.enabled)
33
+ this.logger.logFile(this.config.fileLogging.logFilePath, false);
34
+ this.logger.info('Reciple Client v' + version_1.version + ' is starting...');
35
+ }
36
+ startModules() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ this.logger.info('Loading modules...');
39
+ const modules = yield (0, modules_1.loadModules)(this);
40
+ if (!modules)
41
+ throw new Error('Failed to load modules.');
42
+ this.modules = modules.modules.map(m => m.script);
43
+ for (const command of modules.commands) {
44
+ if (!command.name)
45
+ continue;
46
+ if (command instanceof MessageCommandBuilder_1.MessageCommandBuilder) {
47
+ this.commands.MESSAGE_COMMANDS[command.name] = command;
48
+ }
49
+ else if (command instanceof InteractionCommandBuilder_1.InteractionCommandBuilder) {
50
+ this.commands.INTERACTION_COMMANDS[command.name] = command;
51
+ }
52
+ }
53
+ this.logger.info(`${Object.keys(this.commands.MESSAGE_COMMANDS).length} message commands loaded.`);
54
+ this.logger.info(`${Object.keys(this.commands.INTERACTION_COMMANDS).length} interaction commands loaded.`);
55
+ return this;
56
+ });
57
+ }
58
+ loadModules() {
59
+ var _a;
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ for (const module_ of this.modules) {
62
+ if (typeof (module_ === null || module_ === void 0 ? void 0 : module_.onLoad) === 'function')
63
+ yield Promise.resolve(module_.onLoad(this));
64
+ }
65
+ this.logger.info(`${this.modules.length} modules loaded.`);
66
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.registerCommands)
67
+ yield (0, registerInteractionCommands_1.registerInteractionCommands)(this);
68
+ return this;
69
+ });
70
+ }
71
+ addCommandListeners() {
72
+ var _a, _b;
73
+ if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.commands.messageCommand.enabled)
74
+ this.on('messageCreate', (message) => { this.messageCommandExecute(message); });
75
+ if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.commands.interactionCommand.enabled)
76
+ this.on('interactionCreate', (interaction) => { this.interactionCommandExecute(interaction); });
77
+ return this;
78
+ }
79
+ messageCommandExecute(message) {
80
+ var _a, _b, _c, _d, _e;
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ if (!message.content)
83
+ return this;
84
+ const parseCommand = (0, fallout_utility_1.getCommand)(message.content, ((_a = this.config) === null || _a === void 0 ? void 0 : _a.prefix) || '!', ((_b = this.config) === null || _b === void 0 ? void 0 : _b.commands.messageCommand.commandArgumentSeparator) || ' ');
85
+ if (parseCommand && parseCommand.command) {
86
+ const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
87
+ if (command && (0, commandPermissions_1.commandPermissions)(command.name, ((_c = message.member) === null || _c === void 0 ? void 0 : _c.permissions) || null, (_d = this.config) === null || _d === void 0 ? void 0 : _d.permissions.messageCommands)) {
88
+ if (!command.allowExecuteInDM && message.channel.type === 'DM')
89
+ return this;
90
+ if (!command.allowExecuteByBots && (message.author.bot || message.author.system))
91
+ return this;
92
+ if (command.validateOptions && !command.getCommandOptionValues(parseCommand)) {
93
+ yield message.reply(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.notEnoughArguments) || 'Not enough arguments.').catch((err) => this.logger.error(err));
94
+ return this;
95
+ }
96
+ const options = {
97
+ message: message,
98
+ command: parseCommand,
99
+ builder: command,
100
+ client: this
101
+ };
102
+ yield Promise.resolve(command.execute(options));
103
+ this.emit('recipleMessageCommandCreate', options);
104
+ }
105
+ }
106
+ return this;
107
+ });
108
+ }
109
+ interactionCommandExecute(interaction) {
110
+ var _a;
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ if (!interaction || !interaction.isCommand())
113
+ return this;
114
+ const command = this.commands.INTERACTION_COMMANDS[interaction.commandName];
115
+ if (command && (0, commandPermissions_1.commandPermissions)(command.name, interaction.memberPermissions, (_a = this.config) === null || _a === void 0 ? void 0 : _a.permissions.interactionCommands)) {
116
+ if (!command.allowExecuteInDM && interaction.member === null)
117
+ return this;
118
+ const options = {
119
+ interaction: interaction,
120
+ command: command,
121
+ builder: command,
122
+ client: this
123
+ };
124
+ yield Promise.resolve(command.execute(options));
125
+ this.emit('recipleInteractionCommandCreate', options);
126
+ }
127
+ return this;
128
+ });
129
+ }
130
+ }
131
+ exports.RecipleClient = RecipleClient;
@@ -0,0 +1,55 @@
1
+ import { ClientOptions, MessageOptions, PermissionResolvable } from 'discord.js';
2
+ export interface Config {
3
+ token: string;
4
+ prefix: string;
5
+ commands: {
6
+ messageCommand: {
7
+ enabled: boolean;
8
+ commandArgumentSeparator: string;
9
+ };
10
+ interactionCommand: {
11
+ enabled: boolean;
12
+ registerCommands: boolean;
13
+ guilds: string[] | string;
14
+ };
15
+ };
16
+ permissions: {
17
+ messageCommands: {
18
+ enabled: boolean;
19
+ commands: {
20
+ command: string;
21
+ permissions: PermissionResolvable[];
22
+ }[];
23
+ };
24
+ interactionCommands: {
25
+ enabled: boolean;
26
+ commands: {
27
+ command: string;
28
+ permissions: PermissionResolvable[];
29
+ }[];
30
+ };
31
+ };
32
+ ignoredChannels: {
33
+ enabled: boolean;
34
+ convertToAllowList: boolean;
35
+ channels: string[];
36
+ };
37
+ fileLogging: {
38
+ enabled: boolean;
39
+ logFilePath: string;
40
+ };
41
+ client: ClientOptions;
42
+ messages: {
43
+ [key: string]: MessageOptions | string;
44
+ };
45
+ modulesFolder: string;
46
+ }
47
+ export declare class RecipleConfig {
48
+ config?: Config;
49
+ configPath: string;
50
+ constructor(configPath: string);
51
+ parseConfig(): RecipleConfig;
52
+ getConfig(): Config;
53
+ parseToken(askIfNull?: boolean): string | null;
54
+ private askToken;
55
+ }
@@ -0,0 +1,68 @@
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
+ exports.RecipleConfig = void 0;
7
+ const fallout_utility_1 = require("fallout-utility");
8
+ const fs_1 = require("fs");
9
+ const flags_1 = require("../flags");
10
+ const path_1 = __importDefault(require("path"));
11
+ const yaml_1 = __importDefault(require("yaml"));
12
+ class RecipleConfig {
13
+ constructor(configPath) {
14
+ this.configPath = './reciple.yml';
15
+ if (!configPath)
16
+ throw new Error('Config path is not defined');
17
+ this.configPath = configPath;
18
+ }
19
+ parseConfig() {
20
+ if (!(0, fs_1.existsSync)(this.configPath)) {
21
+ const defaultConfigPath = path_1.default.join(__dirname, '../../../resource/reciple.yml');
22
+ if (!(0, fs_1.existsSync)(defaultConfigPath))
23
+ throw new Error('Default Config file not found. Please reinstall Reciple.');
24
+ const defaultConfig = (0, fs_1.readFileSync)(defaultConfigPath, 'utf-8');
25
+ (0, fs_1.writeFileSync)(this.configPath, defaultConfig, 'utf-8');
26
+ if (!(0, fs_1.existsSync)(this.configPath))
27
+ throw new Error('Failed to create config file.');
28
+ this.config = yaml_1.default.parse(defaultConfig);
29
+ if (this.config && this.config.token === 'TOKEN') {
30
+ this.config.token = this.askToken() || this.config.token;
31
+ (0, fs_1.writeFileSync)(this.configPath, (0, fallout_utility_1.replaceAll)(defaultConfig, 'TOKEN', this.config.token), 'utf-8');
32
+ }
33
+ return this;
34
+ }
35
+ if (!(0, fs_1.existsSync)(this.configPath))
36
+ throw new Error('Failed to read config file.');
37
+ const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
38
+ this.config = yaml_1.default.parse(config);
39
+ return this;
40
+ }
41
+ getConfig() {
42
+ if (!this.config)
43
+ throw new Error('Config is not parsed.');
44
+ this.config.token = this.parseToken() || 'TOKEN';
45
+ return this.config;
46
+ }
47
+ parseToken(askIfNull = true) {
48
+ let token = flags_1.token || null;
49
+ if (token)
50
+ return token;
51
+ if (!this.config)
52
+ return token;
53
+ if (!this.config.token)
54
+ return token || (askIfNull ? this.askToken() : null);
55
+ const envToken = this.config.token.toString().split(':');
56
+ if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
57
+ token = process.env[envToken[1]] || null;
58
+ }
59
+ else {
60
+ token = this.config.token;
61
+ }
62
+ return token || (askIfNull ? this.askToken() : null);
63
+ }
64
+ askToken() {
65
+ return flags_1.token || (0, fallout_utility_1.input)({ 'text': 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, exitStrings: ['exit', 'quit', ''], sigint: true }) || null;
66
+ }
67
+ }
68
+ exports.RecipleConfig = RecipleConfig;
@@ -0,0 +1,15 @@
1
+ import { SlashCommandBuilder } from '@discordjs/builders';
2
+ import { CommandInteraction } from 'discord.js';
3
+ import { RecipleClient } from '../Client';
4
+ export interface RecipleInteractionCommandExecute {
5
+ interaction: CommandInteraction;
6
+ command: InteractionCommandBuilder;
7
+ builder: InteractionCommandBuilder;
8
+ client: RecipleClient;
9
+ }
10
+ export declare class InteractionCommandBuilder extends SlashCommandBuilder {
11
+ allowExecuteInDM: boolean;
12
+ execute: (options: RecipleInteractionCommandExecute) => void;
13
+ setAllowExecuteInDM(allowExecuteInDM: boolean): InteractionCommandBuilder;
14
+ setExecute(execute: (options: RecipleInteractionCommandExecute) => void): InteractionCommandBuilder;
15
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InteractionCommandBuilder = void 0;
4
+ const builders_1 = require("@discordjs/builders");
5
+ class InteractionCommandBuilder extends builders_1.SlashCommandBuilder {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.allowExecuteInDM = true;
9
+ this.execute = (options) => { };
10
+ }
11
+ setAllowExecuteInDM(allowExecuteInDM) {
12
+ if (typeof allowExecuteInDM !== 'boolean')
13
+ throw new Error('allowExecuteInDM must be a boolean.');
14
+ this.allowExecuteInDM = allowExecuteInDM;
15
+ return this;
16
+ }
17
+ setExecute(execute) {
18
+ if (!execute || typeof execute !== 'function')
19
+ throw new Error('execute must be a function.');
20
+ this.execute = execute;
21
+ return this;
22
+ }
23
+ }
24
+ exports.InteractionCommandBuilder = InteractionCommandBuilder;
@@ -0,0 +1,47 @@
1
+ import { Message } from 'discord.js';
2
+ import { RecipleClient } from '../Client';
3
+ export interface CommandMessage {
4
+ command?: string;
5
+ args?: string[];
6
+ raw?: string;
7
+ prefix?: string;
8
+ separator?: string;
9
+ }
10
+ export interface RecipleMessageCommandExecute {
11
+ message: Message;
12
+ command: CommandMessage;
13
+ builder: MessageCommandBuilder;
14
+ client: RecipleClient;
15
+ }
16
+ export interface MessageCommandValidatedOption {
17
+ name: string;
18
+ value: any;
19
+ required: boolean;
20
+ }
21
+ export declare class MessageOption {
22
+ name: string;
23
+ description: string;
24
+ required: boolean;
25
+ validate: (value: any) => boolean;
26
+ setName(name: string): MessageOption;
27
+ setDescription(description: string): MessageOption;
28
+ setRequired(required: boolean): MessageOption;
29
+ setValidator(validator: (value: any) => boolean): MessageOption;
30
+ }
31
+ export declare class MessageCommandBuilder {
32
+ name: string;
33
+ description: string;
34
+ options: MessageOption[];
35
+ validateOptions: boolean;
36
+ allowExecuteInDM: boolean;
37
+ allowExecuteByBots: boolean;
38
+ execute: (options: RecipleMessageCommandExecute) => void;
39
+ setName(name: string): MessageCommandBuilder;
40
+ setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
41
+ setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
42
+ setDescription(description: string): MessageCommandBuilder;
43
+ setExecute(execute: (options: RecipleMessageCommandExecute) => void): MessageCommandBuilder;
44
+ addOption(option: MessageOption | ((constructor: MessageOption) => MessageOption)): MessageCommandBuilder;
45
+ setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
46
+ getCommandOptionValues(options: CommandMessage): undefined | MessageCommandValidatedOption[];
47
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageCommandBuilder = exports.MessageOption = void 0;
4
+ class MessageOption {
5
+ constructor() {
6
+ this.name = '';
7
+ this.description = '';
8
+ this.required = true;
9
+ this.validate = () => true;
10
+ }
11
+ setName(name) {
12
+ if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
13
+ throw new Error('name must be a string and match the regex /^[\\w-]{1,32}$/.');
14
+ this.name = name;
15
+ return this;
16
+ }
17
+ setDescription(description) {
18
+ if (!description || typeof description !== 'string')
19
+ throw new Error('description must be a string.');
20
+ this.description = description;
21
+ return this;
22
+ }
23
+ setRequired(required) {
24
+ if (typeof required !== 'boolean')
25
+ throw new Error('required must be a boolean.');
26
+ this.required = required;
27
+ return this;
28
+ }
29
+ setValidator(validator) {
30
+ if (!validator || typeof validator !== 'function')
31
+ throw new Error('validator must be a function.');
32
+ this.validate = validator;
33
+ return this;
34
+ }
35
+ }
36
+ exports.MessageOption = MessageOption;
37
+ class MessageCommandBuilder {
38
+ constructor() {
39
+ this.name = '';
40
+ this.description = '';
41
+ this.options = [];
42
+ this.validateOptions = false;
43
+ this.allowExecuteInDM = true;
44
+ this.allowExecuteByBots = false;
45
+ this.execute = (options) => { };
46
+ }
47
+ setName(name) {
48
+ if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
49
+ throw new Error('name must be a string and match the regex /^[\\w-]{1,32}$/');
50
+ this.name = name;
51
+ return this;
52
+ }
53
+ setAllowExecuteInDM(allowExecuteInDM) {
54
+ if (typeof allowExecuteInDM !== 'boolean')
55
+ throw new Error('allowExecuteInDM must be a boolean.');
56
+ this.allowExecuteInDM = allowExecuteInDM;
57
+ return this;
58
+ }
59
+ setAllowExecuteByBots(allowExecuteByBots) {
60
+ if (typeof allowExecuteByBots !== 'boolean')
61
+ throw new Error('allowExecuteByBots must be a boolean.');
62
+ this.allowExecuteByBots = allowExecuteByBots;
63
+ return this;
64
+ }
65
+ setDescription(description) {
66
+ if (!description || typeof description !== 'string')
67
+ throw new Error('description must be a string.');
68
+ this.description = description;
69
+ return this;
70
+ }
71
+ setExecute(execute) {
72
+ if (!execute || typeof execute !== 'function')
73
+ throw new Error('execute must be a function.');
74
+ this.execute = execute;
75
+ return this;
76
+ }
77
+ addOption(option) {
78
+ if (!option)
79
+ throw new Error('option must be a MessageOption.');
80
+ option = typeof option === 'function' ? option(new MessageOption()) : option;
81
+ if (this.options.find(o => o.name === option.name))
82
+ throw new Error('option with name "' + option.name + '" already exists.');
83
+ if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
84
+ throw new Error('All required options must be before optional options.');
85
+ this.options = [...this.options, option];
86
+ return this;
87
+ }
88
+ setValidateOptions(validateOptions) {
89
+ if (typeof validateOptions !== 'boolean')
90
+ throw new Error('validateOptions must be a boolean.');
91
+ this.validateOptions = validateOptions;
92
+ return this;
93
+ }
94
+ getCommandOptionValues(options) {
95
+ const args = options.args || [];
96
+ const required = this.options.filter(o => o.required);
97
+ const optional = this.options.filter(o => !o.required);
98
+ if (required.length > args.length)
99
+ return;
100
+ let i = 0;
101
+ let result = [];
102
+ for (const option of [...required, ...optional]) {
103
+ const arg = args[i];
104
+ if (!arg && option.required)
105
+ return;
106
+ if (!option.validate(arg))
107
+ return;
108
+ result = [...result, { name: option.name, value: arg, required: option.required }];
109
+ i++;
110
+ }
111
+ return result;
112
+ }
113
+ }
114
+ exports.MessageCommandBuilder = MessageCommandBuilder;
@@ -0,0 +1,3 @@
1
+ import { Permissions } from "discord.js";
2
+ import { Config } from "./classes/Config";
3
+ export declare function commandPermissions(commandName: string, member: Permissions | null, permissions?: Config['permissions']['messageCommands'] | Config['permissions']['interactionCommands']): boolean;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commandPermissions = void 0;
4
+ function commandPermissions(commandName, member, permissions) {
5
+ if (!(permissions === null || permissions === void 0 ? void 0 : permissions.enabled))
6
+ return true;
7
+ const command = permissions.commands.find(c => c.command.toLowerCase() === commandName.toLowerCase());
8
+ if (!command)
9
+ return true;
10
+ if (!command.permissions.length)
11
+ return true;
12
+ return member ? member.has(command.permissions) : false;
13
+ }
14
+ exports.commandPermissions = commandPermissions;
@@ -0,0 +1 @@
1
+ export declare const token: any;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.token = void 0;
4
+ const commander_1 = require("commander");
5
+ const flags = commander_1.program
6
+ .option('-t, --token <token>', 'Replace used bot token')
7
+ .parse().opts();
8
+ exports.token = flags.token;
@@ -0,0 +1,2 @@
1
+ import { Logger } from 'fallout-utility';
2
+ export declare function logger(stringifyJSON: boolean): Logger;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ const fallout_utility_1 = require("fallout-utility");
5
+ function logger(stringifyJSON) {
6
+ return new fallout_utility_1.Logger("Main", {
7
+ addPrefixToEveryJsonNewLines: stringifyJSON,
8
+ stringifyJSON: stringifyJSON,
9
+ });
10
+ }
11
+ exports.logger = logger;
@@ -0,0 +1,23 @@
1
+ import { RecipleClient } from './classes/Client';
2
+ import { MessageCommandBuilder } from './classes/builders/MessageCommandBuilder';
3
+ import { InteractionCommandBuilder } from './classes/builders/InteractionCommandBuilder';
4
+ export declare type recipleCommands = (MessageCommandBuilder | InteractionCommandBuilder)[];
5
+ export declare type loadedModules = {
6
+ commands: recipleCommands;
7
+ modules: RecipleModule[];
8
+ };
9
+ export interface RecipleScript {
10
+ versions: string | string[];
11
+ commands?: (MessageCommandBuilder | InteractionCommandBuilder)[];
12
+ onLoad?: (reciple: RecipleClient) => void;
13
+ onStart: (reciple: RecipleClient) => boolean;
14
+ }
15
+ export interface RecipleModule {
16
+ script: RecipleScript;
17
+ info: {
18
+ filename: string;
19
+ versions: string[];
20
+ path: string;
21
+ };
22
+ }
23
+ export declare function loadModules(client: RecipleClient): Promise<loadedModules>;