added multiple roles
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#Copyright 2020 Sleepingpirate.
|
||||
import os
|
||||
from os import environ
|
||||
import logging
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import asyncio
|
||||
@@ -21,7 +22,7 @@ except:
|
||||
|
||||
# settings
|
||||
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')
|
||||
PLEXPASS = config.get(BOT_SECTION, 'plex_pass')
|
||||
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'))
|
||||
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 = li
|
||||
|
||||
#rolenames = list(roleid.split(','))
|
||||
|
||||
Plex_LIBS = list(Plex_LIBS.split(','))
|
||||
roleid = list(roleid.split(','))
|
||||
print(roleid)
|
||||
if auto_remove_user:
|
||||
print("auto remove user = True")
|
||||
import db as db
|
||||
@@ -76,8 +75,9 @@ class MyClient(discord.Client):
|
||||
await client.change_presence(activity=discord.Game(name="Admins can do -help"))
|
||||
|
||||
async def on_member_update(self, before, after):
|
||||
role = after.guild.get_role(roleid)
|
||||
secure = client.get_channel(chan)
|
||||
for role_for_plex in roleid:
|
||||
role = after.guild.get_role(int(role_for_plex))
|
||||
if (role in after.roles and role not in before.roles):
|
||||
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.')
|
||||
@@ -87,6 +87,7 @@ class MyClient(discord.Client):
|
||||
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.')
|
||||
return
|
||||
else:
|
||||
await asyncio.sleep(5)
|
||||
await after.send('Got it we will be processing your email shortly')
|
||||
@@ -100,6 +101,8 @@ class MyClient(discord.Client):
|
||||
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.')
|
||||
return
|
||||
|
||||
elif(role not in after.roles and role in before.roles):
|
||||
if auto_remove_user:
|
||||
try:
|
||||
@@ -114,7 +117,7 @@ class MyClient(discord.Client):
|
||||
print("Cannot remove this user from db.")
|
||||
except:
|
||||
print("Cannot remove this user from plex.")
|
||||
|
||||
return
|
||||
|
||||
async def on_message(self, message):
|
||||
secure = client.get_channel(chan)
|
||||
@@ -227,8 +230,6 @@ class MyClient(discord.Client):
|
||||
deleted = db.delete_user(user_id)
|
||||
if deleted:
|
||||
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:
|
||||
print("Cannot remove this user from db.")
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user