Example #1
0
 async def list(self, ctx, data_type):
     if not has_permissions(ctx, MOD_ROLE):
         await ctx.send(
             "You do not have sufficient permissions to perform this command",
             hidden=True)
         return False
     title = "List"
     info = []
     if data_type == "players":
         players = sorted(Player.fetch_players_list(),
                          key=lambda item: item.minecraft_username)
         title = "Registered Users"
         for player in players:
             player_string = f"**{player.minecraft_username}** ({self.bot.get_user(player.discord_id).mention if self.bot.get_user(player.discord_id) else '<@' + str(player.discord_id) + '> 🚫' })\n"
             for key in player.__dict__.keys():
                 player_string += f"> {key}: `{player.__dict__[key]}`\n"
             info.append(player_string)
     elif data_type == "register_requests":
         title = "IGN Registration Requests"
         requests = sorted(get_all_register_requests(),
                           key=lambda item: item[2])
         for request in requests:
             info.append(
                 f"**{request[2]}** ({self.bot.get_user(request[1]).mention if self.bot.get_user(request[1]) else '<@' + str(request[1]) + '> 🚫'})"
             )
     await create_list_pages(
         bot=self.bot,
         ctx=ctx,
         title=title,
         info=info,
         if_empty="There are no registration requests" if data_type
         == "register_requests" else "There are no registered players",
         elements_per_page=5)
Example #2
0
 async def update_usernames(self):
     server = self.bot_channel.guild
     changes_list = []
     for player in Player.fetch_players_list():
         old_username = player.minecraft_username
         latest_username = player.update_minecraft_username()
         if latest_username != old_username and latest_username is not None:
             changes_list.append([player, old_username])
         await async_sleep(1)
     if len(changes_list) > 0:
         embed = Embed(title="IGNs Updated", color=Colour.dark_purple())
         for change in changes_list:
             player = change[0]
             member = server.get_member(player.discord_id)
             old_username = change[1]
             if not member.nick:
                 member.nick = member.name
             team_list = re.findall(r"^\[(\w{1,4})\]", member.nick)
             alias_list = re.findall(r"\s\((.*)\)$", member.nick)
             new_nick = f"{'[' + team_list[0] + '] ' if team_list else ''}{player.minecraft_username}" + \
                        (f" ({alias_list[0]})" if alias_list else "")
             if UPDATE_NICKNAMES:
                 try:
                     await member.edit(nick=new_nick)
                 except Forbidden:
                     embed_value = f"🔴 Failed to update nickname to `{new_nick}` (Forbidden)"
                 else:
                     embed_value = f"Updated server nickname to `{new_nick}`"
                     try:
                         await success_embed(
                             member,
                             f"PUG server nickname updated to `{new_nick}`")
                         embed_value += " (DM sent)"
                     except Forbidden:
                         embed_value += " (confirmation DM failed to send)"
             else:
                 embed_value = "Nickname updates disabled in config."
             embed.add_field(
                 name=f"{old_username} → {player.minecraft_username}",
                 value=embed_value,
                 inline=False)
         await self.bot_channel.send(embed=embed)
Example #3
0
 async def prune_missing_players(self, ctx):
     """Removes registered players from the database who aren't in the server"""
     if not has_permissions(ctx, ADMIN_ROLE) and ctx.guild not in SLASH_COMMANDS_GUILDS:
         await ctx.send("You do not have sufficient permissions to perform this command", hidden=True)
         return False
     await ctx.defer()
     tz = timezone('US/Eastern')
     time = datetime.now(tz).strftime("%Y%m%d-%H%M%S")
     backup_filename = f"backups/database-{time}.db"
     copyfile("database/database.db", backup_filename)
     await success_embed(ctx, f"Created backup file: `{backup_filename}`")
     players = Player.fetch_players_list()
     guild_member_ids = [member.id for member in ctx.guild.members]
     deleted_player_names = []
     for player in players:
         if player.discord_id not in guild_member_ids:
             deleted_player_names.append(player.minecraft_username)
             player.delete()
     if deleted_player_names:
         await success_embed(ctx, f"Removed players `{', '.join(deleted_player_names)}` from database.")
     else:
         await error_embed(ctx, "No players to prune.")