From 5a7729fd7d80e124b33630a775733b399b885285 Mon Sep 17 00:00:00 2001 From: David Sevilla Martin <6401250+datitisev@users.noreply.github.com> Date: Tue, 21 Feb 2023 11:02:21 -0500 Subject: [PATCH] fix: remove prefix references --- README.md | 2 +- lib/Discord/Client.js | 13 ++++--------- lib/Discord/Command.js | 2 +- lib/Discord/Commands/Conf.js | 2 -- lib/Discord/index.js | 1 - lib/Models/Guild.js | 33 +-------------------------------- 6 files changed, 7 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 77ff3f3..3c0883c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Invite the bot at http://bit.ly/DiscordYappyGitlab ### Commands -Prefixes are `GL! ` (with space), custom prefix set up, or mention the bot. +Mention the bot to use commands. Get more updated details of these commands at https://www.yappybots.tk/gitlab/commands. __**Util**__: diff --git a/lib/Discord/Client.js b/lib/Discord/Client.js index f6c4aa2..f30e342 100644 --- a/lib/Discord/Client.js +++ b/lib/Discord/Client.js @@ -6,7 +6,6 @@ const Log = require('../Util/Log'); /** * @typedef {external:ClientOptions} ClientOptions - * @property {String} prefix discord bot's prefix * @property {String} owner discord bot's owner user id * @property {String} [name] discord bot's name */ @@ -42,10 +41,11 @@ class Client extends DiscordClient { this.aliases = new Discord.Collection(); /** - * Discord bot's prefix + * Discord prefix is just mention. + * Only for usage in commands. * @type {String} */ - this.prefix = opts.prefix; + this.prefix = '@Yappy '; /** * Discord bot's name @@ -190,7 +190,6 @@ class Client extends DiscordClient { */ async execute(msg) { if (msg.author.equals(this.user) || msg.author.bot) return; - const prefix = (msg.guild && Guild.getPrefix(msg.guild)) || this.prefix; const userMention = this.user.toString(); const botMention = userMention.replace('@', '@!'); @@ -198,17 +197,13 @@ class Client extends DiscordClient { if ( msg.channel.type !== 'dm' && !msg.content.startsWith(userMention) && - !msg.content.startsWith(botMention) && - !msg.content.startsWith(prefix) && - !msg.content.startsWith(this.prefix) + !msg.content.startsWith(botMention) ) return false; const content = - (msg.content.startsWith(prefix) && msg.content.replace(prefix, '')) || (msg.content.startsWith(userMention) && msg.content.replace(`${userMention} `, '')) || (msg.content.startsWith(botMention) && msg.content.replace(`${botMention} `, '')) || - (msg.content.startsWith(this.prefix) && msg.content.replace(this.prefix, '')) || msg.content; const command = content.split(' ')[0].toLowerCase(); const args = content.split(' ').slice(1); diff --git a/lib/Discord/Command.js b/lib/Discord/Command.js index 3b60760..1f10c0d 100644 --- a/lib/Discord/Command.js +++ b/lib/Discord/Command.js @@ -15,7 +15,7 @@ class Command extends DefaultCommand { errorUsage(msg) { return this.commandError( msg, - `Correct usage: \`${this.bot.prefix}${this.help.usage}\`\nRun \`${this.bot.prefix}help ${this.help.name}\` for help and examples`, + `Correct usage: \`@Yappy ${this.help.usage}\`\nRun \`@Yappy help ${this.help.name}\` for help and examples`, 'Incorrect Usage' ); } diff --git a/lib/Discord/Commands/Conf.js b/lib/Discord/Commands/Conf.js index 7f75193..3d457ee 100644 --- a/lib/Discord/Commands/Conf.js +++ b/lib/Discord/Commands/Conf.js @@ -23,9 +23,7 @@ class ConfCommand extends Command { usage: 'conf [view|get|set|filter] [key] [value] ["--global"|"-g"]', examples: [ 'conf view', - 'conf get prefix', 'conf set repo datitisev/DiscordBot-Yappy', - 'conf set prefix g. --global', 'conf filter events ignore merge_request/update', 'conf filter events enable merge_request/update', 'conf filter users blacklist', diff --git a/lib/Discord/index.js b/lib/Discord/index.js index 702e78c..646c6ae 100644 --- a/lib/Discord/index.js +++ b/lib/Discord/index.js @@ -27,7 +27,6 @@ const bot = new Client({ 'VOICE_STATE_UPDATE', 'VOICE_SERVER_UPDATE', ], - prefix: 'GL! ', owner: '175008284263186437', messageCacheMaxSize: 1, messageCacheLifetime: 300, diff --git a/lib/Models/Guild.js b/lib/Models/Guild.js index 09c9755..b00d38c 100644 --- a/lib/Models/Guild.js +++ b/lib/Models/Guild.js @@ -1,8 +1,6 @@ const bookshelf = require('.'); const Model = require('./Model'); -const prefixCache = new Map(); - require('./Channel'); class Guild extends Model { @@ -11,7 +9,7 @@ class Guild extends Model { } static get validKeys() { - return ['prefix']; + return []; } channels() { @@ -43,35 +41,6 @@ class Guild extends Model { require: fail, }); } - - /** - * Get prefix for guild. Obtains prefix from DB only if not cached. - * @param {external:Guild} guild - */ - static getPrefix(guild) { - const id = guild.id; - - if (prefixCache.has(id)) return prefixCache.get(id); - - return Guild.find(guild.id) - .then((conf) => { - const prefix = conf.get('prefix'); - - prefixCache.set(id, prefix); - - return prefix; - }) - .catch(() => null); - } - - /** - * Update cached prefix for guild - * @param {external:Guild} guild - * @param {string} prefix - */ - static updateCachedPrefix(guild, prefix) { - prefixCache.set(guild.id, prefix); - } } module.exports = bookshelf.model('Guild', Guild);