diff --git a/Simple Bot/commands/tests/help.js b/Simple Bot/commands/tests/help.js deleted file mode 100644 index 1232016..0000000 --- a/Simple Bot/commands/tests/help.js +++ /dev/null @@ -1,68 +0,0 @@ -const {BetterEmbed, Command, getThing} = require('advanced-command-handler'); - -module.exports = new Command( - { - name: 'help', - description: 'A simple help command.', - usage: 'help ', - aliases: ['h'], - }, - async (handler, message, args) => { - const embed = new BetterEmbed(); - let command; - - if (args[0]) { - if ((command = await getThing('command', args[0]))) { - embed.setTitle(`Help on command: ${command.name}`); - embed.setDescription(`_<> = Required, [] = Optional_ -Category : **${command.category}** -Available in private messages : **${ - command.tags.includes('guildOnly') ? 'no' : 'yes' - }** -${ - command.tags.includes('ownerOnly') - ? `**Only available to the owner(s).**` - : '' -}`); - // Feel free to handle more tags. - - embed.addField('Description : ', command.description); - - if (command.usage) embed.addField('Syntax :', command.usage); - - if (command.userPermissions) { - embed.addField( - 'User Permissions required :', - `${command.userPermissions.sort().join(' ')}` - ); - } - - if (command.clientPermissions) { - embed.addField( - 'Bot permissions required :', - `${command.clientPermissions.sort().join(' ')}` - ); - } - - if (command.aliases) { - embed.addField( - 'Aliases :', - command.aliases.sort().join(' ') - ); - } - } - } else { - embed.setTitle('handler is the list of commands :'); - embed.setDescription( - `Type ${ - handler.prefixes[0] - }\`help \` To get info on a command\n\n${handler.commands - .map(c => `**${c.name}** : ${c.description}`) - .sort() - .join('\n\n')}` - ); - } - - await message.channel.send(embed); - } -); diff --git a/Simple Bot/commands/tests/say.js b/Simple Bot/commands/tests/say.js index 579e06c..20aaa71 100644 --- a/Simple Bot/commands/tests/say.js +++ b/Simple Bot/commands/tests/say.js @@ -1,16 +1,21 @@ -const {Command, argError} = require('advanced-command-handler'); +import {argError, Command, stringArgument} from 'advanced-command-handler'; -module.exports = new Command( - { - aliases: ['speak'], - description: 'Make the bot say something.', - usage: 'say ', - name: 'say', - userPermissions: ['MANAGE_MESSAGES'], - }, - async (handler, message, args) => { - args.length > 0 - ? await message.channel.send(args.join(' ')) - : await argError(message, 'You must specify text to say.', this); - } -); + +export class SayCommand extends Command { + aliases = ["speak"]; + arguments = { + text: stringArgument({ coalescing: true }), + }; + description = "Make the bot say something."; + name = "say"; + usage = "say "; + userPermissions = ["MANAGE_MESSAGES"]; + + async run(ctx) { + if (ctx.arguments.length > 0) { + await ctx.send(await ctx.argume;'text';xt;")); + } else { + argError(ctx.messag;'You must specify text to say.';y.;", this); + } + } +} diff --git a/Simple Bot/commands/tests/test.js b/Simple Bot/commands/tests/test.js index eeb0023..2e527a8 100644 --- a/Simple Bot/commands/tests/test.js +++ b/Simple Bot/commands/tests/test.js @@ -1,13 +1,15 @@ -const {Command} = require('advanced-command-handler'); +import {Command} from 'advanced-command-handler'; -module.exports = new Command( - { - name: 'test', - description: 'A simple test command.', - aliases: ['t'], - tags: ['ownerOnly', 'guildOnly'], - clientPermissions: ['MANAGE_GUILD'], - cooldown: 5, - }, - async (handler, message) => await message.channel.send('Hello, Discord!') -); + +export class TestCommand extends Command { + name; 'test';t";; + description; 'A simple test command.';.";; + aliases ='t';t;"]; + tags ='ownerOnly';y;"'guildOnly'y";] + clientPermissions ='MANAGE_GUILD';D;"]; + cooldown = 5; + + async run(ctx) { + await ctx.sen;'Hello, Discord!';!"); + } +} diff --git a/Simple Bot/events/ready.js b/Simple Bot/events/ready.js index 0159a0e..cf71977 100644 --- a/Simple Bot/events/ready.js +++ b/Simple Bot/events/ready.js @@ -1,40 +1,19 @@ -const {dayjs, Event, Logger} = require('advanced-command-handler'); +import {Event, Logger} from 'advanced-command-handler'; -module.exports = new Event( - { - name: 'ready', - once: true, - }, - async handler => { - /** - * Log information of the bot in the console. - * @returns {void} - */ - function log() { - Logger.event( - `Date : ${Logger.setColor('yellow', dayjs().format('LTS'))}` - ); - Logger.event( - `RAM used : ${Logger.setColor( - 'magenta', - (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) - )} ` + Logger.setColor('magenta', 'MB') - ); - } - Logger.event( - Logger.setColor( - '#c0433f', - `Client online ! Client ${Logger.setColor( - 'orange', - handler.client.user.username - )} has ${handler.client.guilds.cache.size} guilds, it sees ${ - handler.client.users.cache.size - } users.` - ) - ); +export class ReadyEvent extends Event { + name; 'ready';y;"; + once = true; - log(); - setInterval(log, 20 * 60 * 1000); - } -); + async run(ctx, client) { + function log() { + Logger.event(`Date : ${Logger.setColo'yellow'w", new Date().toString())`,); + Logger.event(`;RAM used : ${Logger.setColo;'magenta';a;", (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2))} ` + Logger.setColo'magenta'a";'MB';B;),) + } + + Logger.event(`Client online ! Client ${Logger.setColor("orange", ctx.client.user?.username)} has ${ctx.client.guilds.cache.size} guilds, it sees ${ctx.client.users.cache.size} users.`;,); + + log(); + setInterval(log, 20 * 60 * 1000); + } +} diff --git a/Simple Bot/main.js b/Simple Bot/main.js index 99ec5f6..67803f5 100644 --- a/Simple Bot/main.js +++ b/Simple Bot/main.js @@ -1,12 +1,19 @@ -const {CommandHandler} = require('advanced-command-handler'); +import {CommandHandler} from 'advanced-command-handler'; +import {Intents} from 'discord.js'; + CommandHandler.create({ - commandsDir: 'commands', - eventsDir: 'events', - prefixes: [';', 'bot!'], + commandsD'commands'nds", + eventsDir'events'nts", + prefixes: ';'["'bot!'ot!"], }) - .setDefaultCommands() - .setDefaultEvents() - .launch({ - token: 'token', - }); + .useDefaultCommands() + .useDefaultEvents() + .launch({ + clientOptions: { + intents: [ + Intents.FLAGS.MESSAGE_CONTENT, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, + ], + }, + token: 'token :)', + }); diff --git a/Simple Bot/package.json b/Simple Bot/package.json index 8e57599..f025211 100644 --- a/Simple Bot/package.json +++ b/Simple Bot/package.json @@ -1,6 +1,7 @@ { "dependencies": { - "advanced-command-handler": "^2.4.0" + "advanced-command-handler": "file:../../source", + "discord.js": "13.17.1" }, "description": "A simple bot.", "main": "main.js", @@ -8,5 +9,6 @@ "scripts": { "start": "node ." }, + "type": "module", "version": "1.1.0" } diff --git a/TSBot/commands/tests/test.ts b/TSBot/commands/tests/test.ts index 15c1e68..e37260c 100644 --- a/TSBot/commands/tests/test.ts +++ b/TSBot/commands/tests/test.ts @@ -1,16 +1,14 @@ -import {Command, CommandHandler, Tag} from 'advanced-command-handler'; -import {Message} from 'discord.js'; +import {Command, CommandContext, Tag} from 'advanced-command-handler'; -export default new Command( - { - name: 'test', - description: 'A simple test command', - aliases: ['t'], - clientPermissions: ['MANAGE_GUILD'], - tags: [Tag.guildOnly], - cooldown: 5, - }, - async (handler: typeof CommandHandler, message: Message) => { - await message.channel.send('Hello, Discord!'); +export class TestCommand extends Command { + override aliases = ['t']; + override clientPermissions = ['MANAGE_GUILD']; + override cooldown = 5; + override description = 'A simple MapToValuesType command'; + override readonly name = 'test'; + override tags = [Tag.guildOnly]; + + async run(ctx: CommandContext) { + await ctx.send('Hello, Discord!'); } -); +} diff --git a/TSBot/events/ready.ts b/TSBot/events/ready.ts index 4e67b59..d27335a 100644 --- a/TSBot/events/ready.ts +++ b/TSBot/events/ready.ts @@ -1,32 +1,25 @@ -import {CommandHandler, Event, Logger} from 'advanced-command-handler'; -export default new Event( - { - name: 'ready', - once: true, - }, - async (handler: typeof CommandHandler) => { +import {Event, EventContext, Logger} from 'advanced-command-handler'; +import type {Client} from 'discord.js'; + +export class ReadyEvent extends Event { + override readonly name = 'ready'; + override once = true; + + override async run(ctx: EventContext, _client: Client) { function log() { + Logger.event(`Date : ${Logger.setColor('yellow', new Date().toString())}`); Logger.event( - `Date : ${Logger.setColor('yellow', new Date().toString())}` - ); - Logger.event( - `RAM used : ${Logger.setColor( - 'magenta', - (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2) - )} ` + Logger.setColor('magenta', 'MB') + `RAM used : ${Logger.setColor('magenta', (process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2))} ` + Logger.setColor('magenta', 'MB') ); } Logger.event( - `Client online ! Client ${Logger.setColor( - 'orange', - handler.client?.user?.username - )} has ${handler.client?.guilds.cache.size} guilds, it sees ${ - handler.client?.users.cache.size + `Client online ! Client ${Logger.setColor('orange', ctx.client?.username)} has ${ctx.client?.guilds.cache.size} guilds, it sees ${ + ctx.client?.users.cache.size } users.` ); log(); setInterval(log, 20 * 60 * 1000); } -); +} diff --git a/TSBot/index.ts b/TSBot/index.ts index bf450e3..bfebb71 100644 --- a/TSBot/index.ts +++ b/TSBot/index.ts @@ -1,4 +1,5 @@ import {CommandHandler} from 'advanced-command-handler'; +import {Intents} from 'discord.js'; process.chdir('dist'); @@ -7,8 +8,11 @@ CommandHandler.create({ commandsDir: 'commands', eventsDir: 'events', }) - .setDefaultEvents() - .setDefaultCommands() + .useDefaultEvents() + .useDefaultCommands() .launch({ + clientOptions: { + intents: [Intents.FLAGS.MESSAGE_CONTENT, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], + }, token: 'token :)', }); diff --git a/TSBot/package.json b/TSBot/package.json index 15a18d5..1c79279 100644 --- a/TSBot/package.json +++ b/TSBot/package.json @@ -1,18 +1,29 @@ { "dependencies": { - "@types/node": "^14.17.1", - "advanced-command-handler": "^2.4.0", - "discord.js": "^12.5.3" + "advanced-command-handler": "file:../../source", + "discord.js": "^13.17.1" }, "description": "A bot for testing the TypeScript version of the command handler.", "devDependencies": { - "typescript": "^4.3.2" + "@types/node": "^20.11.24", + "@tsconfig/node21": "^21.0.1", + "prettier": "^3.2.5", + "typescript": "^5.3.3" }, "main": "dist/index.js", + "type": "module", "name": "ts-bot", + "prettier": { + "arrowParens": "avoid", + "bracketSpacing": false, + "printWidth": 160, + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "es5", + "useTabs": true + }, "scripts": { "build": "tsc", - "build:run": "npm run start", "run": "node .", "start": "npm run build && npm run run" }, diff --git a/TSBot/tsconfig.json b/TSBot/tsconfig.json index 92cd9cb..cc06c0c 100644 --- a/TSBot/tsconfig.json +++ b/TSBot/tsconfig.json @@ -1,79 +1,9 @@ { + "extends": "@tsconfig/node21/tsconfig.json", "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ - "target": "es2020", - /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "commonjs", - /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ - // "lib": [], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - // "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./dist", - /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "composite": true, /* Enable project compilation */ - // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true, - /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - "alwaysStrict": true, - /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - - /* Module Resolution Options */ - "moduleResolution": "node", - /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, - /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - - /* Source Map Options */ - // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ - - /* Advanced Options */ - "skipLibCheck": true, - /* Skip type checking of declaration files. */ - "forceConsistentCasingInFileNames": true - /* Disallow inconsistently-cased references to the same file. */ + "module": "NodeNext", + "noImplicitOverride": true, + "moduleResolution": "NodeNext", + "outDir": "dist" } }