Skip to content

Commit

Permalink
Hotfix 4: =clear fix, string changes, API error security
Browse files Browse the repository at this point in the history
  • Loading branch information
yakMM committed Apr 3, 2021
1 parent 3064e29 commit 15792c6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
13 changes: 8 additions & 5 deletions bot/display/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def match_help(ctx):
if is_admin(ctx.author):
embed.add_field(name="Staff commands",
value='`=clear` - Clear the match\n'
'`=sub @player1 @player2` - Replace player1 by player2'
'`=sub @player1 @player2` - Replace player1 by player2\n'
'`=check account/online` - Disable account or online check\n'
'`=channel freeze`/`unfreeze` - Prevent / Allow players to send messages',
inline=False)
Expand Down Expand Up @@ -278,20 +278,23 @@ def global_info(ctx, lobby, match_list):
embed.add_field(name=lb_embed.name, value=lb_embed.value, inline=lb_embed.inline)
for m in match_list:
desc = ""
if m.next_status is not MatchStatus.IS_FREE:
if m.status is MatchStatus.IS_FREE:
continue
else:
if m.round_no != 0:
desc += f"*Match {m.id} - Round {m.round_no}*"
else:
desc += f"*Match {m.id}*"
desc += "\n"
desc += f"Status: {m.status_str}"
if m.status is MatchStatus.IS_PLAYING:
desc += f"\nTime Remaining: **{m.get_formatted_time_to_round_end()}**"
if m.base:
desc += f"\nBase: **{m.base.name}**\n"
desc += f"\nBase: **{m.base.name}**"
for tm in m.teams:
if tm and tm.faction != 0:
desc += f"\n{tm.name}: **{cfg.factions[tm.faction]}**"
if m.status is MatchStatus.IS_PLAYING:
desc += f"\nTime Remaining: **{m.get_formatted_time_to_round_end()}**"

embed.add_field(name=m.channel.name, value=desc, inline=False)
return embed

