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