From a8f7acc3f389dc85e76e6e787045f7282f588559 Mon Sep 17 00:00:00 2001 From: Navy Date: Thu, 9 Apr 2020 12:18:14 +0300 Subject: [PATCH] user and member resolvers --- middleware/client/Resolver.js | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/middleware/client/Resolver.js b/middleware/client/Resolver.js index c8bdb19..a12712f 100644 --- a/middleware/client/Resolver.js +++ b/middleware/client/Resolver.js @@ -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; + } }