Skip to content

Commit

Permalink
1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
yakMM committed Sep 17, 2020
1 parent a2ccd52 commit 4c8ab73
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 134 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v1.14:
- Added sub command for staff
- Updated help embeds for all channels
- Banned weapon usage is now reported in both match and staff channels
- Match info now shows the remaining time for current round
- Added rdy as alias for the ready command
- Added global information prompt accessible with command info
- All scores are now posted in the result channel
- Matches are now stored in database

# v1.13:
- Added match score tracking (BETA)
- Fixed bug with display of scores
Expand Down Expand Up @@ -57,7 +67,7 @@

# v1.6:
- Fixed critical bug in account distribution (every account could only be used 1 time)
- Match lenght is now 10 minutes
- Match length is now 10 minutes
- ALL commands are now case insensitive (it was the case of only a few)
- Fixed a bug when lobby is stuck but a match spot becomes available
- "Round 2 is over" message is no longer displayed twice
Expand Down Expand Up @@ -91,7 +101,6 @@
- Matches are now constituted of 2 rounds
- Round number is now displayed


# v1.1:
- Rules acceptance feature
- Registration of users with their Jaeger accounts, linked with ps2 api and a backend database
Expand Down
43 changes: 39 additions & 4 deletions bot/classes/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def onInactive(self, fct):
self.inactiveTask.start(fct)

def onActive(self):
if self.status is PlayerStatus.IS_LOBBIED:
if self.__status is PlayerStatus.IS_LOBBIED:
self.inactiveTask.cancel()

def onResign(self):
Expand Down Expand Up @@ -274,8 +274,7 @@ async def _addCharacters(self, charList):
try:
world = int(jdata["character_list"][0]["world_id"])
if world != WORLD_ID:
raise CharInvalidWorld(
jdata["character_list"][0]["name"]["first"])
raise CharInvalidWorld(jdata["character_list"][0]["name"]["first"])
else:
faction = int(jdata["character_list"][0]["faction_id"])
currId = int(jdata["character_list"][0]["character_id"])
Expand Down Expand Up @@ -313,6 +312,7 @@ class ActivePlayer:
def __init__(self, player, team):
self.__player = player
self.__player._active = self
self.__illegalWeapons = dict()
self.__kills = 0
self.__deaths = 0
self.__net = 0
Expand All @@ -324,6 +324,28 @@ def __init__(self, player, team):
def clean(self):
self.__player.onPlayerClean()

def getData(self):
data = {"discord_id": self.__player.id,
"ig_id": self.igId,
"ill_weapons": self.__getIllWeaponsDoc(),
"score": self.__score,
"net": self.__net,
"deaths": self.__deaths,
"kills": self.__kills,
"rank": self.__player.rank
}
return data

def __getIllWeaponsDoc(self):
data = list()
for weapId in self.__illegalWeapons.keys():
doc = {"weap_id": weapId,
"kills": self.__illegalWeapons[weapId]
}
data.append(doc)
return data


@property
def name(self):
return self.__player.name
Expand Down Expand Up @@ -410,6 +432,16 @@ def score(self):
def net(self):
return self.__net

@property
def illegalWeapons(self):
return self.__illegalWeapons

def addIllegalWeapon(self, weapId):
if weapId in self.__illegalWeapons:
self.__illegalWeapons[weapId] += 1
else:
self.__illegalWeapons[weapId] = 1

def addOneKill(self, points):
self.__kills += 1
self.__team.addOneKill()
Expand All @@ -418,7 +450,9 @@ def addOneKill(self, points):
def addOneDeath(self, points):
self.__deaths += 1
self.__team.addOneDeath()
self.__net -= points
points = -points
self.__net += points
self.__team.addNet(points)

def addOneTK(self):
self.__addPoints(cfg.scores["teamkill"])
Expand All @@ -432,6 +466,7 @@ def __addPoints(self, points):
self.__net += points
self.__score += points
self.__team.addScore(points)
self.__team.addNet(points)


class TeamCaptain(ActivePlayer):
Expand Down
31 changes: 31 additions & 0 deletions bot/classes/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,28 @@ def __init__(self, id, name, match):
self.__name = name
self.__players = list()
self.__score = 0
self.__net = 0
self.__deaths = 0
self.__kills = 0
self.__faction = 0
self.__cap = 0
self.__match = match

def getData(self):
playersData = list()
for p in self.__players:
playersData.append(p.getData())
data = {"name": self.__name,
"faction_id": self.__faction,
"score": self.__score,
"net": self.__net,
"deaths": self.deaths,
"kills": self.__kills,
"cap_points": self.__cap,
"players": playersData
}
return data

