major changes
added -plexadd removed webhook url
This commit is contained in:
@@ -8,7 +8,6 @@ from discord import Webhook, AsyncWebhookAdapter
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# settings
|
# settings
|
||||||
Discord_bot_token = environ.get('discord_bot_token')
|
Discord_bot_token = environ.get('discord_bot_token')
|
||||||
roleid = int(environ.get('roleid')) # Role Id, right click the role and copy id.
|
roleid = int(environ.get('roleid')) # Role Id, right click the role and copy id.
|
||||||
@@ -16,7 +15,7 @@ PLEXUSER = environ.get('PLEXUSER') # Plex Username
|
|||||||
PLEXPASS = environ.get('PLEXPASS') # plex password
|
PLEXPASS = environ.get('PLEXPASS') # plex password
|
||||||
PLEX_SERVER_NAME = environ.get('PLEX_SERVER_NAME') # Name of plex server
|
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.
|
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.
|
chan = int(environ.get('channelid'))
|
||||||
|
|
||||||
li = list(Plex_LIBS.split(','))
|
li = list(Plex_LIBS.split(','))
|
||||||
Plex_LIBS = li
|
Plex_LIBS = li
|
||||||
@@ -24,6 +23,20 @@ Plex_LIBS = li
|
|||||||
account = MyPlexAccount(PLEXUSER, PLEXPASS)
|
account = MyPlexAccount(PLEXUSER, PLEXPASS)
|
||||||
plex = account.resource(PLEX_SERVER_NAME).connect() # returns a PlexServer instance
|
plex = account.resource(PLEX_SERVER_NAME).connect() # returns a PlexServer instance
|
||||||
|
|
||||||
|
def plexadd(plexname):
|
||||||
|
try:
|
||||||
|
plex.myPlexAccount().inviteFriend(user=plexname, server=plex, sections=Plex_LIBS, allowSync=False,
|
||||||
|
allowCameraUpload=False, allowChannels=False, filterMovies=None,
|
||||||
|
filterTelevision=None, filterMusic=None)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
print(plexname +' has been added to plex (☞ຈل͜ຈ)☞')
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class MyClient(discord.Client):
|
class MyClient(discord.Client):
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print('Made by Sleepingpirate https://github.com/Sleepingpirates/')
|
print('Made by Sleepingpirate https://github.com/Sleepingpirates/')
|
||||||
@@ -35,7 +48,7 @@ class MyClient(discord.Client):
|
|||||||
async def on_member_update(self, before, after):
|
async def on_member_update(self, before, after):
|
||||||
role = after.guild.get_role(roleid)
|
role = after.guild.get_role(roleid)
|
||||||
if (role in after.roles and role not in before.roles):
|
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('Welcome To '+ PLEX_SERVER_NAME +'. 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.')
|
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):
|
def check(m):
|
||||||
return m.author == after and not m.guild
|
return m.author == after and not m.guild
|
||||||
@@ -48,19 +61,26 @@ class MyClient(discord.Client):
|
|||||||
await after.send('Got it we will be processing your email shortly')
|
await after.send('Got it we will be processing your email shortly')
|
||||||
print(email.content) #make it go to a log channel
|
print(email.content) #make it go to a log channel
|
||||||
plexname = str(email.content)
|
plexname = str(email.content)
|
||||||
try:
|
if plexadd(plexname):
|
||||||
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)
|
await asyncio.sleep(20)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
else:
|
|
||||||
await after.send('You have Been Added To Plex!')
|
await after.send('You have Been Added To Plex!')
|
||||||
async with aiohttp.ClientSession() as session:
|
secure = client.get_channel(chan)
|
||||||
webhook = Webhook.from_url(Webhookurl, adapter=AsyncWebhookAdapter(session))
|
await secure.send(plexname + ' ' + after.mention + ' was added to plex')
|
||||||
await webhook.send(plexname + ' ' + after.mention + ' was added to plex', username='Logger')
|
else:
|
||||||
|
await after.send('There was an error adding this email address. Message Server Admin.')
|
||||||
|
|
||||||
|
async def on_message(self, message):
|
||||||
|
secure = client.get_channel(chan)
|
||||||
|
if message.author.id == self.user.id:
|
||||||
|
return
|
||||||
|
|
||||||
|
if str(message.channel) == str(secure):
|
||||||
|
if message.content.startswith('-plexadd'):
|
||||||
|
mgs = message.content.replace('-plexadd ','')
|
||||||
|
if plexadd(mgs):
|
||||||
|
await message.channel.send('The email has been added! {0.author.mention}'.format(message))
|
||||||
|
else:
|
||||||
|
message.channel.send('Error Check Logs! {0.author.mention}'.format(message))
|
||||||
|
|
||||||
client = MyClient()
|
client = MyClient()
|
||||||
client.run(Discord_bot_token)
|
client.run(Discord_bot_token)
|
||||||
|
|||||||
Reference in New Issue
Block a user