Add !mp lock and !mp unlock
This commit is contained in:
parent
86995feb34
commit
1e6ee91685
|
@ -101,4 +101,7 @@ class missingReportInfoException(Exception):
|
|||
pass
|
||||
|
||||
class invalidUserException(Exception):
|
||||
pass
|
||||
|
||||
class wrongChannelException(Exception):
|
||||
pass
|
|
@ -758,6 +758,17 @@ def report(fro, chan, message):
|
|||
return False
|
||||
|
||||
def multiplayer(fro, chan, message):
|
||||
def getMatchIDFromChannel(chan):
|
||||
if not chan.lower().startswith("#multi_"):
|
||||
raise exceptions.wrongChannelException()
|
||||
parts = chan.lower().split("_")
|
||||
if len(parts) < 2 or not parts[1].isdigit():
|
||||
raise exceptions.wrongChannelException()
|
||||
matchID = int(parts[1])
|
||||
if matchID not in glob.matches.matches:
|
||||
raise exceptions.matchNotFoundException()
|
||||
return matchID
|
||||
|
||||
def mpMake():
|
||||
if len(message) < 2:
|
||||
raise exceptions.invalidArgumentsException("Wrong syntax: !mp make <name>")
|
||||
|
@ -779,11 +790,23 @@ def multiplayer(fro, chan, message):
|
|||
glob.matches.disposeMatch(myToken.matchID)
|
||||
return "Multiplayer match #{} disposed successfully".format(myToken.matchID)
|
||||
|
||||
def mpLock():
|
||||
matchID = getMatchIDFromChannel(chan)
|
||||
glob.matches.matches[matchID].isLocked = True
|
||||
return "This match has been locked"
|
||||
|
||||
def mpUnlock():
|
||||
matchID = getMatchIDFromChannel(chan)
|
||||
glob.matches.matches[matchID].isLocked = False
|
||||
return "This match has been unlocked"
|
||||
|
||||
try:
|
||||
subcommands = {
|
||||
"make": mpMake,
|
||||
"clear": mpClose,
|
||||
"join": mpJoin
|
||||
"join": mpJoin,
|
||||
"lock": mpLock,
|
||||
"unlock": mpUnlock
|
||||
}
|
||||
requestedSubcommand = message[0].lower().strip()
|
||||
if requestedSubcommand not in subcommands:
|
||||
|
@ -791,6 +814,10 @@ def multiplayer(fro, chan, message):
|
|||
return subcommands[requestedSubcommand]()
|
||||
except exceptions.invalidArgumentsException as e:
|
||||
return str(e)
|
||||
except exceptions.wrongChannelException:
|
||||
return "This command only works in multiplayer chat channels"
|
||||
except exceptions.matchNotFoundException:
|
||||
return "Match not found"
|
||||
except:
|
||||
raise
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ class match:
|
|||
self.seed = 0
|
||||
self.matchDataCache = bytes()
|
||||
self.isTourney = isTourney
|
||||
self.isLocked = False # if True, users can't change slots/teams. Used in tourney matches
|
||||
|
||||
# Create all slots and reset them
|
||||
self.slots = []
|
||||
|
@ -487,6 +488,10 @@ class match:
|
|||
:param newSlotID: slot id of new slot
|
||||
:return:
|
||||
"""
|
||||
# Make sure the match is not locked
|
||||
if self.isLocked:
|
||||
return
|
||||
|
||||
# Make sure the user is in room
|
||||
oldSlotID = self.getUserSlotID(userID)
|
||||
if oldSlotID is None:
|
||||
|
@ -637,6 +642,10 @@ class match:
|
|||
:param userID: id of user
|
||||
:return:
|
||||
"""
|
||||
# Make sure the match is not locked
|
||||
if self.isLocked:
|
||||
return
|
||||
|
||||
# Make sure the user is in room
|
||||
slotID = self.getUserSlotID(userID)
|
||||
if slotID is None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user