diff --git a/src/main/utils/utils.py b/src/main/utils/utils.py index 54195a0..3cd27e2 100644 --- a/src/main/utils/utils.py +++ b/src/main/utils/utils.py @@ -105,10 +105,58 @@ async def fetch(url, *, params={}, json=False): global session async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r: - if json is True: + if json: return await r.json() return await r.read() # def geneate_embed(**kwargs): # embed = d.Embed(title=kwargs['title'], ) + +def get_args(ctx, args, *, rem=False, rm=False, lim=False): + destination = ctx + remaining = list(args[:]) + remove = False + limit = 1 + + if '-d' in remaining or '-dm' in remaining: + destination = ctx.author + + try: + remaining.remove('-d') + except KeyError: + remaining.remove('-dm') + + if rm: + if ('-r' in remaining or '-rm' in remaining or '-remove' in remaining) and ctx.author.permissions_in(ctx.channel).manage_messages: + remove = True + print('remove') + + try: + remaining.remove('-r') + except KeyError: + try: + remaining.remove('-rm') + except KeyError: + remaining.remove('-remove') + + if lim: + for arg in remaining: + if len(arg) == 1: + with suppress(ValueError): + if int(arg) <= 3 and int(arg) >= 1: + limit = int(arg) + remaining.remove(arg) + break + else: + raise exc.BoundsError(arg) + + if rem: + if rm and lim: + return destination, remaining, remove, limit + if rm: + return destination, remaining, remove + if lim: + return destination, remaining, limit + return destination, remaining + return destination