1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Add a convert method

This commit is contained in:
phxntxm 2017-06-27 19:14:40 -05:00
parent 49ac1ac6f3
commit 5f6615d370

View file

@ -2,6 +2,7 @@ import aiohttp
from io import BytesIO
import inspect
import discord
from discord.ext import commands
from . import config
from PIL import Image
@ -96,6 +97,34 @@ async def request(url, *, headers=None, payload=None, method='GET', attr='json')
except:
continue
async def convert(ctx, option):
"""Tries to convert a string to an object of useful representiation"""
cmd = ctx.bot.get_command(option)
if cmd:
return cmd
async def do_convert(converter, _ctx, _option):
try:
return await converter.convert(_ctx, _option)
except commands.converter.BadArgument:
return None
member = await do_convert(commands.converter.MemberConverter(), ctx, option)
if member:
return member
channel = await do_convert(commands.converter.TextChannelConverter(), ctx, option)
if channel:
return channel
channel = await do_convert(commands.converter.VoiceChannelConverter(), ctx, option)
if channel:
return channel
role = await do_convert(commands.converter.RoleConverter(), ctx, option)
if role:
return role
async def update_records(key, db, winner, loser):
# We're using the Harkness scale to rate