.BANCHO. Update ranks, add !alertuser command
This commit is contained in:
		@@ -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."
 | 
				
			||||||
@@ -469,8 +484,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 = [
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@@ -496,15 +521,20 @@ commands = [
 | 
				
			|||||||
	}, {
 | 
						}, {
 | 
				
			||||||
		"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",
 | 
				
			||||||
@@ -527,11 +557,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",
 | 
				
			||||||
@@ -539,11 +569,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",
 | 
				
			||||||
@@ -577,5 +607,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?")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,3 +51,7 @@ def readableMods(__mods):
 | 
				
			|||||||
		r += "SO"
 | 
							r += "SO"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return r
 | 
						return r
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def strContains(s, w):
 | 
				
			||||||
 | 
						return (' ' + w + ' ') in (' ' + s + ' ')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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,10 +36,17 @@ 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["rank"] != None:
 | 
				
			||||||
 | 
									# Rank = x
 | 
				
			||||||
 | 
									if userHelper.getRankPrivileges(userHelper.getID(fro)) != i["rank"]:
 | 
				
			||||||
 | 
										return False
 | 
				
			||||||
 | 
								else:
 | 
				
			||||||
 | 
									# Rank > x
 | 
				
			||||||
				if i["minRank"] > 1:
 | 
									if i["minRank"] > 1:
 | 
				
			||||||
					# Get rank from db only if minrank > 1, so we save some CPU
 | 
										# Get rank from db only if minrank > 1, so we save some CPU
 | 
				
			||||||
					if userHelper.getRankPrivileges(userHelper.getID(fro)) < i["minRank"]:
 | 
										if userHelper.getRankPrivileges(userHelper.getID(fro)) < i["minRank"]:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user