From 922a90be69845bc0596bd97f4f10d6c1ba4b5514 Mon Sep 17 00:00:00 2001 From: marios Date: Sun, 12 Jan 2020 18:57:01 +0200 Subject: [PATCH] notif channel id is now settable from within the bot also added docker files --- Animebyter/Dockerfile | 14 ++++++++++++ Animebyter/animebyter.py | 41 +++++++++++++++++++++++++++-------- Animebyter/docker-compose.yml | 22 +++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 Animebyter/Dockerfile create mode 100644 Animebyter/docker-compose.yml diff --git a/Animebyter/Dockerfile b/Animebyter/Dockerfile new file mode 100644 index 0000000..a9a4e58 --- /dev/null +++ b/Animebyter/Dockerfile @@ -0,0 +1,14 @@ +FROM python:alpine3.7 + +RUN apk add build-base +RUN apk add libffi-dev +RUN apk add openssl-dev +RUN apk add python3-dev + +COPY . /app +WORKDIR /app +ENV interval 300 + +RUN pip install -r requirements.txt + +CMD python3 animebyter.py \ No newline at end of file diff --git a/Animebyter/animebyter.py b/Animebyter/animebyter.py index 6e7210b..2b53dee 100644 --- a/Animebyter/animebyter.py +++ b/Animebyter/animebyter.py @@ -11,8 +11,18 @@ client = Bot('ab!') QB_URL = getenv("qbit_url") INTERVAL = int(getenv("INTERVAL")) if getenv("INTERVAL") else 300 web = ClientSession() -db = TinyDB("animebyter.json") -chn = int(getenv("channel")) +db = TinyDB(getenv("database_path","animebyter.json")) +path = getenv("download_path") + +def get_channel_id(): + res = db.search(Query().type == 'channel') + if len(res) > 0: + chn = res[0]['id'] + else: + db.insert({'type':'channel','id':''}) + chn = None + return chn +get_channel_id() downloading = [] @@ -49,9 +59,8 @@ async def get_airing(): async def add_torrent(anime): print("Adding episode {} of {}".format(anime.last_episode,anime.title)) - path = "/mnt/Storage/Anime" try: - res = await web.post(QB_URL+'/command/download',data={'urls':anime.torrent_link,'savepath':join(path,anime.title),'label':'Anime'}) + res = await web.post(QB_URL+'/command/download',data={'urls':anime.torrent_link,'savepath':join(path,anime.title),'category':'Anime'}) except Exception as e: print(str(e)) return @@ -77,7 +86,7 @@ async def main(): if le {} has finished downloading.".format(i)) + await client.get_channel(get_channel_id()).send(":exclamation: <@!196224042988994560> {} has finished downloading.".format(i)) else: print("Something went wrong with fetching downloads ({}: {})".format(res.status,await res.text())) except Exception as e: @@ -121,9 +130,16 @@ def chunks(s, n=1999): @client.command(pass_context=True) async def add(ctx): airing = await get_airing() + already_added = [] txt = "" - for i,v in enumerate(airing): + i = 0 + for v in airing: + if v.title in already_added: + continue + else: + already_added.append(v.title) txt+="{}) {}\n".format(i,v.title) + i += 1 msgs = [] for i in chunks(txt): msgs.append(await ctx.send(i)) @@ -146,6 +162,8 @@ async def remove(ctx): watching = db.all() txt = "" for i,v in enumerate(watching): + if not 'title' in v: + continue txt+="{}) {}\n".format(i,v['title']) msgs = [] for i in chunks(txt): @@ -164,7 +182,7 @@ async def remove(ctx): return await ctx.send("Invalid number") an = watching[msg] db.remove(Query().title==an['title']) - return await ctx.send("Removed {}".format(an)) + return await ctx.send("Removed {}".format(an['title'])) @client.command(pass_context=True) async def down(ctx): @@ -187,6 +205,11 @@ async def down(ctx): return await ctx.send("Invalid number") await ctx.send(await add_torrent(airing[msg])) +@client.command(pass_context=True) +async def setchannel(ctx): + db.update({'id':ctx.channel.id},Query().type == 'channel') + await ctx.send("I will now send notifications to this channel!") + @client.event async def on_ready(): print("Starting animebyter") diff --git a/Animebyter/docker-compose.yml b/Animebyter/docker-compose.yml new file mode 100644 index 0000000..23ce208 --- /dev/null +++ b/Animebyter/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3' +services: + animebyter: + build: . + container_name: animebyter + environment: + - qbit_url=http://qbittorrent:8080 + - qbit_user=admin + - qbit_pass=adminadmin + - ab_key=YOUR_ANIMEBYTES_KEY + - discord_token=YOUR_DISCORD_TOKEN + - download_path=/Anime + volumes: + - ./db:/db + networks: + - qbit-network + restart: unless-stopped + +networks: + qbit-network: + external: + name: qbittorrent_qbit-network \ No newline at end of file