mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
Helper method for cleaning command args, implicit truth tweak
This commit is contained in:
parent
ca0d7c7400
commit
4d6659d167
1 changed files with 49 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue