Example #1
0
    async def on_member_update(self, before, after):
        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.'
                )

                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.'
                    )
                    return
                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.'
                        )
                    return

            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
Example #2
0
 async def on_member_remove(self, member):
     if auto_remove_user:
         try:
             user_id = member.id ## not there
             email = db.get_useremail(user_id)
             plexremove(email)
             deleted = db.delete_user(user_id)
             if deleted:
                 print("Removed {} from db".format(email))
             else:
                 print("Cannot remove this user from db.")
         except:
             print("Cannot remove this user from plex.")
Example #3
0
 async def on_member_remove(self, member):
     if auto_remove_user:
         try:
             user_id = member.id  ## not there
             email = db.get_useremail(user_id)
             plexremove(email)
             deleted = db.delete_user(user_id)
             if deleted:
                 print("Entfernt {} aus DB".format(email))
             else:
                 print("Kann User nicht aus DB entfernen.")
         except:
             print("Kann User nicht von **StreamNet** entfernen.")
Example #4
0
 async def on_member_remove(self, member):            
     if auto_remove_user:
         try:
             user_id = member.id ## not there 
             email = db.get_useremail(user_id)
             plexremove(email)
             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:
             print("Cannot remove this user from plex.")
Example #5
0
    async def on_member_update(self, before, after):
        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 Neptune! 🔱  Reply to this message with the email linked to your Plex account and I'll send you an invite.")
                await after.send("If I don't hear from you in 10 minutes, I'll cancel this request.")
                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("Time's up! ⏰ Contact the admin to have them add you manually.")
                    return
                else:
                    await asyncio.sleep(5)
                    await after.send("Thanks! You'll get an email with your invitation soon. 💌")
                    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're in! 🎉 Enjoy your time with Neptune and let us know if you have any questions.")
                        await secure.send(plexname + ' ' + after.mention + ' was added to plex')
                    else:
                        await after.send('There was an error adding this email address. Message the admin for help.')
                    return

            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
Example #6
0
    async def on_message(self, message):
        secure = client.get_channel(chan)

        if message.author.id == self.user.id:
            return

        if message.author.guild_permissions.administrator:
            if message.content.startswith('-plex add'):
                mgs = message.content.replace('-plex add ','')
                if plexadd(mgs):
                    await secure.send('The email has been added! {0.author.mention}'.format(message))
                else:
                    await secure.send('Error Check Logs! {0.author.mention}'.format(message))
            if message.content.startswith('-plex rm'):
                mgs = message.content.replace('-plex rm ','')
                if plexremove(mgs):
                    await secure.send('The email has been removed! {0.author.mention}'.format(message))
                else:
                    await secure.send('Error Check Logs! {0.author.mention}'.format(message))

        if message.author.guild_permissions.administrator:
           if message.content.startswith('-db add'):
               mgs = message.content.replace('-db add ','')
               try:
                   mgs = mgs.split(' ')
                   email = mgs[0]
                   if(plexadd(email)):
                     await message.channel.send('User has been added to plex.')
                   else:
                     await message.channel.send('Error adding email to plex. Ignore this if the email already exist in plex.')

                   bad_chars = ['<','>','@','!']
                   user_id = mgs[1]
                   for i in bad_chars:
                       user_id = user_id.replace(i, '')
                   db.save_user(user_id, email)
                   await message.channel.send(email + ' ' + mgs[1] + ' was added to the database.')
               except:
                   await message.channel.send('Cannot add this user to db.')
                   print("Cannot add this user to db.")
               #await message.delete()

        if message.author.guild_permissions.administrator:
            if message.content.startswith('-db ls') or message.content.startswith('-db rm'):
                embed = discord.Embed(title='Invitarr Database.')
                all = db.read_useremail()

                table = texttable.Texttable()
                table.set_cols_dtype(["t", "t", "t"])
                table.set_cols_align(["c", "c", "c"])
                header = ("#", "Name", "Email")
                table.add_row(header)

                for index, peoples in enumerate(all):
                    index = index + 1
                    id = int(peoples[1])
                    dbuser = client.get_user(id)
                    dbemail = peoples[2]
                    try:
                        username = dbuser.name
                    except:
                        username = "******"
                    embed.add_field(name=f"**{index}. {username}**", value=dbemail+'\n', inline=False)
                    table.add_row((index, username, dbemail))


                if message.content.startswith('-db ls'):
                    total = str(len(all))
                    if(len(all)>25):
                        f = open("db.txt", "w")
                        f.write(table.draw())
                        f.close()
                        await message.channel.send("Database too large! Total: {total}".format(total = total),file=discord.File('db.txt'))
                    else:
                        await message.channel.send(embed = embed)


                else:
                    try:
                        position = message.content.replace("-db rm", "")
                        position = int(position) - 1
                        id = all[position][1]
                        email = db.get_useremail(id)
                        deleted = db.delete_user(id)
                        if deleted:
                            print("Removed {} from db".format(email))
                            await secure.send("Removed {} from db".format(email))
                        else:
                            print("Cannot remove this user from db.")
                    except Exception as e:
                        print(e)

            if message.content.startswith('-help'):
                embed = discord.Embed(title='Invitarr Bot Commands', description='Made by [Sleepingpirates](https://github.com/Sleepingpirates/Invitarr), [Join Discord Server](https://discord.gg/vcxCytN)')
                embed.add_field(name='-plex add <email>', value='This command is used to add an email to plex', inline=False)
                embed.add_field(name='-plex rm <email>', value='This command is used to remove an email from plex', inline=False)
                embed.add_field(name='-db ls', value='This command is used list Invitarrs database', inline=False)
                embed.add_field(name='-db add <email> <@user>', value='This command is used to add exsisting users email and discord id to the DB. Bot tries to add email to plex', inline=False)
                embed.add_field(name='-db rm <position>', value='This command is used remove a record from the Db. Use -db ls to determine record position. ex: -db rm 1', inline=False)
                await message.channel.send(embed = embed)
Example #7
0
    async def on_member_update(self, before, after):
        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('**Willkommen** bei **' + PLEX_SERVER_NAME +
                                 '**.')
                await after.send(
                    'Antworte einfach mit deiner **PLEX Mail**, damit ich dich bei **StreamNet** hinzufügen kann!'
                )
                await after.send(
                    'Ich werde 10 Minuten auf deine Nachricht warten. Wenn du bis dahin nicht geantwortet hast, werde ich den Befehl abbrechen.'
                )

                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(
                        'Zeitüberschreitung. Wende dich an den Server Admin damit der dich manuell hinzufügen kann.'
                    )
                    return
                else:
                    await asyncio.sleep(5)
                    await after.send(
                        '**GOTCHA**, wir werden deine Email in kürze bearbeiten.'
                    )
                    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(
                            'Du wurdest bei **StreamNet** hinzugefügt!')
                        await secure.send(
                            plexname + ' ' + after.mention +
                            ' wurde bei **StreamNet** hinzugefügt')
                    else:
                        await after.send(
                            'Es gab ein Fehler beim Hinzufügen deiner Email. Bitte kontaktiere den Server Admin.'
                        )
                    return

            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("Entfernt {} aus DB".format(email))
                            await secure.send(
                                plexname + ' ' + after.mention +
                                ' wurde von **StreamNet** entfernt')
                        else:
                            print(
                                "Konnte diesen User nicht aus der DB entfernen."
                            )
                    except:
                        print(
                            "Konnte diesen User nicht von **StreamNet** entfernen."
                        )
                return