Skip to content

Commit

Permalink
Added basic stat display
Browse files Browse the repository at this point in the history
  • Loading branch information
yakMM committed Apr 15, 2021
1 parent 145f8de commit 295456b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Bot now use only necessary gateway intents (discord API)
- Added proper logger Plugin
- Added embed showing player status when using =r command
- Added basic stats display

# v3.1:
- Fixed some issues with sub command
Expand Down
4 changes: 2 additions & 2 deletions bot/cogs/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def register(self, ctx, *args):
return
player = classes.Player.get(ctx.author.id)
if not player:
await display.REG_NO_RULE.send(ctx, cfg.channels["rules"])
await display.NO_RULE.send(ctx, f"={ctx.command.name}", cfg.channels["rules"])
return

msg = await _register(player, ctx, args)
Expand All @@ -52,7 +52,7 @@ async def register(self, ctx, *args):
async def notify(self, ctx):
player = classes.Player.get(ctx.author.id)
if not player:
await display.REG_NO_RULE.send(ctx, cfg.channels["rules"])
await display.NO_RULE.send(ctx, f"={ctx.command.name}", cfg.channels["rules"])
return
if player.is_notify:
player.is_notify = False
Expand Down
11 changes: 11 additions & 0 deletions bot/display/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ def register_status(ctx, player):
return embed


def player_stats(ctx, stats):
embed = Embed(colour=Color.blue(), title="Player stats",
description=f"POG stats for <@{stats.id}>\nNote: Tracking stats only after POG match 569")
embed.add_field(name="Number of matches played", value=stats.nb_matches_played, inline=False)
embed.add_field(name="Raw POG net", value=stats.net, inline=False)
embed.add_field(name="Raw POG score", value=stats.score, inline=False)
embed.add_field(name="Number of POG kills", value=stats.kills, inline=False)
embed.add_field(name="Number of POG deaths", value=stats.deaths, inline=False)
return embed


def account(ctx, account):
""" Returns account message embed
"""
Expand Down
3 changes: 2 additions & 1 deletion bot/display/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AllStrings(Enum):
REG_WITH_CHARS = Message("You successfully registered with the following Jaeger characters: `{}`, `{}`, `{}`")
REG_FROZEN = Message("You can't register while you're playing a match!")
REG_RULES = Message("{} You have accepted the rules, you may now register", embed=embeds.register_help)
REG_NO_RULE = Message("You have to accept the rules before registering! Check <#{}>")

LB_ALREADY_IN = Message("You are already in queue!")
LB_IN_MATCH = Message("You are already in a match!")
Expand Down Expand Up @@ -112,6 +111,8 @@ class AllStrings(Enum):
CANCEL_NOTHING = Message("Nothing to cancel!")
CANCEL_NOT_CAPTAIN = Message("You can't cancel this request!")
READY_NO_COMMAND = Message("Can't do that while your team is ready!")
NO_RULE = Message("You have to accept the rules before using `{}`! Check <#{}>")
DISPLAY_STATS = Message("Here are your POG stats:", embed=embeds.player_stats)

BOT_UNLOCKED = Message("Unlocked!")
BOT_LOCKED = Message("Locked!")
Expand Down
16 changes: 16 additions & 0 deletions bot/modules/dm_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from classes import Player, PlayerStat
import modules.config as cfg
from display import AllStrings as disp, ContextWrapper
from logging import getLogger

log = getLogger("pog_bot")


async def on_stats(user):
player = Player.get(user.id)
if not player:
await disp.NO_RULE.send(user, "stats", cfg.channels["rules"])
return
log.info(f"Stats request from player id: [{player.id}], name: [{player.name}]")
stat_player = await PlayerStat.get_from_database(player.id)
await disp.DISPLAY_STATS.send(user, stats=stat_player)
4 changes: 4 additions & 0 deletions bot/modules/message_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from asyncio import sleep
import modules.tools as tools
from logging import getLogger
from modules.dm_handler import on_stats

__spam_list = dict()
__SPAM_MSG_FREQUENCY = 5
Expand Down Expand Up @@ -69,6 +70,9 @@ async def on_message(client, message):

# if dm, send in staff
if isinstance(message.channel, DMChannel):
if message.content.lower() in ("stat", "stats", "statistics", "s"):
await on_stats(message.author)
return
await disp.BOT_DM.send(ContextWrapper.channel(cfg.channels["staff"]), msg=message)
await disp.BOT_DM_RECEIVED.send(message.author)
return
Expand Down

0 comments on commit 295456b

Please sign in to comment.