.BANCHO. Add !ban and !unban fokabot commands

This commit is contained in:
Nyo 2016-04-24 11:46:33 +02:00
parent c68fdf6d7c
commit e1cdbfd6c9
3 changed files with 61 additions and 2 deletions

View File

@ -180,6 +180,43 @@ def removeSilence(fro, chan, message):
return "{}'s silence reset".format(target)
def ban(fro, chan, message):
# Get parameters
for i in message:
i = i.lower()
target = message[0].replace("_", " ")
# Make sure the user exists
targetUserID = userHelper.getID(target)
if targetUserID == False:
return "{}: user not found".format(target)
# Set allowed to 0
userHelper.setAllowed(targetUserID, 0)
# Send ban packet to the user if he's online
targetToken = glob.tokens.getTokenFromUsername(target)
if targetToken != None:
targetToken.enqueue(serverPackets.loginBanned())
return "RIP {}. You will not be missed.".format(target)
def unban(fro, chan, message):
# Get parameters
for i in message:
i = i.lower()
target = message[0].replace("_", " ")
# Make sure the user exists
targetUserID = userHelper.getID(target)
if targetUserID == False:
return "{}: user not found".format(target)
# Set allowed to 1
userHelper.setAllowed(targetUserID, 1)
return "Welcome back {}!".format(target)
def restartShutdown(restart):
"""Restart (if restart = True) or shutdown (if restart = False) pep.py safely"""
msg = "We are performing some maintenance. Bancho will {} in 5 seconds. Thank you for your patience.".format("restart" if restart else "shutdown")
@ -344,6 +381,16 @@ commands = [
"trigger": "!system status",
"minRank": 3,
"callback": systemStatus
}, {
"trigger": "!ban",
"syntax": "<target>",
"minRank": 3,
"callback": ban
}, {
"trigger": "!unban",
"syntax": "<target>",
"minRank": 3,
"callback": unban
}
]

View File

@ -18,7 +18,10 @@ def forceUpdate():
return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.sInt32]])
def loginBanned():
return packetHelper.buildPacket(packetIDs.server_userID, [[-3, dataTypes.sInt32]])
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.sInt32]])
packets += notification("You are banned. You can ask to get unbanned after 1 month since your ban by contacting support@ripple.moe")
return packets
#return packetHelper.buildPacket(packetIDs.server_userID, [[-3, dataTypes.sInt32]])
def loginError():
return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.sInt32]])

View File

@ -261,8 +261,17 @@ def getPP(userID, gameMode):
Get userID's PP relative to gameMode
userID -- user
return -- gameMode number
return -- PP
"""
modeForDB = gameModes.getGameModeForDB(gameMode)
return glob.db.fetch("SELECT pp_{} FROM users_stats WHERE id = ?".format(modeForDB), [userID])["pp_{}".format(modeForDB)]
def setAllowed(userID, allowed):
"""
Set userID's allowed status
userID -- user
allowed -- allowed status. 1: normal, 0: banned
"""
glob.db.execute("UPDATE users SET allowed = ? WHERE id = ?", [allowed, userID])