forked from embee/woomy
Added back all the missing functions
This commit is contained in:
parent
02e570eb00
commit
123f5c9c11
2 changed files with 87 additions and 38 deletions
|
@ -1,4 +1,5 @@
|
|||
module.exports = client => {
|
||||
// Permission level function
|
||||
client.permlevel = message => {
|
||||
let permlvl = 0
|
||||
|
||||
|
@ -15,6 +16,7 @@ module.exports = client => {
|
|||
return permlvl
|
||||
}
|
||||
|
||||
// Loads commands
|
||||
client.loadCommand = (commandName) => {
|
||||
try {
|
||||
const props = require(`../commands/${commandName}`)
|
||||
|
@ -33,6 +35,7 @@ module.exports = client => {
|
|||
}
|
||||
}
|
||||
|
||||
// Command unloader
|
||||
client.unloadCommand = async (commandName) => {
|
||||
let command
|
||||
if (client.commands.has(commandName)) {
|
||||
|
@ -56,6 +59,7 @@ module.exports = client => {
|
|||
return false
|
||||
}
|
||||
|
||||
// Clean up input to remove @everyone, token, etc
|
||||
client.clean = async (client, text) => {
|
||||
if (text && text.constructor.name === 'Promise') {
|
||||
text = await text
|
||||
|
@ -71,40 +75,65 @@ module.exports = client => {
|
|||
return text
|
||||
}
|
||||
|
||||
client.getMembers = function (guild, query) {
|
||||
if (!query) return
|
||||
query = query.toLowerCase()
|
||||
|
||||
var a = []
|
||||
var b
|
||||
|
||||
// MAKE IT SO IT CAN TAKE AN ID
|
||||
|
||||
// Single line await messages
|
||||
client.awaitReply = async (msg, question, limit = 60000) => {
|
||||
const filter = m => m.author.id === msg.author.id
|
||||
await msg.channel.send(question)
|
||||
try {
|
||||
b = guild.members.cache.find(x => x.displayName.toLowerCase() === query)
|
||||
if (!b) guild.members.cache.find(x => x.user.username.toLowerCase() === query)
|
||||
} catch (err) {}
|
||||
if (b) a.push(b)
|
||||
guild.members.cache.forEach(member => {
|
||||
if (
|
||||
(member.displayName.toLowerCase().startsWith(query) ||
|
||||
member.user.tag.toLowerCase().startsWith(query)) &&
|
||||
member.id !== (b && b.id)
|
||||
) {
|
||||
a.push(member)
|
||||
}
|
||||
})
|
||||
return a
|
||||
const collected = await msg.channel.awaitMessages(filter, {
|
||||
max: 1,
|
||||
time: limit,
|
||||
errors: ['time']
|
||||
})
|
||||
return collected.first().content
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
client.getMembers = function (guild, query) {
|
||||
if (!query || typeof query !== 'string') return
|
||||
client.embedColour = function (guild) {
|
||||
if (!guild || guild.member(client.user).displayHexColor === '#000000') {
|
||||
return ['#ff9d68', '#ff97cb', '#d789ff', '#74FFFF'].random()
|
||||
} else {
|
||||
return guild.member(client.user).displayHexColor
|
||||
}
|
||||
}
|
||||
|
||||
// FIND RANDOM INT BETWEEN TWO INTEGERS
|
||||
client.intBetween = function (min, max) {
|
||||
return Math.round((Math.random() * (max - min)) + min)
|
||||
}
|
||||
|
||||
Object.defineProperty(Array.prototype, 'random', {
|
||||
value: function() {
|
||||
return this[Math.floor(Math.random() * this.length)]
|
||||
}
|
||||
})
|
||||
|
||||
// `await client.wait(1000);` to 'pause' for 1 second.
|
||||
client.wait = require('util').promisify(setTimeout)
|
||||
|
||||
// Find guild members
|
||||
client.findMembers = function (guild, search) {
|
||||
if (!search || typeof search !== 'string') return
|
||||
|
||||
const members = []
|
||||
let member
|
||||
|
||||
// Try mention
|
||||
if (search.startsWith('<@') && search.endsWith('>')) {
|
||||
let mention = search.slice(2, -1)
|
||||
|
||||
if (mention.startsWith('!')) {
|
||||
mention = mention.slice(1)
|
||||
}
|
||||
|
||||
return guild.members.cache.get(mention)
|
||||
}
|
||||
|
||||
// Try ID search
|
||||
if (!isNaN(query) === true) {
|
||||
members.push(guild.members.cache.get(query))
|
||||
if (!isNaN(search) === true) {
|
||||
members.push(guild.members.cache.get(search))
|
||||
if (members[0]) {
|
||||
return members[0]
|
||||
}
|
||||
|
@ -112,15 +141,35 @@ module.exports = client => {
|
|||
|
||||
// Try username search
|
||||
try {
|
||||
guild.members.cache.forEach(m => {
|
||||
if (m.displayName.toLowerCase().startsWith(query) || m.user.tag.toLowerCase.startsWith(query)) {
|
||||
members.push(m)
|
||||
console.log(m)
|
||||
}
|
||||
})
|
||||
|
||||
return members
|
||||
member = guild.members.cache.find(m => m.displayName.toLowerCase() === search)
|
||||
if (!member) {
|
||||
guild.members.cache.find(m => m.user.tag.toLowerCase() === search)
|
||||
}
|
||||
} catch (err) {}
|
||||
if (member) {
|
||||
members.push(member)
|
||||
}
|
||||
guild.members.cache.forEach(m => {
|
||||
if (m.displayName.toLowerCase().startsWith(search) || m.user.tag.toLowerCase().startsWith(search)) {
|
||||
members.push(m)
|
||||
}
|
||||
})
|
||||
|
||||
return members
|
||||
}
|
||||
|
||||
client.findRole = function (guild, search) {
|
||||
var role
|
||||
role = guild.roles.cache.find(r => r.name.toLowerCase() === search.toLowerCase())
|
||||
if (!role) {
|
||||
role = guild.roles.cache.get(search.toLowerCase())
|
||||
}
|
||||
|
||||
if (!role) {
|
||||
return
|
||||
}
|
||||
|
||||
return role
|
||||
}
|
||||
|
||||
// Both of these functions catch errors and log them
|
||||
|
|
|
@ -11,15 +11,15 @@ module.exports = client => {
|
|||
var hrs = ~~(duration / 60 / 60)
|
||||
var min = ~~(duration / 60) % 60
|
||||
var sec = ~~(duration - min * 60)
|
||||
|
||||
|
||||
if (String(hrs).length < 2) {
|
||||
hrs = '0' + String(hrs) + ':'
|
||||
}
|
||||
|
||||
|
||||
if (String(min).length < 2) {
|
||||
min = '0' + String(min)
|
||||
}
|
||||
|
||||
|
||||
if (String(sec).length < 2) {
|
||||
sec = '0' + String(sec)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue