async def notify(self, ctx): """Notify command""" if ctx.invoked_subcommand is None: import globvars delta = time.time() - globvars.last_notify if delta < NOTIFY_COOLDOWN: msg = f"{ctx.author.mention} {botutils.BotEmoji.fquit} This command is rate-limited. Please try again in {display_time(int(NOTIFY_COOLDOWN - delta))}." await ctx.send(msg) return if botutils.check_if_lobby(ctx): globvars.last_notify = time.time() pings = [] users_to_ping = sorted(set(globvars.notify_list) - set(globvars.ignore_list)) for userid in users_to_ping: member = globvars.client.get_guild(SERVER_ID).get_member(userid) # member found, only ping them if they are not offline if member: if member.status != Status.offline and \ member.id not in globvars.master_state.pregame and \ member.id != ctx.author.id: pings.append(member.mention) # member not present in server, remove their id else: globvars.notify_list.remove(userid) msg = f"{ctx.author.mention} {botutils.BotEmoji.mention} {' '.join(pings)}" await ctx.send(msg)
def cog_check(self, ctx): """Check the channel of the context, return True if it is sent in either lobby, or in spec chat. Admins can bypass. """ return botutils.check_if_admin(ctx) or \ botutils.check_if_lobby(ctx) or \ botutils.check_if_spec(ctx)
async def notify(self, ctx): """Notify command""" if ctx.invoked_subcommand is None: import globvars if cooldown_map.get(len(globvars.master_state.pregame), 0) > time.time(): min_next_no_cd_players = 20 while cooldown_map.get( min_next_no_cd_players, None) is None or cooldown_map[ min_next_no_cd_players] < time.time(): min_next_no_cd_players -= 1 return await ctx.send( notify_cooldown.format( ctx.author.mention, BotEmoji.x_emoji, display_time( int(cooldown_map[len( globvars.master_state.pregame)] - time.time())), min_next_no_cd_players)) # Set cooldowns if botutils.check_if_lobby(ctx): for i in range(len(globvars.master_state.pregame), -1, -1): if cooldown_map.get( i, None) is None or cooldown_map[i] < time.time(): cooldown_map[i] = time.time() + NOTIFY_COOLDOWN users_to_ping = [] with sqlite3.connect("data.sqlite3") as conn: c = conn.cursor() c.execute(""" SELECT user_id, min_playercount, cooldown, always_notify FROM notify """) for user_id, min_playercount, cooldown, always_notify in c.fetchall( ): member = globvars.client.get_guild(SERVER_ID).get_member( user_id) # Do not ping the person that ran the command notify_map[ctx.author.id] = time.time() if (member and member.id not in globvars.master_state.pregame and len(globvars.master_state.pregame) >= min_playercount and time.time() - notify_map.get(member.id, 0) > cooldown and (always_notify == 1 or member.status != Status.offline) and member.id != ctx.author.id): notify_map[member.id] = time.time() users_to_ping.append(member.id) c.execute("SELECT user_id FROM ignore") for user_id, in c.fetchall(): if user_id in users_to_ping: users_to_ping.remove(user_id) if len(users_to_ping) > 0: pings = [] for user_id in users_to_ping: pings.append(botutils.make_ping(user_id)) pings = ' '.join(pings) msg = f"{ctx.author.mention} {BotEmoji.mention} {pings}" else: msg = no_users_to_notify.format(ctx.author.mention, BotEmoji.x_emoji) await ctx.send(msg)