forked from Galactic/galactic-bot
user and member resolvers
This commit is contained in:
parent
34a006e351
commit
a8f7acc3f3
@ -57,7 +57,7 @@ class Resolver {
|
||||
|
||||
}
|
||||
|
||||
async resolveUsers(resolveables = []) {
|
||||
async resolveUsers(resolveables = [], strict = false) {
|
||||
|
||||
if(typeof resolveables === 'string') resolveables = [ resolveables ];
|
||||
if(resolveables.length === 0) return false;
|
||||
@ -88,6 +88,14 @@ class Resolver {
|
||||
}).first(1);
|
||||
if(user) resolved.push(user);
|
||||
|
||||
} else if(!strict) {
|
||||
|
||||
let name = resolveable.toLowerCase();
|
||||
let user = users.cache.filter(u => {
|
||||
return u.username.toLowerCase().includes(name);
|
||||
}).first(1);
|
||||
if(user) resolved.push(user);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -111,10 +119,40 @@ class Resolver {
|
||||
let member = await members.fetch(id).catch(err => { if(err.code === 10007) return false; else { console.warn(err); return false; } });
|
||||
if(member) resolved.push(member);
|
||||
|
||||
} else if(/(id\:)?([0-9]{17,21})/.test(resolveable)) {
|
||||
|
||||
let id = resolveable.match(/(id\:)?([0-9]{17,21})/)[2];
|
||||
let member = await members.fetch(id).catch(err => { if(err.code === 10007) return false; else { console.warn(err); return false; } });
|
||||
if(member) resolved.push(member);
|
||||
|
||||
} else if(/^\@?([\S\s]{1,32})\#([0-9]{4})/.test(resolveable)) {
|
||||
|
||||
let m = resolveable.match(/^\@?([\S\s]{1,32})\#([0-9]{4})/);
|
||||
let username = m[1].toLowerCase();
|
||||
let discrim = m[2].toLowerCase();
|
||||
let member = members.cache.filter(m => {
|
||||
return m.user.username.toLowerCase() === username && m.user.discriminator === discrim
|
||||
}).first(1);
|
||||
if(member) resolved.push(member);
|
||||
|
||||
} else if(/^\@?([\S\s]{1,32})/.test(resolveable) && guild && !strict) {
|
||||
|
||||
let nickname = resolveable.match(/^\@?([\S\s]{1,32})/)[0].toLowerCase();
|
||||
let member = members.cache.filter((m) => {
|
||||
return (m && m.user) &&
|
||||
((!m.nickname ? false : m.nickname.toLowerCase() == nickname ) ||
|
||||
(!m.nickname ? false : m.nickname.toLowerCase().includes(nickname)) ||
|
||||
m.user.username.toLowerCase().includes(nickname) ||
|
||||
m.user.username.toLowerCase() == nickname);
|
||||
}).first(1);
|
||||
if(member) resolved.push(member);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resolved;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user