additions to util
This commit is contained in:
parent
ac28415075
commit
998eefef4c
2 changed files with 36 additions and 0 deletions
|
@ -3,6 +3,33 @@ class MessageUtil {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Grab the last message sent in a channel (excludes the command)
|
||||||
|
async getLastMessage (channel) {
|
||||||
|
if (channel) {
|
||||||
|
let lastMsg;
|
||||||
|
|
||||||
|
await channel.messages.fetch({ limit: 2 }).then(messages => {
|
||||||
|
lastMsg = messages.last().content;
|
||||||
|
});
|
||||||
|
return lastMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, {
|
||||||
|
max: 1,
|
||||||
|
time: limit,
|
||||||
|
errors: ["time"]
|
||||||
|
});
|
||||||
|
return collected.first().content;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MessageUtil;
|
module.exports = MessageUtil;
|
|
@ -3,6 +3,7 @@ class Util {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Simple check to see if someone is a developer or not
|
||||||
isDeveloper (userID) {
|
isDeveloper (userID) {
|
||||||
let isDev = false;
|
let isDev = false;
|
||||||
const developers = this.client.config.ownerIDs;
|
const developers = this.client.config.ownerIDs;
|
||||||
|
@ -17,6 +18,7 @@ class Util {
|
||||||
return isDev;
|
return isDev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleans output and removes sensitive information, used by eval
|
||||||
async clean (text) {
|
async clean (text) {
|
||||||
if (text && text.constructor.name == "Promise")
|
if (text && text.constructor.name == "Promise")
|
||||||
text = await text;
|
text = await text;
|
||||||
|
@ -30,6 +32,13 @@ class Util {
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return random integer between two given integers
|
||||||
|
intBetween (min, max) {
|
||||||
|
return Math.round((Math.random() * (max - min))+min);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Util;
|
module.exports = Util;
|
Loading…
Reference in a new issue