@property
def id(self):
return self.__id
Expand All @@ -40,6 +56,10 @@ def faction(self, faction):
def score(self):
return self.__score

@property
def net(self):
return self.__net

@property
def cap(self):
return self.__cap
Expand Down Expand Up @@ -78,10 +98,14 @@ def clear(self):
def addCap(self, points):
self.__cap += points
self.__score += points
self.__net += points

def addScore(self, points):
self.__score += points

def addNet(self, points):
self.__net += points

def addOneKill(self):
self.__kills +=1

Expand All @@ -99,3 +123,10 @@ def onTeamReady(self):
def onMatchReady(self):
for p in self.__players:
p.onMatchReady()

def onPlayerSub(self, subbed, newPlayer):
i = 0
while self.__players[i] is not subbed:
i+=1
active = type(subbed)(newPlayer, self)
self.__players[i] = active
28 changes: 28 additions & 0 deletions bot/cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,34 @@ async def channel(self, ctx, *args):
return
await send("WRONG_USAGE", ctx, ctx.command.name)

@commands.command()
@commands.guild_only()
async def sub(self, ctx, *args):
# Check for match status first maybe?
player = await _removeChecks(ctx, cfg.channels["matches"])
if player is None:
return
if player.status not in (PlayerStatus.IS_MATCHED, PlayerStatus.IS_PICKED):
await send("SUB_NO", ctx)
return
if player.status is PlayerStatus.IS_PICKED and isinstance(player.active, TeamCaptain):
await send("SUB_NO_CAPTAIN", ctx)
return
newPlayer = player.match.onPlayerSub(player)
if newPlayer is None:
await send("SUB_NO_PLAYER", ctx)
return
else:
await channelSend("SUB_LOBBY", cfg.channels["lobby"], newPlayer.mention, newPlayer.match.id,
namesInLobby=getAllNamesInLobby())
if newPlayer.status is PlayerStatus.IS_PICKED:
await send("SUB_OKAY_TEAM", ctx, newPlayer.mention, player.mention,
newPlayer.active.team.name, match=newPlayer.match)
else:
await send("SUB_OKAY", ctx, newPlayer.mention, player.mention, match=newPlayer.match)
return



def setup(client):
client.add_cog(AdminCog(client))
Expand Down
10 changes: 9 additions & 1 deletion bot/cogs/lobby.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from classes.players import PlayerStatus, getPlayer

from matches import getLobbyLen, isLobbyStuck, removeFromLobby, addToLobby, getAllNamesInLobby
from matches import getLobbyLen, isLobbyStuck, removeFromLobby, addToLobby, getAllNamesInLobby, getMatch

log = getLogger(__name__)

Expand Down Expand Up @@ -95,6 +95,14 @@ async def queue(self, ctx):
return
await send("LB_QUEUE", ctx, namesInLobby=getAllNamesInLobby())

@commands.command(aliases=['i'])
@commands.guild_only()
async def info(self, ctx):
matchList = list()
for ch in cfg.channels["matches"]:
matchList.append(getMatch(ch))
await send("GLOBAL_INFO", ctx, lobby=getAllNamesInLobby(), matchList=matchList)


def setup(client):
client.add_cog(LobbyCog(client))
2 changes: 1 addition & 1 deletion bot/cogs/matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def resign(self,ctx):
else:
await send("PK_PICK_STARTED", ctx)

@commands.command()
@commands.command(aliases=['rdy'])
@commands.guild_only()
async def ready(self, ctx): # when ready
match = getMatch(ctx.channel.id)
Expand Down
1 change: 1 addition & 0 deletions bot/cogs/muted.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# Custom modules
import modules.config as cfg
from modules.roles import permsMuted, forceInfo, roleUpdate
from modules.exceptions import ElementNotFound
from modules.display import send

log = getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions bot/config_template.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ notify = # id of the notify role
users = # name of the mongodb user collection
sBases = # name of the mongodb base collection
sWeapons = # name of the mongodb weapons collection
matches = # name of the mongodb matches collection
8 changes: 4 additions & 4 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def _addInitHandlers(client):

@client.event
async def on_ready():
# Initialise matches channels
matchesInit(client, cfg.channels["matches"])

rolesInit(client)

# fetch rule message, remove all reaction but the bot's
Expand Down Expand Up @@ -242,13 +245,10 @@ def main(launchStr=""):
# Get Account sheet from drive
AccountHander.init(f"client_secret{launchStr}.json")

# Initialise matches channels
matchesInit(cfg.channels["matches"])

# Initialise display module
displayInit(client)

# Add main handlers
# Add init handlers
_addInitHandlers(client)
if launchStr == "_test":
_test(client)
Expand Down
Loading

0 comments on commit 4c8ab73

Please sign in to comment.