2016-04-19 17:40:59 +00:00
|
|
|
"""FokaBot related functions"""
|
2016-05-18 17:12:46 +00:00
|
|
|
from helpers import userHelper
|
|
|
|
from objects import glob
|
2016-05-17 21:40:34 +00:00
|
|
|
from constants import actions
|
2016-05-18 17:12:46 +00:00
|
|
|
from constants import serverPackets
|
|
|
|
from constants import fokabotCommands
|
2016-05-20 16:53:09 +00:00
|
|
|
import re
|
2016-05-28 18:26:26 +00:00
|
|
|
from helpers import generalFunctions
|
2016-05-20 16:53:09 +00:00
|
|
|
|
|
|
|
# Tillerino np regex, compiled only once to increase performance
|
|
|
|
npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)")
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def connect():
|
|
|
|
"""Add FokaBot to connected users and send userpanel/stats packet to everyone"""
|
|
|
|
token = glob.tokens.addToken(999)
|
|
|
|
token.actionID = actions.idle
|
|
|
|
glob.tokens.enqueueAll(serverPackets.userPanel(999))
|
2016-08-17 14:41:05 +00:00
|
|
|
glob.tokens.enqueueAll(serverPackets.userStats(999))
|
2016-06-17 15:43:49 +00:00
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def disconnect():
|
|
|
|
"""Remove FokaBot from connected users"""
|
|
|
|
glob.tokens.deleteToken(glob.tokens.getTokenFromUserID(999))
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
def fokabotResponse(fro, chan, message):
|
|
|
|
"""
|
|
|
|
Check if a message has triggered fokabot (and return its response)
|
|
|
|
|
|
|
|
fro -- sender username (for permissions stuff with admin commands)
|
|
|
|
chan -- channel name
|
|
|
|
message -- message
|
|
|
|
|
|
|
|
return -- fokabot's response string or False
|
|
|
|
"""
|
|
|
|
for i in fokabotCommands.commands:
|
|
|
|
# Loop though all commands
|
2016-05-28 18:26:26 +00:00
|
|
|
#if i["trigger"] in message:
|
|
|
|
if generalFunctions.strContains(message, i["trigger"]):
|
2016-04-19 17:40:59 +00:00
|
|
|
# message has triggered a command
|
|
|
|
|
|
|
|
# Make sure the user has right permissions
|
2016-07-03 18:51:19 +00:00
|
|
|
if i["privileges"] != None:
|
2016-05-28 18:26:26 +00:00
|
|
|
# Rank = x
|
2016-07-03 18:51:19 +00:00
|
|
|
if userHelper.getPrivileges(userHelper.getID(fro)) & i["privileges"] == 0:
|
2016-04-19 17:40:59 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
# Check argument number
|
|
|
|
message = message.split(" ")
|
|
|
|
if i["syntax"] != "" and len(message) <= len(i["syntax"].split(" ")):
|
|
|
|
return "Wrong syntax: {} {}".format(i["trigger"], i["syntax"])
|
|
|
|
|
|
|
|
# Return response or execute callback
|
|
|
|
if i["callback"] == None:
|
|
|
|
return i["response"]
|
|
|
|
else:
|
|
|
|
return i["callback"](fro, chan, message[1:])
|
|
|
|
|
|
|
|
# No commands triggered
|
|
|
|
return False
|