Skip to content

Commit

Permalink
fix: remove prefix references
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Feb 21, 2023
1 parent af7b88a commit 5a7729f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**__:
Expand Down
13 changes: 4 additions & 9 deletions lib/Discord/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -190,25 +190,20 @@ 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('@', '@!');

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);
Expand Down
2 changes: 1 addition & 1 deletion lib/Discord/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
Expand Down
2 changes: 0 additions & 2 deletions lib/Discord/Commands/Conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion lib/Discord/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const bot = new Client({
'VOICE_STATE_UPDATE',
'VOICE_SERVER_UPDATE',
],
prefix: 'GL! ',
owner: '175008284263186437',
messageCacheMaxSize: 1,
messageCacheLifetime: 300,
Expand Down
33 changes: 1 addition & 32 deletions lib/Models/Guild.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const bookshelf = require('.');
const Model = require('./Model');

const prefixCache = new Map();

require('./Channel');

class Guild extends Model {
Expand All @@ -11,7 +9,7 @@ class Guild extends Model {
}

static get validKeys() {
return ['prefix'];
return [];
}

channels() {
Expand Down Expand Up @@ -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);

0 comments on commit 5a7729f

Please sign in to comment.