async def timeout(self, ctx, *args): if len(args) == 1 and args[0] == "help": await disp.RM_TIMEOUT_HELP.send(ctx) return if len(ctx.message.mentions) != 1: await disp.RM_MENTION_ONE.send(ctx) return player = Player.get(ctx.message.mentions[0].id) if not player: # player isn't even registered in the system... player = Player(ctx.message.mentions[0].id, ctx.message.mentions[0].name) await db.async_db_call(db.set_element, "users", player.id, player.get_data()) if player.is_lobbied: lobby.remove_from_lobby(player) await disp.RM_LOBBY.send( ContextWrapper.channel(cfg.channels["lobby"]), player.mention, names_in_lobby=lobby.get_all_names_in_lobby()) if player.match: await disp.RM_IN_MATCH.send(ctx) return if len(args) == 0: if player.is_timeout: await disp.RM_TIMEOUT_INFO.send( ctx, dt.utcfromtimestamp( player.timeout).strftime("%Y-%m-%d %H:%M UTC")) return await roles.role_update(player) await roles.perms_muted(False, player.id) await disp.RM_TIMEOUT_NO.send(ctx) return # =timeout @player remove if len(args) == 1 and args[0] == 'remove': player.timeout = 0 await player.db_update("timeout") await disp.RM_TIMEOUT_FREE.send(ctx, player.mention) await roles.role_update(player) await roles.perms_muted(False, player.id) return # Check if command is correct (=timeout @player 12 d) time = tools.time_calculator(" ".join(args)) if time == 0: await disp.RM_TIMEOUT_INVALID.send(ctx) return end_time = tools.timestamp_now() + time player.timeout = end_time await roles.role_update(player) await player.db_update("timeout") await roles.perms_muted(True, player.id) await disp.RM_TIMEOUT.send( ctx, player.mention, dt.utcfromtimestamp(end_time).strftime("%Y-%m-%d %H:%M UTC"))
async def is_spam(author, channel, ctx=None): a_id = author.id if a_id in __spam_list and __spam_list[a_id] > 0: if a_id in __last_requests and __last_requests[ a_id] < tools.timestamp_now() - 30: log.info( f"Automatically unlocked id[{a_id}], name[{author.name}] from spam filter" ) unlock(a_id) __last_requests[a_id] = tools.timestamp_now() if a_id not in __spam_list: __spam_list[a_id] = 1 return False __spam_list[a_id] += 1 if __spam_list[a_id] == 1: return False if __spam_list[a_id] % __SPAM_MSG_FREQUENCY == 0: if not ctx: ctx = ContextWrapper.wrap(channel, author=author) await disp.STOP_SPAM.send(ctx) return True
async def start_match_loop(self): self.match.plugin_manager.on_match_starting() await disp.MATCH_STARTING_1.send(self.match.channel, self.match.round_no, "30") await sleep(10) await disp.MATCH_STARTING_2.send(self.match.channel, self.match.round_no, "20") await sleep(10) await disp.MATCH_STARTING_2.send(self.match.channel, self.match.round_no, "10") await sleep(10) player_pings = [" ".join(tm.all_pings) for tm in self.match.teams] await disp.MATCH_STARTED.send(self.match.channel, *player_pings, self.match.round_no) self.match.plugin_manager.on_match_started() self.match.round_stamps.append(tools.timestamp_now()) super().change_status(MatchStatus.IS_PLAYING) self.match_loop.start() self.auto_info_loop.start() self.match.status = MatchStatus.IS_PLAYING
async def _lobby_loop(): for p in _lobby_list: now = tools.timestamp_now() if p.lobby_stamp < (now - 7800): remove_from_lobby(p) await disp.LB_TOO_LONG.send( ContextWrapper.channel(cfg.channels["lobby"]), p.mention, names_in_lobby=get_all_names_in_lobby()) elif p.lobby_stamp < (now - 7200): if p not in _warned_players: ih = interactions.InteractionHandler(p, views.reset_button) _warned_players[p] = ih _add_ih_callback(ih, p) ctx = ih.get_new_context( ContextWrapper.channel(cfg.channels["lobby"])) await disp.LB_WARNING.send(ctx, p.mention)
async def get_new_stats(match_cls, player, time=tools.timestamp_now() - 1209600): m_list = get_matches_in_time(player, time) new_p_stats = PlayerStat(player.id, player.name) for m_id in m_list: match = await match_cls.get_from_database(m_id) if not match: log.error( f"get_new_stats: Couldn't find match {m_id} in database!") continue found = False for tm in match.data.teams: for p_score in tm.players: if int(p_score.id) == player.id: p_score.stats = new_p_stats p_score.update_stats() found = True break if found: break return new_p_stats
async def stats(self, ctx, *args): if len(ctx.message.mentions) == 1: p_id = ctx.message.mentions[0].id else: await disp.RM_MENTION_ONE.send(ctx) return stat_player = await PlayerStat.get_from_database(p_id, "N/A") if stat_player.nb_matches_played == 0: await disp.NO_DATA.send(ctx) return time = 0 if len(args) > 0: time = tools.time_calculator(" ".join(args)) if time == 0: await disp.WRONG_USAGE.send(ctx, ctx.command.name) return time = tools.timestamp_now() - tools.time_calculator( " ".join(args)) else: time = stat_processor.oldest num = len(stat_processor.get_matches_in_time(stat_player, time)) t_str = tools.time_diff(time) num_str = "" suffix = "" if num == 0: num_str = "no" else: num_str = str(num) if num > 1: suffix = "es" await disp.DISPLAY_USAGE.send( ctx, p_id, num_str, suffix, t_str, dt.utcfromtimestamp(time).strftime("%Y-%m-%d %H:%M UTC"))
def on_faction_pick(self, team): self.__auto_dict_add("factions", {"team": team.id, "timestamp": timestamp_now(), "faction": cfg.factions[team.faction]}) self.__event(f"on_faction_pick: team: [{team.id}] picked: [{cfg.factions[team.faction]}]")
def on_teams_done(self): self.data["teams_done"] = timestamp_now() self.__event("on_teams_done")
def on_captain_selected(self, i, player): self.__auto_dict_add("captains", {"team": i, "timestamp": timestamp_now(), "player": player.id}) self.__event(f"on_captain_selected: id: [{player.id}], name: [{player.name}]")
def on_match_launching(self): self.data = {"_id": self.match.id, "match_launching": timestamp_now()} self.__event("on_match_launching")
def on_lobby_add(self): self.__lobby_stamp = tools.timestamp_now() self.update_role()
def is_last_used(base): for i in range(2): if base.id == last_base[i][0]: if last_base[i][1] > (tools.timestamp_now() - 14400): return True return False
def on_match_over(self): self.data["match_over"] = timestamp_now() self.__event("on_match_over")
async def w(ctx, *args): time = tools.time_calculator("".join(args)) ts = tools.timestamp_now() - time t_str = tools.time_diff(ts) print(t_str)
def on_match_starting(self): self.__auto_dict_add("rounds", {"round_number": self.match.round_no, "event": "starting", "timestamp": timestamp_now()}) self.__event("on_match_starting")
def on_round_over(self): self.__auto_dict_add("rounds", {"round_number": self.match.round_no, "event": "stopping", "timestamp": timestamp_now()}) self.__event("on_round_over")
def is_timeout(self): return self.__timeout > tools.timestamp_now()
def reset_lobby_timestamp(self): self.__lobby_stamp = tools.timestamp_now()
def push_last_bases(base): last_base[1] = (last_base[0][0], last_base[0][1]) last_base[0] = (base.id, tools.timestamp_now())