added notification tag command

This commit is contained in:
marios 2020-01-15 14:04:49 +02:00
parent 922a90be69
commit c9de243847

View File

@ -22,7 +22,18 @@ def get_channel_id():
db.insert({'type':'channel','id':''}) db.insert({'type':'channel','id':''})
chn = None chn = None
return chn return chn
def get_notif_id():
res = db.search(Query().type == 'notifications')
if len(res) > 0:
id = res[0]['id']
else:
db.insert({'type':'notifications','id':''})
id = None
return id
get_channel_id() get_channel_id()
get_notif_id()
downloading = [] downloading = []
@ -33,6 +44,12 @@ class Anime:
self.torrent_link = tl self.torrent_link = tl
self.resolution = res.strip() self.resolution = res.strip()
def __eq__(self,other):
return self.title == other.title
def __hash__(self):
return hash(self.title)
async def login_qb(): async def login_qb():
async with web.post(QB_URL+'/login',data={'username':getenv("qbit_user"),'password':getenv("qbit_pass")}) as res: async with web.post(QB_URL+'/login',data={'username':getenv("qbit_user"),'password':getenv("qbit_pass")}) as res:
if res.status!=200: if res.status!=200:
@ -113,7 +130,7 @@ async def dl_watchdog():
downloading.remove(i) downloading.remove(i)
except ValueError: except ValueError:
pass pass
await client.get_channel(get_channel_id()).send(":exclamation: <@!196224042988994560> {} has finished downloading.".format(i)) await client.get_channel(get_channel_id()).send(":exclamation: <@!{}> {} has finished downloading.".format(get_notif_id(),i))
else: else:
print("Something went wrong with fetching downloads ({}: {})".format(res.status,await res.text())) print("Something went wrong with fetching downloads ({}: {})".format(res.status,await res.text()))
except Exception as e: except Exception as e:
@ -129,17 +146,10 @@ def chunks(s, n=1999):
@client.command(pass_context=True) @client.command(pass_context=True)
async def add(ctx): async def add(ctx):
airing = await get_airing() airing = list(set(await get_airing()))
already_added = []
txt = "" txt = ""
i = 0 for i,v in enumerate(airing):
for v in airing:
if v.title in already_added:
continue
else:
already_added.append(v.title)
txt+="{}) {}\n".format(i,v.title) txt+="{}) {}\n".format(i,v.title)
i += 1
msgs = [] msgs = []
for i in chunks(txt): for i in chunks(txt):
msgs.append(await ctx.send(i)) msgs.append(await ctx.send(i))
@ -159,11 +169,9 @@ async def add(ctx):
@client.command(pass_context=True) @client.command(pass_context=True)
async def remove(ctx): async def remove(ctx):
watching = db.all() watching = [i for i in db.all() if 'title' in i]
txt = "" txt = ""
for i,v in enumerate(watching): for i,v in enumerate(watching):
if not 'title' in v:
continue
txt+="{}) {}\n".format(i,v['title']) txt+="{}) {}\n".format(i,v['title'])
msgs = [] msgs = []
for i in chunks(txt): for i in chunks(txt):
@ -210,6 +218,11 @@ async def setchannel(ctx):
db.update({'id':ctx.channel.id},Query().type == 'channel') db.update({'id':ctx.channel.id},Query().type == 'channel')
await ctx.send("I will now send notifications to this channel!") await ctx.send("I will now send notifications to this channel!")
@client.command(pass_context=True)
async def setnotif(ctx):
db.update({'id':ctx.author.id}, Query().type == 'notifications')
await ctx.send("I will now tag you for notifications!")
@client.event @client.event
async def on_ready(): async def on_ready():
print("Starting animebyter") print("Starting animebyter")