Add !mp start

This commit is contained in:
Giuseppe Guerra 2017-08-04 01:04:26 +02:00
parent 3309f2f8fd
commit 5975e84f52
2 changed files with 53 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import json
import random
import re
import threading
import requests
import time
@ -844,6 +845,47 @@ def multiplayer(fro, chan, message):
matchID = getMatchIDFromChannel(chan)
glob.matches.matches[matchID].removeHost()
def mpStart():
def _start():
matchID = getMatchIDFromChannel(chan)
success = glob.matches.matches[matchID].start()
if not success:
chat.sendMessage("FokaBot", chan, "Couldn't start match. Make sure there are enough players and "
"teams are valid. The match has been unlocked.")
else:
chat.sendMessage("FokaBot", chan, "Have fun!")
def _decreaseTimer(t):
if t <= 0:
_start()
else:
if t % 10 == 0 or t <= 5:
chat.sendMessage("FokaBot", chan, "Match starts in {} seconds. The match has been locked. "
"Please don't leave the match during the countdown "
"or you might receive a penalty".format(t))
threading.Timer(1.00, _decreaseTimer, [t - 1]).start()
if len(message) < 2 or not message[1].isdigit():
startTime = 0
else:
startTime = int(message[1])
_match = glob.matches.matches[getMatchIDFromChannel(chan)]
# Force everyone to ready
for i, slot in enumerate(_match.slots):
if slot.status != slotStatuses.READY and slot.user is not None:
_match.toggleSlotReady(i)
if startTime == 0:
_start()
return "Starting match"
else:
_match.isStarting = True
threading.Timer(1.00, _decreaseTimer, [startTime - 1]).start()
return "Match starts in {} seconds".format(startTime)
try:
subcommands = {
"make": mpMake,
@ -855,6 +897,7 @@ def multiplayer(fro, chan, message):
"move": mpMove,
"host": mpHost,
"clearhost": mpClearHost,
"start": mpStart,
}
requestedSubcommand = message[0].lower().strip()
if requestedSubcommand not in subcommands:

View File

@ -57,6 +57,7 @@ class match:
self.matchDataCache = bytes()
self.isTourney = isTourney
self.isLocked = False # if True, users can't change slots/teams. Used in tourney matches
self.isStarting = False
# Create all slots and reset them
self.slots = []
@ -216,6 +217,8 @@ class match:
:return:
"""
# Update ready status and setnd update
if self.slots[slotID].user is None or self.isStarting:
return
oldStatus = self.slots[slotID].status
if oldStatus == slotStatuses.READY:
newStatus = slotStatuses.NOT_READY
@ -499,7 +502,7 @@ class match:
:return:
"""
# Make sure the match is not locked
if self.isLocked:
if self.isLocked or self.isStarting:
return False
# Make sure the user is in room
@ -654,7 +657,7 @@ class match:
:return:
"""
# Make sure the match is not locked
if self.isLocked:
if self.isLocked or self.isStarting:
return
# Make sure the user is in room
@ -712,9 +715,12 @@ class match:
:return:
"""
# Remove isStarting timer flag thingie
self.isStarting = False
# Make sure we have enough players
if self.countUsers() < 2 or not self.checkTeams():
return
return False
# Create playing channel
glob.streams.add(self.playingStreamName)
@ -737,3 +743,4 @@ class match:
# Send updates
self.sendUpdates()
return True