async def pingall(self, ctx, *, message: str = None): """ Ping everyone in all of your incomplete games Not useable by all players. **Examples** `[p]pingall My phone died and I will make all turns tomorrow` Send a message to everyone in all of your incomplete games `[p]pingall @Glouc3stershire Glouc is in Tahiti and will play again tomorrow` *Staff:* Send a message to everyone in another player's games """ if not message: return await ctx.send(f'Message is required.') m = utilities.string_to_user_id(message.split()[0]) if m: logger.debug('Third party use of pingall') # Staff member using command on third party if settings.get_user_level(ctx) <= 3: logger.debug('insufficient user level') return await ctx.send(f'You do not have permission to use this command on another player\'s games.') message = ' '.join(message.split()[1:]) # remove @Mention first word of message target = str(m) else: logger.debug('first party usage of pingall') # Play using command on their own games if settings.get_user_level(ctx) <= 2: logger.debug('insufficient user level') return await ctx.send(f'You do not have permission to use this command. You can ask a server staff member to use this command on your games for you.') target = str(ctx.author.id) logger.debug(f'pingall target is {target}') try: player_match = models.Player.get_or_except(player_string=target, guild_id=ctx.guild.id) except exceptions.NoSingleMatch: return await ctx.send(f'User <@{target}> is not a registered ELO player.') game_list = models.Game.search(player_filter=[player_match], status_filter=2, guild_id=ctx.guild.id) logger.debug(f'{len(game_list)} incomplete games for target') list_of_players = [] for g in game_list: list_of_players += [f'<@{l.player.discord_member.discord_id}>' for l in g.lineup] list_of_players = list(set(list_of_players)) logger.debug(f'{len(list_of_players)} unique opponents for target') clean_message = utilities.escape_role_mentions(message) if len(list_of_players) > 100: await ctx.send(f'*Warning:* More than 100 unique players are addressed. Only the first 100 will be mentioned.') await ctx.send(f'Message to all players in unfinished games for <@{target}>: *{clean_message}*') recipient_message = f'Message recipients: {" ".join(list_of_players[:100])}' return await ctx.send(recipient_message[:2000])
async def pingall(self, ctx, *message): """ Ping everyone in all of your incomplete games Not useable by all players. **Examples** `[p]pingall My phone died and I will make all turns tomorrow` Send a message to everyone in all of your incomplete games `[p]pingall @Glouc3stershire Glouc is in Tahiti and will play again tomorrow` *Staff:* Send a message to everyone in another player's games """ if not message: return await ctx.send(f'Message is required.') m = re.match(r"<@[!]?([0-9]{17,21})>", message[0]) if m: # Staff member using command on third party if settings.get_user_level(ctx) <= 4: return await ctx.send( f'You do not have permission to use this command on another player\'s games.' ) message = message[1:] target = m[1] else: # Play using command on their own games if settings.get_user_level(ctx) <= 3: return await ctx.send( f'You do not have permission to use this command. You can ask a server staff member to use this command on your games for you.' ) target = str(ctx.author.id) try: player_match = models.Player.get_or_except(player_string=target, guild_id=ctx.guild.id) except exceptions.NoSingleMatch: return await ctx.send( f'User <@{target}> is not a registered ELO player.') game_list = models.Game.search(player_filter=[player_match], status_filter=2, guild_id=ctx.guild.id) list_of_players = [] for g in game_list: list_of_players += [ f'<@{l.player.discord_member.discord_id}>' for l in g.lineup ] list_of_players = list(set(list_of_players)) clean_message = utilities.escape_role_mentions(' '.join(message)) if len(list_of_players) > 100: await ctx.send( f'*Warning:* More than 100 unique players are addressed. Only the first 100 will be mentioned.' ) await ctx.send( f'Message to all players in unfinished games for <@{target}>: *{clean_message}*' ) return await ctx.send( f'Message recipients: {" ".join(list_of_players[:100])}')
async def pingall(self, ctx, *, message: str = None): """ Ping everyone in all of your incomplete games Not useable by all players. You can use `pingsteam` to only ping players in your Steam platform games, or `pingmobile` to only ping players in your Mobile games. **Examples** `[p]pingall My phone died and I will make all turns tomorrow` Send a message to everyone in all of your incomplete games `[p]pingall @Glouc3stershire Glouc is in Tahiti and will play again tomorrow` *Staff:* Send a message to everyone in another player's games `[p]pingmobile My phone died but I'm still taking turns on Steam!` """ if not message: return await ctx.send('Message is required.') m = utilities.string_to_user_id(message.split()[0]) if m: logger.debug(f'Third party use of {ctx.invoked_with}') # Staff member using command on third party if settings.get_user_level(ctx.author) <= 3: logger.debug('insufficient user level') return await ctx.send( 'You do not have permission to use this command on another player\'s games.' ) message = ' '.join( message.split()[1:]) # remove @Mention first word of message target = str(m) log_message = f'{models.GameLog.member_string(ctx.author)} used pingall on behalf of player ID `{target}` with message: ' else: logger.debug('first party usage of pingall') # Play using command on their own games if settings.get_user_level(ctx.author) <= 2: logger.debug('insufficient user level') return await ctx.send( 'You do not have permission to use this command. You can ask a server staff member to use this command on your games for you.' ) target = str(ctx.author.id) log_message = f'{models.GameLog.member_string(ctx.author)} used {ctx.invoked_with} with message: ' try: player_match = models.Player.get_or_except(player_string=target, guild_id=ctx.guild.id) except exceptions.NoSingleMatch: return await ctx.send( f'User <@{target}> is not a registered ELO player.') if ctx.invoked_with == 'pingall': platform_filter = 2 title_str = 'Message to all players in unfinished games' elif ctx.invoked_with == 'pingmobile': platform_filter = 1 title_str = 'Message to players in unfinished mobile games' elif ctx.invoked_with == 'pingsteam': platform_filter = 0 title_str = 'Message to players in unfinished Steam games' else: raise ValueError( f'{ctx.invoked_with} is not a handled alias for this command') game_list = models.Game.search(player_filter=[player_match], status_filter=2, guild_id=ctx.guild.id, platform_filter=platform_filter) logger.debug(f'{len(game_list)} incomplete games for target') list_of_players = [] for g in game_list: list_of_players += g.mentions() list_of_players = list(set(list_of_players)) logger.debug(f'{len(list_of_players)} unique opponents for target') clean_message = utilities.escape_role_mentions(message) if len(list_of_players) > 100: await ctx.send( '*Warning:* More than 100 unique players are addressed. Only the first 100 will be mentioned.' ) await ctx.send( f'{title_str} for <@{target}> ({player_match.name}): *{clean_message}*' ) recipient_message = f'Message recipients: {" ".join(list_of_players[:100])}' await ctx.send(recipient_message[:2000]) for game in game_list: logger.debug( f'Sending message to game channels for game {game.id} from {ctx.invoked_with}' ) models.GameLog.write( game_id=game, guild_id=ctx.guild.id, message= f'{log_message} *{discord.utils.escape_markdown(clean_message)}*' ) await game.update_squad_channels( self.bot.guilds, game.guild_id, message= f'{title_str} for **{player_match.name}**: *{clean_message}*')