.HIDE. Merge branch 'master' of git.zxq.co:ripple/pep.py

This commit is contained in:
Howl 2016-05-28 22:33:26 +02:00
commit f8c1f49170
5 changed files with 62 additions and 16 deletions

View File

@ -11,6 +11,9 @@ import json
from constants import mods from constants import mods
from helpers import generalFunctions from helpers import generalFunctions
from helpers import consoleHelper
from constants import bcolors
""" """
Commands callbacks Commands callbacks
@ -46,6 +49,8 @@ def faq(fro, chan, message):
return "Check the server status (here!)[https://ripple.moe/index.php?p=27]" return "Check the server status (here!)[https://ripple.moe/index.php?p=27]"
elif message[0] == "english": elif message[0] == "english":
return "Please keep this channel in english." return "Please keep this channel in english."
else:
return False
def roll(fro, chan, message): def roll(fro, chan, message):
maxPoints = 100 maxPoints = 100
@ -63,6 +68,16 @@ def alert(fro, chan, message):
glob.tokens.enqueueAll(serverPackets.notification(' '.join(message[:]))) glob.tokens.enqueueAll(serverPackets.notification(' '.join(message[:])))
return False 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): def moderated(fro, chan, message):
try: try:
# Make sure we are in a channel and not PM # Make sure we are in a channel and not PM
@ -341,7 +356,7 @@ def getPPMessage(userID):
return msg return msg
except requests.exceptions.RequestException: except requests.exceptions.RequestException:
# RequestException # RequestException
return "API Timeout." return "API Timeout. Please try again in a few seconds."
except exceptions.apiException: except exceptions.apiException:
# API error # API error
return "Unknown error in LETS API call. Please tell this to a dev." return "Unknown error in LETS API call. Please tell this to a dev."
@ -476,6 +491,10 @@ def tillerinoLast(fro, chan, message):
print(a) print(a)
return False return False
def mm00(fro, chan, message):
random.seed()
return random.choice(["meme", "MA MAURO ESISTE?"])
""" """
Commands list Commands list
@ -484,8 +503,18 @@ callback: function to call when the command is triggered. Optional.
response: text to return 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: <arg1> <arg2>) syntax: command syntax. Arguments must be separated by spaces (eg: <arg1> <arg2>)
minRank: minimum rank to execute that command. Optional (default = 1) 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 = [ commands = [
{ {
@ -507,19 +536,24 @@ commands = [
"callback": ask "callback": ask
}, { }, {
"trigger": "!mm00", "trigger": "!mm00",
"response": random.choice(["meme", "MA MAURO ESISTE?"]) "callback": mm00
}, { }, {
"trigger": "!alert", "trigger": "!alert",
"syntax": "<message>", "syntax": "<message>",
"minRank": 4, "minRank": 3,
"callback": alert "callback": alert
}, {
"trigger": "!alertuser",
"syntax": "<username> <message>",
"minRank": 3,
"callback": alertUser,
}, { }, {
"trigger": "!moderated", "trigger": "!moderated",
"minRank": 3, "minRank": 3,
"callback": moderated "callback": moderated
}, { }, {
"trigger": "!kickall", "trigger": "!kickall",
"minRank": 4, "rank": 3,
"callback": kickAll "callback": kickAll
}, { }, {
"trigger": "!kick", "trigger": "!kick",
@ -542,11 +576,11 @@ commands = [
"callback": removeSilence "callback": removeSilence
}, { }, {
"trigger": "!system restart", "trigger": "!system restart",
"minRank": 4, "rank": 3,
"callback": systemRestart "callback": systemRestart
}, { }, {
"trigger": "!system shutdown", "trigger": "!system shutdown",
"minRank": 4, "rank": 3,
"callback": systemShutdown "callback": systemShutdown
}, { }, {
"trigger": "!system reload", "trigger": "!system reload",
@ -554,11 +588,11 @@ commands = [
"callback": systemReload "callback": systemReload
}, { }, {
"trigger": "!system maintenance", "trigger": "!system maintenance",
"minRank": 3, "rank": 3,
"callback": systemMaintenance "callback": systemMaintenance
}, { }, {
"trigger": "!system status", "trigger": "!system status",
"minRank": 3, "rank": 3,
"callback": systemStatus "callback": systemStatus
}, { }, {
"trigger": "!ban", "trigger": "!ban",
@ -595,5 +629,6 @@ commands = [
for cmd in commands: for cmd in commands:
cmd.setdefault("syntax", "") cmd.setdefault("syntax", "")
cmd.setdefault("minRank", 1) cmd.setdefault("minRank", 1)
cmd.setdefault("rank", None)
cmd.setdefault("callback", None) cmd.setdefault("callback", None)
cmd.setdefault("response", "u w0t m8?") cmd.setdefault("response", "u w0t m8?")

View File

@ -101,9 +101,9 @@ def userPanel(userID):
if username == "FokaBot": if username == "FokaBot":
userRank = userRanks.MOD userRank = userRanks.MOD
elif rank == 4: elif rank == 4:
userRank = userRanks.ADMIN
elif rank == 3:
userRank = userRanks.MOD userRank = userRanks.MOD
elif rank == 3:
userRank = userRanks.ADMIN
elif rank == 2: elif rank == 2:
userRank = userRanks.SUPPORTER userRank = userRanks.SUPPORTER
else: else:

View File

@ -1,5 +1,4 @@
"""Bancho user ranks""" """Bancho user ranks"""
# TODO: Uppercase, maybe?
NORMAL = 0 NORMAL = 0
PLAYER = 1 PLAYER = 1
SUPPORTER = 4 SUPPORTER = 4

View File

@ -51,3 +51,7 @@ def readableMods(__mods):
r += "SO" r += "SO"
return r return r
def strContains(s, w):
return (' ' + w + ' ') in (' ' + s + ' ')

View File

@ -5,6 +5,7 @@ from constants import actions
from constants import serverPackets from constants import serverPackets
from constants import fokabotCommands from constants import fokabotCommands
import re import re
from helpers import generalFunctions
# Tillerino np regex, compiled only once to increase performance # Tillerino np regex, compiled only once to increase performance
npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)") npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)")
@ -35,14 +36,21 @@ def fokabotResponse(fro, chan, message):
for i in fokabotCommands.commands: for i in fokabotCommands.commands:
# Loop though all 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 # message has triggered a command
# Make sure the user has right permissions # Make sure the user has right permissions
if i["minRank"] > 1: if i["rank"] != None:
# Get rank from db only if minrank > 1, so we save some CPU # Rank = x
if userHelper.getRankPrivileges(userHelper.getID(fro)) < i["minRank"]: if userHelper.getRankPrivileges(userHelper.getID(fro)) != i["rank"]:
return False 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 # Check argument number
message = message.split(" ") message = message.split(" ")