Expand Down
10 changes: 6 additions & 4 deletions bot/display/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ class AllStrings(Enum):
PK_OK = Message("Player picked! {} your turn, pick a player!", embed=embeds.team_update, ping=False)
PK_OK_2 = Message("Player picked!", ping=False)
PK_LAST = Message("Assigned {} to {}!", embed=embeds.team_update)
PK_OK_FACTION = Message("Teams are ready! {} pick a faction with `=pick` `tr`/`vs`/`nc` or by reacting bellow!",
PK_OK_FACTION = Message("Teams are ready! {} pick a faction with `=pick` `tr`/`vs`/`nc` or by reacting below!",
ping=False)
PK_NOT_VALID_FACTION = Message("Incorrect input!")
PK_FACTION_OK = Message("{} chose {}!", ping=False)
PK_FACTION_ALREADY = Message("Your team is already {}!")
PK_FACTION_OTHER = Message("Faction already picked by the other team!")
PK_FACTION_OK_NEXT = Message("{} chose {}! {} pick a faction with `=pick` `tr`/`vs`/`nc` or by reacting bellow!",
PK_FACTION_OK_NEXT = Message("{} chose {}! {} pick a faction with `=pick` `tr`/`vs`/`nc` or by reacting below!",
ping=False)
PK_FACTION_CHANGED = Message("{} changed to {}!", ping=False)
PK_FACTION_NOT_PLAYER = Message("Pick a faction, not a player!")
PK_FACTION_INFO = Message("Captains can change faction with `=pick` `tr`/`vs`/`nc`!")
PK_FACTION_HELP = Message("Waiting for {} to pick a faction with `=pick` `tr`/`vs`/`nc` or by reacting bellow!",
PK_FACTION_HELP = Message("Waiting for {} to pick a faction with `=pick` `tr`/`vs`/`nc` or by reacting below!",
ping=False)
PK_OVER_READY = Message("Can't do that if your team is ready!")
PK_RESIGNED = Message("Successfully resigned! {} is the new captain for {}!", embed=embeds.team_update)
Expand All @@ -94,6 +94,8 @@ class AllStrings(Enum):
CHANNEL_INIT = Message("`Bot init`: Correctly hooked in channel <#{}>")
INVALID_STR = Message("You entered an invalid argument! `{}`")
API_ERROR = Message("Could not reach Planetside2 API, try again later!")
API_READY_ERROR = Message("Could not reach Planetside2 API, player online check ignored!", ping=False)
API_SCORE_ERROR = Message("Match {}, round {}: Could not reach Planetside2 API, no scores for this round!")
GLOBAL_INFO = Message("Here is what's going on in POG at the moment:", embed=embeds.global_info)
CHECK_ACCOUNT = Message("Your account password may have been flipped!\n"
"Re-register in <#{}> to confirm you still have access to it!", embed=embeds.flip_accounts)
Expand Down Expand Up @@ -123,7 +125,7 @@ class AllStrings(Enum):

CAP_WAITING = Message("Waiting for captain(s), use `=captain volunteer` or react below if you want to be one",
ping=False, embed=embeds.team_update)
CAP_AUTO_ANNOUNCE = Message("Captains will be automatically chosen in 1 minute!")
CAP_AUTO_ANNOUNCE = Message("Captains will be automatically suggested in 1 minute!")
CAP_OK = Message("{} will be captain for {}!", ping=False)
CAP_AUTO = Message("{} has been designated as captain for {}\n"
"Accept or decline with `=captain accept/decline` or by reacting below!")
Expand Down
23 changes: 16 additions & 7 deletions bot/match/commands/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import modules.roles as roles
from classes import Player
from match.common import check_faction, get_check_captain
from logging import getLogger

import modules.accounts_handler as accounts
import modules.census as census
from modules.asynchttp import ApiNotReachable


log = getLogger("pog_bot")

_external_commands = [SubHandler, SwapHandler]

Expand Down Expand Up @@ -134,12 +139,16 @@ async def ready(self, ctx, args):
" ".join(p.mention for p in not_validated_players))
return
if self.match.check_offline:
offline_players = await census.get_offline_players(captain.team)
if len(offline_players) != 0:
await disp.MATCH_PLAYERS_OFFLINE.send(ctx, captain.team.name,
" ".join(p.mention for p in offline_players),
p_list=offline_players)
return
try:
offline_players = await census.get_offline_players(captain.team)
if len(offline_players) != 0:
await disp.MATCH_PLAYERS_OFFLINE.send(ctx, captain.team.name,
" ".join(p.mention for p in offline_players),
p_list=offline_players)
return
except ApiNotReachable as e:
log.error(f"ApiNotReachable caught when checking online players: {e.url}")
await disp.API_READY_ERROR.send(ctx)
await match.on_team_ready(captain.team, True)
await disp.MATCH_TEAM_READY.send(ctx, captain.team.name, match=self.match.proxy)
return
Expand Down Expand Up @@ -184,7 +193,7 @@ async def base(self, ctx, args):
await self.match.base_selector.process_request(ctx, a_player, args)

@Command.command(*captains_ok_states, MatchStatus.IS_CAPTAIN)
async def clear(self, ctx):
async def clear(self, ctx, args):
match = self.match.proxy
await disp.MATCH_CLEAR.send(ctx)
await match.clear(ctx)
16 changes: 13 additions & 3 deletions bot/match/processes/match_playing.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
from display import AllStrings as disp
from display import AllStrings as disp, ContextWrapper
from asyncio import sleep
from datetime import datetime as dt, timezone as tz
from lib.tasks import Loop, loop
from logging import getLogger

from match import MatchStatus
from .process import Process

import modules.config as cfg
import modules.reactions as reactions

from modules.asynchttp import ApiNotReachable

from match.classes.base_selector import push_last_bases

import modules.census as census
import modules.tools as tools
import modules.image_maker as i_maker

log = getLogger("pog_bot")


class MatchPlaying(Process, status=MatchStatus.IS_STARTING):

Expand Down Expand Up @@ -76,8 +81,13 @@ async def on_match_over(self):
await self.match.set_status(MatchStatus.IS_RUNNING)
await self.rh.destroy()
await disp.MATCH_ROUND_OVER.send(self.match.channel, *player_pings, self.match.round_no)
await census.process_score(self.match.proxy)
await i_maker.publish_match_image(self.match)
try:
await census.process_score(self.match.proxy)
await i_maker.publish_match_image(self.match)
except ApiNotReachable as e:
log.error(f"ApiNotReachable caught when processing scores : {e.url}")
await disp.API_SCORE_ERROR.send(ContextWrapper.channel(cfg.channels["results"]), self.match.id,
self.match.round_no)
await self.match.next_process()

@Process.public
Expand Down

0 comments on commit 15792c6

Please sign in to comment.