mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Better prefix handling
This commit is contained in:
+27
-35
@@ -104,7 +104,6 @@ class Discord {
|
|||||||
// TODO: Handle DMs commands soon
|
// TODO: Handle DMs commands soon
|
||||||
if(!(message.channel instanceof TextChannel)) return;
|
if(!(message.channel instanceof TextChannel)) return;
|
||||||
if(message.author.bot) return;
|
if(message.author.bot) return;
|
||||||
|
|
||||||
if(typeof message.guild?.id === 'undefined') return;
|
if(typeof message.guild?.id === 'undefined') return;
|
||||||
|
|
||||||
let GuildCache = await Cache.getGuild(message.guild.id);
|
let GuildCache = await Cache.getGuild(message.guild.id);
|
||||||
@@ -112,47 +111,40 @@ class Discord {
|
|||||||
|
|
||||||
if(!message.content.startsWith(GuildCache.prefix)) return;
|
if(!message.content.startsWith(GuildCache.prefix)) return;
|
||||||
|
|
||||||
let cachedPrefix = GuildCache.prefix;
|
let noPrefixMessage = message.content.replace(GuildCache.prefix, '');
|
||||||
|
let symbols = [
|
||||||
|
'!','@','#','$','%','^','&','*','(',')','-','=','_','+','\\','/','<','>','[',']','{','}','`','"',"'",',','.','~','|',';',':','?','、','。'
|
||||||
|
];
|
||||||
|
|
||||||
let args = message.content.split(" ");
|
if((GuildCache.prefix.indexOf(' ') >= 0)) {
|
||||||
|
if(noPrefixMessage.charAt(0) !== ' ') return;
|
||||||
let skipIndex = 0;
|
}
|
||||||
if((cachedPrefix.split(" ")[0] !== cachedPrefix)) {
|
else {
|
||||||
//skipIndex = (cachedPrefix.split(" ").length) - (args.length - (cachedPrefix.split(" ").length));
|
if(symbols.includes(GuildCache.prefix.charAt(GuildCache.prefix.length - 1))) {
|
||||||
skipIndex = (cachedPrefix.split(" ").length) - 1;
|
if(noPrefixMessage.charAt(0) === ' ') return;
|
||||||
|
}
|
||||||
//if(/^[A-Za-z0-9_.]+$/.test(cachedPrefix.split(" ")[cachedPrefix.split(" ").length - 1]))
|
else {
|
||||||
skipIndex++;
|
if(noPrefixMessage.charAt(0) !== ' ') return;
|
||||||
|
}
|
||||||
|
//if(noPrefixMessage.charAt(0) !== ' ' && !symbols.includes(noPrefixMessage.charAt(0))) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(/^[A-Za-z0-9_.]+$/.test(cachedPrefix.charAt(cachedPrefix.length - 1))) {
|
if(noPrefixMessage === '') return;
|
||||||
if(![
|
if(noPrefixMessage.charAt(0) === ' ') {
|
||||||
'!','@','#','$','%','^','&','*','(',')','-','=','_','+','\\','/','<','>','[',']','{','}','`','"',"'",',','.','~','|',';',':','?'
|
/*if(symbols.includes(GuildCache.prefix.charAt(GuildCache.prefix.length - 1))) {
|
||||||
].includes(cachedPrefix.charAt(cachedPrefix.length - 1))) {
|
if((GuildCache.prefix.indexOf(' ') >= 0)) return;
|
||||||
cachedPrefix = cachedPrefix + " ";
|
}*/
|
||||||
// if(!/^[A-Za-z0-9_.]+$/)
|
|
||||||
skipIndex++;
|
noPrefixMessage = noPrefixMessage.substring(1);
|
||||||
} else if (
|
|
||||||
(cachedPrefix.startsWith('<@!') && cachedPrefix.endsWith('>')) ||
|
|
||||||
cachedPrefix.startsWith('<:') && cachedPrefix.endsWith('>') ||
|
|
||||||
cachedPrefix.startsWith('<a:') && cachedPrefix.endsWith('>') ||
|
|
||||||
cachedPrefix.startsWith('<#') && cachedPrefix.endsWith('>')
|
|
||||||
) {
|
|
||||||
cachedPrefix = cachedPrefix + " ";
|
|
||||||
skipIndex++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof args[0 + skipIndex] === 'undefined') return;
|
let args = noPrefixMessage.split(" ");
|
||||||
|
|
||||||
let command = args[0 + skipIndex].replace(cachedPrefix, '');
|
|
||||||
|
|
||||||
if(command === '') return;
|
|
||||||
|
|
||||||
for(let i = 0; i < (skipIndex + 1); i++) {
|
|
||||||
args.shift();
|
|
||||||
}
|
|
||||||
args = args.filter(e => e !== '');
|
args = args.filter(e => e !== '');
|
||||||
|
|
||||||
|
let command = args[0];
|
||||||
|
|
||||||
|
args.shift();
|
||||||
|
|
||||||
if(args.length === 0)
|
if(args.length === 0)
|
||||||
args = [];
|
args = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user