def search(self, event, query: str): queries = [] if query.isdigit(): queries.append((User.user_id == query)) q = USER_MENTION_RE.findall(query) if len(q) and q[0].isdigit(): queries.append((User.user_id == q[0])) else: queries.append( (User.username**'%{}%'.format(query.replace('%', '')))) if '#' in query: username, discrim = query.rsplit('#', 1) if discrim is not None: queries.append(((User.username == username) & (User.discriminator == discrim))) users = User.select().where(reduce(operator.or_, queries)).limit(10) if len(users) == 0: raise CommandFail('No users found for query `{}`'.format( S(query, escape_codeblocks=True))) if len(users) == 1: if users[0].user_id in self.state.users: return self.info(event, self.state.users.get(users[0].user_id)) raise CommandSuccess( 'Found the following users for your query: ```{}```'.format( '\n'.join([ '{} ({})'.format(str(i), i.user_id) for i in users[:25] ])))
def search(self, event, query): queries = [] if query.isdigit(): queries.append((User.user_id == query)) q = USER_MENTION_RE.findall(query) if len(q) and q[0].isdigit(): queries.append((User.user_id == q[0])) else: queries.append((User.username ** u'%{}%'.format(query.replace('%', '')))) if '#' in query: username, discrim = query.rsplit('#', 1) if discrim.isdigit(): queries.append(( (User.username == username) & (User.discriminator == int(discrim)))) users = User.select().where(reduce(operator.or_, queries)) if len(users) == 0: return event.msg.reply(u'No users found for query `{}`'.format(S(query, escape_codeblocks=True))) if len(users) == 1: if users[0].user_id in self.state.users: return self.info(event, self.state.users.get(users[0].user_id)) return event.msg.reply(u'Found the following users for your query: ```{}```'.format( u'\n'.join(map(lambda i: u'{} ({})'.format(unicode(i), i.user_id), users[:25])) ))
def search_users(query=None): queries = [] if query.isdigit(): queries.append((User.user_id == query)) q = USER_MENTION_RE.findall(query) if len(q) and q[0].isdigit(): ids = [] ids.append(q[0]) return ids else: queries.append((User.username**u'%{}%'.format(query.replace('%', '')))) if '#' in query: username, discrim = query.rsplit('#', 1) if discrim.isdigit(): queries.append(((User.username == username) & (User.discriminator == int(discrim)))) users = User.select().where(reduce(operator.or_, queries)) if len(users) == 0: return [] return map(lambda i: i.user_id, users[:25])