added multiple roles

This commit is contained in:
Sleepingpirates
2020-07-23 01:03:01 +00:00
parent c6b5556df7
commit 8dea30384a

View File

@@ -1,6 +1,7 @@
#Copyright 2020 Sleepingpirate. #Copyright 2020 Sleepingpirate.
import os import os
from os import environ from os import environ
import logging
import discord import discord
from discord.ext import commands from discord.ext import commands
import asyncio import asyncio
@@ -21,7 +22,7 @@ except:
# settings # settings
Discord_bot_token = config.get(BOT_SECTION, 'discord_bot_token') Discord_bot_token = config.get(BOT_SECTION, 'discord_bot_token')
roleid = int(config.get(BOT_SECTION, 'role_id')) roleid = config.get(BOT_SECTION, 'role_id')
PLEXUSER = config.get(BOT_SECTION, 'plex_user') PLEXUSER = config.get(BOT_SECTION, 'plex_user')
PLEXPASS = config.get(BOT_SECTION, 'plex_pass') PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name') PLEX_SERVER_NAME = config.get(BOT_SECTION, 'plex_server_name')
@@ -30,11 +31,9 @@ chan = int(config.get(BOT_SECTION, 'channel_id'))
ownerid = int(config.get(BOT_SECTION, 'owner_id')) ownerid = int(config.get(BOT_SECTION, 'owner_id'))
auto_remove_user = config.get(BOT_SECTION, 'auto_remove_user') if config.get(BOT_SECTION, 'auto_remove_user') else False auto_remove_user = config.get(BOT_SECTION, 'auto_remove_user') if config.get(BOT_SECTION, 'auto_remove_user') else False
li = list(Plex_LIBS.split(',')) Plex_LIBS = list(Plex_LIBS.split(','))
Plex_LIBS = li roleid = list(roleid.split(','))
print(roleid)
#rolenames = list(roleid.split(','))
if auto_remove_user: if auto_remove_user:
print("auto remove user = True") print("auto remove user = True")
import db as db import db as db
@@ -76,45 +75,49 @@ class MyClient(discord.Client):
await client.change_presence(activity=discord.Game(name="Admins can do -help")) await client.change_presence(activity=discord.Game(name="Admins can do -help"))
async def on_member_update(self, before, after): async def on_member_update(self, before, after):
role = after.guild.get_role(roleid)
secure = client.get_channel(chan) secure = client.get_channel(chan)
if (role in after.roles and role not in before.roles): for role_for_plex in roleid:
await after.send('Welcome To '+ PLEX_SERVER_NAME +'. Just reply with your email so we can add you to Plex!') role = after.guild.get_role(int(role_for_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.') if (role in after.roles and role not in before.roles):
def check(m): await after.send('Welcome To '+ PLEX_SERVER_NAME +'. Just reply with your email so we can add you to Plex!')
return m.author == after and not m.guild await after.send('I will wait 10 minutes for your message, if you do not send it by then I will cancel the command.')
try: def check(m):
email = await client.wait_for('message', timeout=600, check=check) return m.author == after and not m.guild
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)
if plexadd(plexname):
if auto_remove_user:
db.save_user(str(after.id), email.content)
await asyncio.sleep(20)
await after.send('You have Been Added To Plex!')
await secure.send(plexname + ' ' + after.mention + ' was added to plex')
else:
await after.send('There was an error adding this email address. Message Server Admin.')
elif(role not in after.roles and role in before.roles):
if auto_remove_user:
try: try:
user_id = after.id email = await client.wait_for('message', timeout=600, check=check)
email = db.get_useremail(user_id) except asyncio.TimeoutError:
plexremove(email) await after.send('Timed Out. Message Server Admin So They Can Add You Manually.')
deleted = db.delete_user(user_id) return
if deleted: else:
print("Removed {} from db".format(email)) await asyncio.sleep(5)
await secure.send(plexname + ' ' + after.mention + ' was removed from plex') 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)
if plexadd(plexname):
if auto_remove_user:
db.save_user(str(after.id), email.content)
await asyncio.sleep(20)
await after.send('You have Been Added To Plex!')
await secure.send(plexname + ' ' + after.mention + ' was added to plex')
else: else:
print("Cannot remove this user from db.") await after.send('There was an error adding this email address. Message Server Admin.')
except: return
print("Cannot remove this user from plex.")
elif(role not in after.roles and role in before.roles):
if auto_remove_user:
try:
user_id = after.id
email = db.get_useremail(user_id)
plexremove(email)
deleted = db.delete_user(user_id)
if deleted:
print("Removed {} from db".format(email))
await secure.send(plexname + ' ' + after.mention + ' was removed from plex')
else:
print("Cannot remove this user from db.")
except:
print("Cannot remove this user from plex.")
return
async def on_message(self, message): async def on_message(self, message):
secure = client.get_channel(chan) secure = client.get_channel(chan)
@@ -227,8 +230,6 @@ class MyClient(discord.Client):
deleted = db.delete_user(user_id) deleted = db.delete_user(user_id)
if deleted: if deleted:
print("Removed {} from db".format(email)) print("Removed {} from db".format(email))
secure = client.get_channel(chan)
#await secure.send(email + ' ' + member.mention + 'was removed from plex because they left the server')
else: else:
print("Cannot remove this user from db.") print("Cannot remove this user from db.")
except: except: