de-OOPify stuff a little

This commit is contained in:
spiral 2021-10-20 12:56:51 -04:00
parent c3fa0554c4
commit 2aadc1a1ef
No known key found for this signature in database
GPG key ID: A6059F0CA0E1BD31
6 changed files with 30 additions and 89 deletions

View file

@ -1,23 +1,14 @@
const Logger = require('@lilywonhalf/pretty-logger'); const Logger = require('@lilywonhalf/pretty-logger');
const Discord = require('discord.js'); const Discord = require('discord.js');
const CommandCategory = require('../model/command-category'); const CommandCategory = require('../model/command-category');
const CommandPermission = require('../model/command-permission');
const Guild = require('../model/guild'); const Guild = require('../model/guild');
class Avatar module.exports = {
{ aliases: ['av'],
constructor() { category: CommandCategory.FUN,
this.aliases = ['av']; isAllowedForContext: () => true,
this.category = CommandCategory.FUN; description: 'Displays the avatar of the specified member.',
this.isAllowedForContext = CommandPermission.yes; process: async (message, args) => {
this.description = 'Displays the avatar of the specified member.';
}
/**
* @param {Message} message
* @param {Array} args
*/
async process(message, args) {
let user = null; let user = null;
if (args.length > 0) { if (args.length > 0) {
@ -46,5 +37,3 @@ class Avatar
} }
} }
} }
module.exports = new Avatar();

View file

@ -6,20 +6,13 @@ const { search } = require('../model/jira');
const MAX_CHARACTERS = 1950; const MAX_CHARACTERS = 1950;
class Changelog module.exports = {
{ aliases: ['change-log', 'cl'],
constructor() { category: CommandCategory.MODERATION,
this.aliases = ['change-log', 'cl']; isAllowedForContext: CommandPermission.isMemberMod,
this.category = CommandCategory.MODERATION; description: 'Builds the changelog for a given version',
this.isAllowedForContext = CommandPermission.isMemberMod; process: async (message, args) => {
this.description = 'Builds the changelog for a given version';
}
/**
* @param {Message} message
* @param {Array} args
*/
async process(message, args) {
const errorHandler = async (error) => { const errorHandler = async (error) => {
if (error) { if (error) {
Logger.exception(error); Logger.exception(error);
@ -71,5 +64,3 @@ class Changelog
await message.react('✔').catch(() => {}); await message.react('✔').catch(() => {});
} }
} }
module.exports = new Changelog();

View file

@ -1,22 +1,13 @@
const Logger = require('@lilywonhalf/pretty-logger');
const Config = require('../config.json'); const Config = require('../config.json');
const CommandCategory = require('../model/command-category'); const CommandCategory = require('../model/command-category');
const CommandPermission = require('../model/command-permission'); const CommandPermission = require('../model/command-permission');
class Clean module.exports = {
{ aliases: ['clear', 'purge'],
constructor() { category: CommandCategory.MODERATION,
this.aliases = ['clear', 'purge']; isAllowedForContext: CommandPermission.isMemberMod,
this.category = CommandCategory.MODERATION; description: 'Deletes messages in bulk.',
this.isAllowedForContext = CommandPermission.isMemberMod; process: async (message, args) => {
this.description = 'Deletes messages in a bulk.';
}
/**
* @param {Message} message
* @param {Array} args
*/
async process(message, args) {
if (args.length > 0 && parseInt(args[0]) > 0) { if (args.length > 0 && parseInt(args[0]) > 0) {
await message.channel.bulkDelete(Math.min(parseInt(args[0]) + 1, 100)); await message.channel.bulkDelete(Math.min(parseInt(args[0]) + 1, 100));
} else { } else {
@ -24,5 +15,3 @@ class Clean
} }
} }
} }
module.exports = new Clean();

View file

@ -9,18 +9,11 @@ const Guild = require('../model/guild');
const JAVASCRIPT_LOGO_URL = 'https://i.discord.fr/IEV8.png'; const JAVASCRIPT_LOGO_URL = 'https://i.discord.fr/IEV8.png';
class Eval module.exports = {
{ aliases: [],
constructor() { category: CommandCategory.BOT_MANAGEMENT,
this.aliases = []; isAllowedForContext: CommandPermission.isMommy,
this.category = CommandCategory.BOT_MANAGEMENT; process: async (message) => {
this.isAllowedForContext = CommandPermission.isMommy;
}
/**
* @param {Message} message
*/
async process(message) {
const code = message.content const code = message.content
.substr(Config.prefix.length + 'eval'.length) .substr(Config.prefix.length + 'eval'.length)
.trim() .trim()
@ -44,6 +37,4 @@ class Eval
message.channel.send(embed).catch(error => Logger.warning(error.toString())); message.channel.send(embed).catch(error => Logger.warning(error.toString()));
} }
} };
module.exports = new Eval();

View file

@ -81,21 +81,12 @@ const categoryPage = (cat, id, direct = false) => {
return data; return data;
} }
class Help module.exports = {
{ aliases: ["commands"],
constructor() { category: CommandCategory.INFO,
this.aliases = ['commands']; isAllowedForContext: () => true,
this.category = CommandCategory.INFO; description: 'Provides the list of commands.',
this.isAllowedForContext = CommandPermission.yes; process: async (message, args) => {
this.description = 'Provides the list of commands';
}
/**
* @param {Message} message
* @param {Array} args
* @param {Command} Command
*/
async process(message, args, command) {
if (!args[0]) if (!args[0])
await bot.api.channels(message.channel.id).messages.post({ data: mainPage(message.author.id) }); await bot.api.channels(message.channel.id).messages.post({ data: mainPage(message.author.id) });
else else
@ -111,8 +102,6 @@ class Help
} }
} }
module.exports = new Help();
module.exports.interactionHandler = async (event) => { module.exports.interactionHandler = async (event) => {
const user = event.member ? event.member.user.id : event.user.id; const user = event.member ? event.member.user.id : event.user.id;
const customId = event.data.custom_id; const customId = event.data.custom_id;

View file

@ -31,14 +31,6 @@ const CommandPermission = {
return await CommandPermission.isMemberMod(message) || await Guild.isMemberHelper(member); return await CommandPermission.isMemberMod(message) || await Guild.isMemberHelper(member);
}, },
/**
* @param {Message} message
* @returns {Promise.<boolean>}
*/
yes: async (message) => {
return true;
}
}; };
module.exports = CommandPermission; module.exports = CommandPermission;