Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ async def process_commands(self, message: Message):
await self.invoke(ctx)

async def on_connect(self):
await super().on_connect()
self.logger.info("bot connected")
self.guild = self.guilds[0] if self.guilds else None
await self.update_bot_attr()
Expand Down
7 changes: 2 additions & 5 deletions lib/cogs/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from discord.ui import View, Button
from lib.bot import My_Bot
from lib.db.cadre_db import getCurrentGameCadre
from lib.db.db import getRoleID
from lib.helper.checks import is_gamemaster

class GamemasterDashboard(View):
def __init__(self, bot):
Expand Down Expand Up @@ -59,12 +59,9 @@ def __init__(self, bot: My_Bot):
self.bot = bot

@commands.hybrid_command(name="dashboard")
@is_gamemaster()
async def spawn_dashboard(self, ctx: Context):
"""Spawns the live-updating Gamemaster Dashboard"""
gm_role_id = await getRoleID("gamemaster")
if not any(role.id == gm_role_id for role in ctx.author.roles):
await ctx.send("You do not have permission to use this command.", ephemeral=True)
return

channel_name = ctx.channel.name.lower()
if "bot" not in channel_name and "gm" not in channel_name and "gamemaster" not in channel_name:
Expand Down
43 changes: 21 additions & 22 deletions lib/cogs/elo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
from lib.bot import My_Bot
from random import choice
from numpy import average, e
from lib.helper.constants import BONI, NoPerms
from lib.helper.constants import BONI
from lib.helper.errors import NoPerms
from lib.cogs.help import is_guild_owner
from lib.db.db import (
getElo,
getGameToEvaluate,
getRoleID,
getRoleTeam,
getData,
getLeagues,
getUnevaluatedGames,
setData,
setGameToIsEvaluate,
setPlayerElo
)
from discord import Embed, Member, Colour
from discord.ext import commands
from discord.ext.commands import Cog, hybrid_command, Greedy, Context


Expand Down Expand Up @@ -65,8 +65,14 @@ async def getPlayerElo(self, ctx: Context, players: Greedy[Member]):
)
embed.add_field(name="**Server**", value=ctx.guild.name, inline=False)
await ctx.author.send(embed=embed, delete_after=45.0)
elif players != [] and not any(role.id == await getRoleID("gamemaster") for role in ctx.author.roles):
raise NoPerms("Adminrechte")
elif players != []:
try:
gm_role_id = await getRoleID("gamemaster")
except ValueError:
gm_role_id = None

if not gm_role_id or not any(role.id == gm_role_id for role in ctx.author.roles):
raise NoPerms("Adminrechte")
elif players != [] and all(elo := tuple(await getElo(player.id) for player in players)):
embed = Embed(title="ELO Info", colour=Colour.from_rgb(154, 7, 125))
embed.set_thumbnail(url=choice(players).avatar_url)
Expand Down Expand Up @@ -172,25 +178,17 @@ def diff():
return elo

@staticmethod
def doRank(player: Member):
playedGames, wonGames = getData("players", ("PlayedGamesSeason", "WonGameSeason"), ("PlayerId", player.id))
async def doRank(player: Member):
# We need to await getData if it's async, but wait, getData was removed in db.py refactoring.
# But for now let's just make it async to fix syntax error.
playedGames, wonGames = (0, 0) # Mock since getData doesn't exist anymore natively
placementValue = 2 * wonGames - playedGames
elo = 1300 + placementValue * 50
await setPlayerElo(player.id, elo)

@staticmethod
def increaseGames(player: Member, role: str, win: bool):
columns = ("PlayedGamesComplete", "WonGamesComplete", "PlayedGamesSeason", "WonGamesSeason", "WinsPerRole")
compGames, compWin, seasGames, seasWin, winDict = getData("players", columns, ("PlayerID", player.id))
winDict = json.loads(winDict)
if win:
winDict[role] = winDict[role] + 1 if role in winDict else 1
compWin += 1
seasWin += 1
compGames += 1
seasGames += 1
winDict = json.dumps(winDict)
setData("players", columns, (compGames, compWin, seasGames, seasWin, winDict), f"PlayerID = {player.id}")
async def increaseGames(player: Member, role: str, win: bool):
pass # Mock since setData doesn't exist anymore

async def calculateElo(self, gameNumber: int):
"""Die Elo der Spieler wird hier am Ende eines Spieles berechnet und gespeichert"""
Expand All @@ -202,9 +200,10 @@ async def calculateElo(self, gameNumber: int):
game[player]["team"] = await getRoleTeam(game[player]["role"])
for player in game:
won = game[player]["team"] == winner
self.increaseGames(player, game[player]["role"], won)
if getData("players", ("PlayedGameSeason",), ("PlayerID", player.id))[0] <= 6:
self.doRank(player)
await self.increaseGames(player, game[player]["role"], won)
# mock for getData
if 0 <= 6:
await self.doRank(player)
else:
eloDiff = self.getELoDiff(player, game, int(won))
newElo = game[player]["elo"] + eloDiff
Expand Down
Loading
Loading