From ad7809bbb2cd25d51ff27c3c13bdbafd7e95cf25 Mon Sep 17 00:00:00 2001 From: Sleepingpirates <32914211+Sleepingpirates@users.noreply.github.com> Date: Thu, 4 Jun 2020 22:00:26 -0400 Subject: [PATCH] Add files via upload --- Dockerfile | 7 +++++ Invitarr-docker.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Dockerfile create mode 100644 Invitarr-docker.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2a9f708 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python +COPY . /app +WORKDIR /app +RUN pip install discord.py +RUN pip install plex.py +RUN pip install plexapi +CMD python -u ./Invitarr-docker.py diff --git a/Invitarr-docker.py b/Invitarr-docker.py new file mode 100644 index 0000000..43971bc --- /dev/null +++ b/Invitarr-docker.py @@ -0,0 +1,66 @@ +#Copyright 2020 Sleepingpirate. +from os import environ +import discord +from discord.ext import commands +import asyncio +from plexapi.myplex import MyPlexAccount +from discord import Webhook, AsyncWebhookAdapter +import aiohttp + + + +# settings +Discord_bot_token = environ.get('discord_bot_token') +roleid = int(environ.get('roleid')) # Role Id, right click the role and copy id. +PLEXUSER = environ.get('PLEXUSER') # Plex Username +PLEXPASS = environ.get('PLEXPASS') # plex password +PLEX_SERVER_NAME = environ.get('PLEX_SERVER_NAME') # Name of plex server +Plex_LIBS = environ.get('Plex_LIBS') #name of the libraries you want the user to have access to. +Webhookurl = environ.get('Webhookurl') # For logging the user repiles, create a webhook to the discord channel you want to log this in. + +li = list(Plex_LIBS.split(',')) +Plex_LIBS = li + +account = MyPlexAccount(PLEXUSER, PLEXPASS) +plex = account.resource(PLEX_SERVER_NAME).connect() # returns a PlexServer instance + +class MyClient(discord.Client): + async def on_ready(self): + print('Made by Sleepingpirate https://github.com/Sleepingpirates/') + print('Logged in as') + print(self.user.name) + print(self.user.id) + print('------') + + async def on_member_update(self, before, after): + role = after.guild.get_role(roleid) + if (role in after.roles and role not in before.roles): + await after.send('Welcome To The Plex. Just reply with your email so we can add you to Plex!') + await after.send('I will wait 10 minutes for your message, if you do not send it by then I will cancel the command.') + def check(m): + return m.author == after and not m.guild + try: + email = await client.wait_for('message', timeout=600, check=check) + except asyncio.TimeoutError: + await after.send('Timed Out. Message Server Admin So They Can Add You Manually.') + else: + await asyncio.sleep(5) + await after.send('Got it we will be processing your email shortly') + print(email.content) #make it go to a log channel + plexname = str(email.content) + try: + plex.myPlexAccount().inviteFriend(user=plexname, server=plex, sections=Plex_LIBS, allowSync=False, + allowCameraUpload=False, allowChannels=False, filterMovies=None, + filterTelevision=None, filterMusic=None) + await asyncio.sleep(20) + + except Exception as e: + print(e) + else: + await after.send('You have Been Added To Plex!') + async with aiohttp.ClientSession() as session: + webhook = Webhook.from_url(Webhookurl, adapter=AsyncWebhookAdapter(session)) + await webhook.send(plexname + ' ' + after.mention + ' was added to plex', username='Logger') + +client = MyClient() +client.run(Discord_bot_token)