code cleanup
This commit is contained in:
parent
f5934e19d2
commit
3441550f23
1 changed files with 123 additions and 106 deletions
|
@ -1,89 +1,55 @@
|
|||
const { MessageEmbed } = require('discord.js')
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { inspect, promisify } = require('util');
|
||||
|
||||
class Functions {
|
||||
constructor (client) {
|
||||
this.client = client;
|
||||
}
|
||||
};
|
||||
|
||||
userError (channel, cmd, error) {
|
||||
const embed = new MessageEmbed()
|
||||
embed.setColor('#EF5350')
|
||||
embed.setTitle(cmd.help.name + ':' + cmd.help.category.toLowerCase())
|
||||
embed.setDescription(error)
|
||||
embed.addField('**Usage**', cmd.help.usage)
|
||||
embed.setFooter(`Run 'help ${cmd.help.name}' for more information.`)
|
||||
channel.send(embed).then(msg => {
|
||||
msg.delete({ timeout: 60000 })
|
||||
})
|
||||
}
|
||||
.setColor('#EF5350')
|
||||
.setTitle(`${cmd.help.name}:${cmd.help.category.toLowerCase()}`)
|
||||
.setDescription(error)
|
||||
.addField('**Usage**', cmd.help.usage)
|
||||
.setFooter(`Run 'help ${cmd.help.name}' for more information.`);
|
||||
|
||||
// Simple check to see if someone is a developer or not
|
||||
isDeveloper (userID) {
|
||||
if (this.client.config.ownerIDs.includes(userID)) {
|
||||
return true;
|
||||
};
|
||||
return false;
|
||||
channel.send(embed);
|
||||
};
|
||||
|
||||
// Cleans output and removes sensitive information, used by eval
|
||||
async clean (text) {
|
||||
if (text && text.constructor.name == "Promise")
|
||||
text = await text;
|
||||
if (typeof text !== "string")
|
||||
text = require("util").inspect(text, { depth: 1 });
|
||||
|
||||
text = text
|
||||
.replace(/`/g, "`" + String.fromCharCode(8203))
|
||||
.replace(/@/g, "@" + String.fromCharCode(8203))
|
||||
.replace(this.client.token, "mfa.VkO_2G4Qv3T--NO--lWetW_tjND--TOKEN--QFTm6YGtzq9PH--4U--tG0");
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
// Return random integer between two given integers
|
||||
intBetween (min, max) {
|
||||
return Math.round((Math.random() * (max - min))+min);
|
||||
}
|
||||
|
||||
// Grab the last message sent in a channel (excludes the command)
|
||||
async getLastMessage (channel) {
|
||||
if (channel) {
|
||||
let lastMsg;
|
||||
let messages = await channel.messages.fetch({ limit: 2 });
|
||||
return messages.last().content;
|
||||
};
|
||||
|
||||
await channel.messages.fetch({ limit: 2 }).then(messages => {
|
||||
lastMsg = messages.last().content;
|
||||
});
|
||||
return lastMsg;
|
||||
}
|
||||
}
|
||||
async awaitReply(message, question, limit = 60000) {
|
||||
const filter = (m) => m.author.id === message.author.id;
|
||||
await message.channel.send(question);
|
||||
|
||||
// Wait for a reply to a message, then pass through the response
|
||||
async awaitReply (msg, question, limit = 60000) {
|
||||
const filter = m => m.author.id === msg.author.id;
|
||||
await msg.channel.send(question);
|
||||
try {
|
||||
const collected = await msg.channel.awaitMessages(filter, {
|
||||
const collected = await message.channel.awaitMessages(filter, {
|
||||
max: 1,
|
||||
time: limit,
|
||||
errors: ["time"]
|
||||
errors: ['time']
|
||||
});
|
||||
|
||||
return collected.first().content;
|
||||
} catch (e) {
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
searchForMembers (guild, query) {
|
||||
if (!query) return;
|
||||
query = query.toLowerCase();
|
||||
|
||||
var matches = [];
|
||||
var match;
|
||||
let matches = [];
|
||||
let match;
|
||||
|
||||
try {
|
||||
match = guild.members.cache.find(x => x.displayName.toLowerCase() == query);
|
||||
if (!match) guild.members.cache.find(x => x.user.username.toLowerCase() == query);
|
||||
} catch (err) {};
|
||||
|
||||
if (match) matches.push(match);
|
||||
guild.members.cache.forEach(member => {
|
||||
if (
|
||||
|
@ -94,11 +60,12 @@ class Functions {
|
|||
matches.push(member);
|
||||
};
|
||||
});
|
||||
|
||||
return matches;
|
||||
};
|
||||
|
||||
findRole (input, message) {
|
||||
var role;
|
||||
let role;
|
||||
role = message.guild.roles.cache.find(r => r.name.toLowerCase() === input.toLowerCase());
|
||||
if(!role) {
|
||||
role = message.guild.roles.cache.get(input.toLowerCase());
|
||||
|
@ -107,9 +74,59 @@ class Functions {
|
|||
return role;
|
||||
};
|
||||
|
||||
intBetween (min, max) {
|
||||
return Math.round((Math.random() * (max - min) + min));
|
||||
};
|
||||
|
||||
|
||||
|
||||
isDeveloper (id) {
|
||||
if (this.client.config.ownerIDs.includes(id)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
shutdown () {
|
||||
const exitQuotes = [
|
||||
'Shutting down.',
|
||||
'I don\'t blame you.',
|
||||
'I don\'t hate you.',
|
||||
'Whyyyyy',
|
||||
'Goodnight.',
|
||||
'Goodbye'
|
||||
];
|
||||
|
||||
this.client.db.pool.end().then(() => {
|
||||
this.client.logger.info('Connection to database closed.')
|
||||
});
|
||||
|
||||
this.client.destroy();
|
||||
|
||||
console.log(exitQuotes);
|
||||
};
|
||||
|
||||
async clean (text) {
|
||||
if (text && text.constructor.name === 'Promise') {
|
||||
text = await text;
|
||||
};
|
||||
|
||||
if (typeof text !== 'string') {
|
||||
text = inspect(text, { depth: 1});
|
||||
};
|
||||
|
||||
text = text
|
||||
.replace(/`/g, "`" + String.fromCharCode(8203))
|
||||
.replace(/@/g, "@" + String.fromCharCode(8203))
|
||||
.replace(this.client.token, "mfa.VkO_2G4Qv3T--NO--lWetW_tjND--TOKEN--QFTm6YGtzq9PH--4U--tG0");
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
wait () {
|
||||
require("util").promisify(setTimeout);
|
||||
}
|
||||
}
|
||||
promisify(setTimeout);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = Functions;
|
Loading…
Reference in a new issue