diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 90256c7..669fd68 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -11,6 +11,9 @@ import json from constants import mods from helpers import generalFunctions +from helpers import consoleHelper +from constants import bcolors + """ Commands callbacks @@ -46,6 +49,8 @@ def faq(fro, chan, message): return "Check the server status (here!)[https://ripple.moe/index.php?p=27]" elif message[0] == "english": return "Please keep this channel in english." + else: + return False def roll(fro, chan, message): maxPoints = 100 @@ -63,6 +68,16 @@ def alert(fro, chan, message): glob.tokens.enqueueAll(serverPackets.notification(' '.join(message[:]))) return False +def alertUser(fro, chan, message): + target = message[0].replace("_", " ") + + targetToken = glob.tokens.getTokenFromUsername(target) + if targetToken != None: + targetToken.enqueue(serverPackets.notification(' '.join(message[1:]))) + return False + else: + return "User offline." + def moderated(fro, chan, message): try: # Make sure we are in a channel and not PM @@ -341,7 +356,7 @@ def getPPMessage(userID): return msg except requests.exceptions.RequestException: # RequestException - return "API Timeout." + return "API Timeout. Please try again in a few seconds." except exceptions.apiException: # API error return "Unknown error in LETS API call. Please tell this to a dev." @@ -469,8 +484,18 @@ callback: function to call when the command is triggered. Optional. response: text to return when the command is triggered. Optional. syntax: command syntax. Arguments must be separated by spaces (eg: ) minRank: minimum rank to execute that command. Optional (default = 1) +rank: EXACT rank used to execute that command. Optional. -You MUST set trigger and callback/response, or the command won't work. +RANKS: +1: Normal user +2: Supporter +3: Developer +4: Community manager + +NOTES: +- You CAN'T use both rank and minRank at the same time. +- If both rank and minrank are **not** present, everyone will be able to run that command. +- You MUST set trigger and callback/response, or the command won't work. """ commands = [ { @@ -496,15 +521,20 @@ commands = [ }, { "trigger": "!alert", "syntax": "", - "minRank": 4, + "minRank": 3, "callback": alert + }, { + "trigger": "!alertuser", + "syntax": " ", + "minRank": 3, + "callback": alertUser, }, { "trigger": "!moderated", "minRank": 3, "callback": moderated }, { "trigger": "!kickall", - "minRank": 4, + "rank": 3, "callback": kickAll }, { "trigger": "!kick", @@ -527,11 +557,11 @@ commands = [ "callback": removeSilence }, { "trigger": "!system restart", - "minRank": 4, + "rank": 3, "callback": systemRestart }, { "trigger": "!system shutdown", - "minRank": 4, + "rank": 3, "callback": systemShutdown }, { "trigger": "!system reload", @@ -539,11 +569,11 @@ commands = [ "callback": systemReload }, { "trigger": "!system maintenance", - "minRank": 3, + "rank": 3, "callback": systemMaintenance }, { "trigger": "!system status", - "minRank": 3, + "rank": 3, "callback": systemStatus }, { "trigger": "!ban", @@ -577,5 +607,6 @@ commands = [ for cmd in commands: cmd.setdefault("syntax", "") cmd.setdefault("minRank", 1) + cmd.setdefault("rank", None) cmd.setdefault("callback", None) cmd.setdefault("response", "u w0t m8?") diff --git a/constants/serverPackets.py b/constants/serverPackets.py index 3a069be..94bdfe6 100644 --- a/constants/serverPackets.py +++ b/constants/serverPackets.py @@ -101,9 +101,9 @@ def userPanel(userID): if username == "FokaBot": userRank = userRanks.MOD elif rank == 4: - userRank = userRanks.ADMIN - elif rank == 3: userRank = userRanks.MOD + elif rank == 3: + userRank = userRanks.ADMIN elif rank == 2: userRank = userRanks.SUPPORTER else: diff --git a/constants/userRanks.py b/constants/userRanks.py index 923bede..c4c3fe8 100644 --- a/constants/userRanks.py +++ b/constants/userRanks.py @@ -1,5 +1,4 @@ """Bancho user ranks""" -# TODO: Uppercase, maybe? NORMAL = 0 PLAYER = 1 SUPPORTER = 4 diff --git a/helpers/generalFunctions.py b/helpers/generalFunctions.py index a5bcc35..6f04eab 100644 --- a/helpers/generalFunctions.py +++ b/helpers/generalFunctions.py @@ -51,3 +51,7 @@ def readableMods(__mods): r += "SO" return r + + +def strContains(s, w): + return (' ' + w + ' ') in (' ' + s + ' ') diff --git a/objects/fokabot.py b/objects/fokabot.py index 27754f7..7265303 100644 --- a/objects/fokabot.py +++ b/objects/fokabot.py @@ -5,6 +5,7 @@ from constants import actions from constants import serverPackets from constants import fokabotCommands import re +from helpers import generalFunctions # Tillerino np regex, compiled only once to increase performance npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)") @@ -35,14 +36,21 @@ def fokabotResponse(fro, chan, message): for i in fokabotCommands.commands: # Loop though all commands - if i["trigger"] in message: + #if i["trigger"] in message: + if generalFunctions.strContains(message, i["trigger"]): # message has triggered a command # Make sure the user has right permissions - if i["minRank"] > 1: - # Get rank from db only if minrank > 1, so we save some CPU - if userHelper.getRankPrivileges(userHelper.getID(fro)) < i["minRank"]: + if i["rank"] != None: + # Rank = x + if userHelper.getRankPrivileges(userHelper.getID(fro)) != i["rank"]: return False + else: + # Rank > x + if i["minRank"] > 1: + # Get rank from db only if minrank > 1, so we save some CPU + if userHelper.getRankPrivileges(userHelper.getID(fro)) < i["minRank"]: + return False # Check argument number message = message.split(" ")