Fix foka responding to commands even if the command is not at the beginning of the message

This commit is contained in:
Giuseppe Guerra
2017-08-02 00:02:38 +02:00
parent 2cf1cdf1fd
commit 3373bc9581
5 changed files with 58 additions and 12 deletions

View File

@@ -41,7 +41,7 @@ def fokabotResponse(fro, chan, message):
"""
for i in fokabotCommands.commands:
# Loop though all commands
if generalUtils.strContains(message, i["trigger"]):
if message.strip().startswith(i["trigger"]):
# message has triggered a command
# Make sure the user has right permissions

View File

@@ -440,11 +440,12 @@ class match:
return False
def userLeft(self, user):
def userLeft(self, user, disposeMatch=True):
"""
Remove someone from users in match
:param user: user object of the user
:param disposeMatch: if `True`, will try to dispose match if there are no users in the room
:return:
"""
# Make sure the user is in room
@@ -456,10 +457,10 @@ class match:
self.setSlot(slotID, slotStatuses.FREE, 0, None, 0)
# Check if everyone left
if self.countUsers() == 0:
if self.countUsers() == 0 and disposeMatch:
# Dispose match
glob.matches.disposeMatch(self.matchID)
log.info("MPROOM{}: Room disposed".format(self.matchID))
log.info("MPROOM{}: Room disposed because all users left".format(self.matchID))
return
# Check if host left

View File

@@ -1,6 +1,7 @@
from objects import match
from objects import glob
from constants import serverPackets
from common.log import logUtils as log
class matchList:
def __init__(self):
@@ -38,12 +39,24 @@ class matchList:
if matchID not in self.matches:
return
# Remove match object and stream
_match = self.matches.pop(matchID)
# Get match and disconnect all players
_match = self.matches[matchID]
for slot in _match.slots:
_token = glob.tokens.getTokenFromUserID(slot.userID, ignoreIRC=True)
if _token is None:
continue
_match.userLeft(_token, disposeMatch=False) # don't dispose the match twice when we remove all players
# Send matchDisposed packet before disposing streams
glob.streams.broadcast(_match.streamName, serverPackets.disposeMatch(_match.matchID))
# Dispose all streams
glob.streams.dispose(_match.streamName)
glob.streams.dispose(_match.playingStreamName)
glob.streams.remove(_match.streamName)
glob.streams.remove(_match.playingStreamName)
# Send match dispose packet to everyone in lobby
glob.streams.broadcast("lobby", serverPackets.disposeMatch(matchID))
glob.streams.broadcast("lobby", serverPackets.disposeMatch(matchID))
del self.matches[matchID]
log.info("MPROOM{}: Room disposed manually".format(_match.matchID))

View File

@@ -323,19 +323,20 @@ class token:
self.leaveStream("multi/{}".format(self.matchID))
self.leaveStream("multi/{}/playing".format(self.matchID)) # optional
# Set usertoken match to -1
leavingMatchID = self.matchID
self.matchID = -1
# Make sure the match exists
if self.matchID not in glob.matches.matches:
if leavingMatchID not in glob.matches.matches:
return
# The match exists, get object
match = glob.matches.matches[self.matchID]
match = glob.matches.matches[leavingMatchID]
# Set slot to free
match.userLeft(self)
# Set usertoken match to -1
self.matchID = -1
def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"):
"""
Kick this user from the server