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 => {
|
module.exports = client => {
|
||||||
|
// Permission level function
|
||||||
client.permlevel = message => {
|
client.permlevel = message => {
|
||||||
let permlvl = 0
|
let permlvl = 0
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ module.exports = client => {
|
||||||
return permlvl
|
return permlvl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loads commands
|
||||||
client.loadCommand = (commandName) => {
|
client.loadCommand = (commandName) => {
|
||||||
try {
|
try {
|
||||||
const props = require(`../commands/${commandName}`)
|
const props = require(`../commands/${commandName}`)
|
||||||
|
@ -33,6 +35,7 @@ module.exports = client => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Command unloader
|
||||||
client.unloadCommand = async (commandName) => {
|
client.unloadCommand = async (commandName) => {
|
||||||
let command
|
let command
|
||||||
if (client.commands.has(commandName)) {
|
if (client.commands.has(commandName)) {
|
||||||
|
@ -56,6 +59,7 @@ module.exports = client => {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up input to remove @everyone, token, etc
|
||||||
client.clean = async (client, text) => {
|
client.clean = async (client, text) => {
|
||||||
if (text && text.constructor.name === 'Promise') {
|
if (text && text.constructor.name === 'Promise') {
|
||||||
text = await text
|
text = await text
|
||||||
|
@ -71,40 +75,65 @@ module.exports = client => {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
client.getMembers = function (guild, query) {
|
// Single line await messages
|
||||||
if (!query) return
|
client.awaitReply = async (msg, question, limit = 60000) => {
|
||||||
query = query.toLowerCase()
|
const filter = m => m.author.id === msg.author.id
|
||||||
|
await msg.channel.send(question)
|
||||||
var a = []
|
|
||||||
var b
|
|
||||||
|
|
||||||
// MAKE IT SO IT CAN TAKE AN ID
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
b = guild.members.cache.find(x => x.displayName.toLowerCase() === query)
|
const collected = await msg.channel.awaitMessages(filter, {
|
||||||
if (!b) guild.members.cache.find(x => x.user.username.toLowerCase() === query)
|
max: 1,
|
||||||
} catch (err) {}
|
time: limit,
|
||||||
if (b) a.push(b)
|
errors: ['time']
|
||||||
guild.members.cache.forEach(member => {
|
})
|
||||||
if (
|
return collected.first().content
|
||||||
(member.displayName.toLowerCase().startsWith(query) ||
|
} catch (e) {
|
||||||
member.user.tag.toLowerCase().startsWith(query)) &&
|
return false
|
||||||
member.id !== (b && b.id)
|
}
|
||||||
) {
|
|
||||||
a.push(member)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return a
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.getMembers = function (guild, query) {
|
client.embedColour = function (guild) {
|
||||||
if (!query || typeof query !== 'string') return
|
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 = []
|
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
|
// Try ID search
|
||||||
if (!isNaN(query) === true) {
|
if (!isNaN(search) === true) {
|
||||||
members.push(guild.members.cache.get(query))
|
members.push(guild.members.cache.get(search))
|
||||||
if (members[0]) {
|
if (members[0]) {
|
||||||
return members[0]
|
return members[0]
|
||||||
}
|
}
|
||||||
|
@ -112,15 +141,35 @@ module.exports = client => {
|
||||||
|
|
||||||
// Try username search
|
// Try username search
|
||||||
try {
|
try {
|
||||||
guild.members.cache.forEach(m => {
|
member = guild.members.cache.find(m => m.displayName.toLowerCase() === search)
|
||||||
if (m.displayName.toLowerCase().startsWith(query) || m.user.tag.toLowerCase.startsWith(query)) {
|
if (!member) {
|
||||||
members.push(m)
|
guild.members.cache.find(m => m.user.tag.toLowerCase() === search)
|
||||||
console.log(m)
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return members
|
|
||||||
} catch (err) {}
|
} 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
|
// Both of these functions catch errors and log them
|
||||||
|
|
|
@ -11,15 +11,15 @@ module.exports = client => {
|
||||||
var hrs = ~~(duration / 60 / 60)
|
var hrs = ~~(duration / 60 / 60)
|
||||||
var min = ~~(duration / 60) % 60
|
var min = ~~(duration / 60) % 60
|
||||||
var sec = ~~(duration - min * 60)
|
var sec = ~~(duration - min * 60)
|
||||||
|
|
||||||
if (String(hrs).length < 2) {
|
if (String(hrs).length < 2) {
|
||||||
hrs = '0' + String(hrs) + ':'
|
hrs = '0' + String(hrs) + ':'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(min).length < 2) {
|
if (String(min).length < 2) {
|
||||||
min = '0' + String(min)
|
min = '0' + String(min)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (String(sec).length < 2) {
|
if (String(sec).length < 2) {
|
||||||
sec = '0' + String(sec)
|
sec = '0' + String(sec)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue