コード例 #1
0
ファイル: plex_manager.py プロジェクト: smashingtags/Arca
 async def on_message(self, message):
     if settings.AUTO_WINNERS:
         if message.author.id == settings.GIVEAWAY_BOT_ID and "congratulations" in message.content.lower(
         ) and message.mentions:
             tempWinner = discord.utils.get(
                 message.guild.roles, name=settings.TEMP_WINNER_ROLE_NAME)
             for u in message.mentions:
                 await u.add_roles(
                     tempWinner,
                     reason="Winner - access winner invite channel")
         if message.channel.id == settings.WINNER_CHANNEL and discord.utils.get(
                 message.guild.roles, name=settings.TEMP_WINNER_ROLE_NAME
         ) in message.author.roles:
             plexname = message.content.strip(
             )  # Only include username, nothing else
             await message.channel.send(
                 "Adding " + plexname +
                 ". Please wait about 30 seconds...\n"
                 "Be aware, you will be removed from this channel once you are added "
                 "successfully.")
             try:
                 serverNumber = None
                 if settings.MULTI_PLEX:
                     serverNumber = px.getSmallestServer()
                 await add_to_plex(plexname, message.author.id, 'w',
                                   serverNumber)
                 await message.channel.send(
                     message.author.mention + " You've been invited, " +
                     plexname + ". Welcome to " +
                     settings.PLEX_SERVER_NAME[serverNumber] + "!")
                 await message.author.remove_roles(
                     discord.utils.get(message.guild.roles,
                                       name=settings.TEMP_WINNER_ROLE_NAME),
                     reason="Winner was processed successfully.")
             except plexapi.exceptions.BadRequest:
                 await message.channel.send(
                     message.author.mention + ", " + plexname +
                     " is not a valid Plex username.")
コード例 #2
0
ファイル: plex_manager.py プロジェクト: smashingtags/Arca
 async def pm_add(self,
                  ctx: commands.Context,
                  user: discord.Member,
                  PlexUsername: str,
                  serverNumber: int = None):
     """
     Add a Discord user to Plex
     Mention the Discord user and their Plex username
     Include optional serverNumber to add to a specific server (if using multiple Plex servers)
     """
     if settings.MULTI_PLEX:
         if serverNumber is None:  # No specific number indicated. Defaults adding to the least-fill server
             serverNumber = px.getSmallestServer()
         elif serverNumber > len(settings.PLEX_SERVER_URL):
             await ctx.send("That server number does not exist.")
         else:
             serverNumber = serverNumber - 1  # user's "server 5" is really server 4 in the index
         await ctx.send('Adding ' + PlexUsername + ' to ' +
                        settings.PLEX_SERVER_NAME[serverNumber] +
                        '. Please wait about 30 seconds...')
         try:
             note = 's'
             if discord.utils.get(
                     self.bot.get_guild(int(
                         settings.DISCORD_SERVER_ID)).roles,
                     name=settings.WINNER_ROLE_NAME) in user.roles:
                 note = 'w'
             added = await add_to_plex(PlexUsername, user.id, note,
                                       serverNumber)
             if added[0] and not added[1]:
                 role = discord.utils.get(
                     ctx.message.guild.roles,
                     name=settings.AFTER_APPROVED_ROLE_NAME)
                 await user.add_roles(role,
                                      reason="Access membership channels")
                 await ctx.send(user.mention + " You've been invited, " +
                                PlexUsername + ". Welcome to " +
                                settings.PLEX_SERVER_NAME[serverNumber] +
                                "!")
             elif added[1]:
                 await ctx.send("That {} is blacklisted.".format(added[1]))
             else:
                 await ctx.send(user.name +
                                " could not be added to that server.")
         except plexapi.exceptions.BadRequest:
             await ctx.send(PlexUsername + " is not a valid Plex username.")
     else:
         await ctx.send('Adding ' + PlexUsername + ' to ' +
                        settings.PLEX_SERVER_NAME[0] +
                        '. Please wait about 30 seconds...')
         try:
             note = 's'
             if discord.utils.get(
                     self.bot.get_guild(int(
                         settings.DISCORD_SERVER_ID)).roles,
                     name=settings.WINNER_ROLE_NAME) in user.roles:
                 note = 'w'
             added = await add_to_plex(PlexUsername, user.id, note,
                                       serverNumber)
             if added[0] and not added[1]:
                 role = discord.utils.get(
                     ctx.message.guild.roles,
                     name=settings.AFTER_APPROVED_ROLE_NAME)
                 await user.add_roles(role,
                                      reason="Access membership channels")
                 await ctx.send(user.mention + " You've been invited, " +
                                PlexUsername + ". Welcome to " +
                                settings.PLEX_SERVER_NAME[0] + "!")
             elif added[1]:
                 await ctx.send("That {} is blacklisted.".format(added[1]))
             else:
                 await ctx.send(user.name + " could not be added to Plex.")
         except plexapi.exceptions.BadRequest:
             await ctx.send(PlexUsername + " is not a valid Plex username.")
コード例 #3
0
ファイル: plex_manager.py プロジェクト: smashingtags/Arca
 async def pm_trial(self,
                    ctx: commands.Context,
                    user: discord.Member,
                    PlexUsername: str,
                    serverNumber: int = None):
     """
     Start a Plex trial
     """
     if settings.MULTI_PLEX:
         if serverNumber is None:  # No specific number indicated. Defaults adding to the least-fill server
             serverNumber = px.getSmallestServer()
         elif serverNumber > len(settings.PLEX_SERVER_URL):
             await ctx.send("That server number does not exist.")
         else:
             serverNumber = serverNumber - 1  # user's "server 5" is really server 4 in the index
         await ctx.send('Adding ' + PlexUsername + ' to ' +
                        settings.PLEX_SERVER_NAME[serverNumber] +
                        '. Please wait about 30 seconds...')
         try:
             added = await add_to_plex(PlexUsername, user.id, 't',
                                       serverNumber)
             if added[0] and not added[1]:
                 role = discord.utils.get(ctx.message.guild.roles,
                                          name=settings.TRIAL_ROLE_NAME)
                 await user.add_roles(role, reason="Trial started.")
                 await user.create_dm()
                 await user.dm_channel.send(
                     trial_message('start', serverNumber))
                 await ctx.send(
                     user.mention +
                     ", your trial has begun. Please check your Direct Messages for details."
                 )
             elif added[1]:
                 await ctx.send("That {} is blacklisted.".format(added[1]))
             else:
                 await ctx.send(user.name +
                                " could not be added to that server.")
         except plexapi.exceptions.BadRequest:
             await ctx.send(PlexUsername + " is not a valid Plex username.")
     else:
         await ctx.send('Starting ' + settings.PLEX_SERVER_NAME[0] +
                        ' trial for ' + PlexUsername +
                        '. Please wait about 30 seconds...')
         try:
             added = await add_to_plex(PlexUsername, user.id, 't')
             if added[0] and not added[1]:
                 role = discord.utils.get(ctx.message.guild.roles,
                                          name=settings.TRIAL_ROLE_NAME)
                 await user.add_roles(role, reason="Trial started.")
                 await user.create_dm()
                 await user.dm_channel.send(trial_message('start'))
                 await ctx.send(
                     user.mention +
                     ", your trial has begun. Please check your Direct Messages for details."
                 )
             elif added[1]:
                 await ctx.send("That {} is blacklisted.".format(added[1]))
             else:
                 await ctx.send(user.name + " could not be added to Plex.")
         except plexapi.exceptions.BadRequest:
             await ctx.send(PlexUsername + " is not a valid Plex username.")
コード例 #4
0
 async def pm_add(self,
                  ctx: commands.Context,
                  user: discord.Member,
                  PlexUsername: str,
                  serverNumber: int = None):
     """
     Add a Discord user to Plex
     Mention the Discord user and their Plex username
     Include optional serverNumber to add to a specific server (if using multiple Plex servers)
     """
     if not REACT_TO_ADD:
         if settings.MULTI_PLEX:
             if not serverNumber:  # No specific number indicated. Defaults adding to the least-fill server
                 serverNumber = px.getSmallestServer()
             elif serverNumber > len(settings.PLEX_SERVER_URL):
                 await ctx.send("That server number does not exist.")
             else:
                 serverNumber = serverNumber - 1  # user's "server 5" is really server 4 in the index
             await ctx.send('Adding ' + PlexUsername + ' to ' +
                            settings.PLEX_SERVER_NAME[serverNumber] +
                            '. Please wait about 60 seconds...')
             try:
                 added = await add_to_plex(PlexUsername, 's', serverNumber)
                 if added:
                     role = discord.utils.get(
                         ctx.message.guild.roles,
                         name=settings.AFTER_APPROVED_ROLE_NAME)
                     await user.add_roles(
                         role, reason="Access membership channels")
                     await ctx.send(
                         user.mention + " You've been invited, " +
                         PlexUsername + ". Welcome to " +
                         settings.PLEX_SERVER_NAME[serverNumber] + "!")
                 else:
                     await ctx.send(user.name +
                                    " could not be added to that server.")
             except plexapi.exceptions.BadRequest:
                 await ctx.send(PlexUsername +
                                " is not a valid Plex username.")
         else:
             await ctx.send('Adding ' + PlexUsername + ' to ' +
                            settings.PLEX_SERVER_NAME +
                            '. Please wait about 60 seconds...')
             try:
                 added = await add_to_plex(PlexUsername, 's', serverNumber)
                 if added:
                     role = discord.utils.get(
                         ctx.message.guild.roles,
                         name=settings.AFTER_APPROVED_ROLE_NAME)
                     await user.add_roles(
                         role, reason="Access membership channels")
                     await ctx.send(user.mention +
                                    " You've been invited, " +
                                    PlexUsername + ". Welcome to " +
                                    settings.PLEX_SERVER_NAME + "!")
                 else:
                     await ctx.send(user.name +
                                    " could not be added to Plex.")
             except plexapi.exceptions.BadRequest:
                 await ctx.send(PlexUsername +
                                " is not a valid Plex username.")
     else:
         await ctx.send(
             'This function is disabled. Please react to usernames to add to Plex.'
         )