-
Notifications
You must be signed in to change notification settings - Fork 0
/
converters.py
36 lines (33 loc) · 1.35 KB
/
converters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from discord.ext import commands
import re
from utils import get_member_name
class Player(commands.MemberConverter):
async def convert(self, ctx, argument):
bot = ctx.bot
match = self._get_id_match(argument) or re.match(r'<@!?([0-9]+)>$', argument)
guild = ctx.guild
result = None
if match is None:
# not a mention...
if guild:
result = guild.get_member_named(argument)
if not result:
result = guild.get_member_named(argument.lower())
else:
result = _get_from_guilds(bot, 'get_member_named', argument)
if not result:
result = _get_from_guilds(bot, 'get_member_named', argument.lower())
else:
user_id = int(match.group(1))
if guild:
result = guild.get_member(user_id) or _utils_get(ctx.message.mentions, id=user_id)
else:
result = _get_from_guilds(bot, 'get_member', user_id)
if not result:
members = guild.members
for m in members:
if get_member_name(m) == get_member_name(argument):
return m
if result is None:
raise BadArgument('Member "{}" not found'.format(argument))
return result