2016-05-18 17:12:46 +00:00
|
|
|
from objects import fokabot
|
2016-04-19 17:40:59 +00:00
|
|
|
import random
|
2016-05-18 17:12:46 +00:00
|
|
|
from objects import glob
|
|
|
|
from constants import serverPackets
|
|
|
|
from constants import exceptions
|
|
|
|
from helpers import userHelper
|
|
|
|
from helpers import systemHelper
|
2016-05-19 18:17:20 +00:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
from constants import mods
|
|
|
|
from helpers import generalFunctions
|
2016-06-04 10:44:54 +00:00
|
|
|
from helpers import logHelper as log
|
2016-06-16 01:34:38 +00:00
|
|
|
from constants import gameModes
|
2016-07-03 18:51:19 +00:00
|
|
|
from constants import privileges
|
2016-05-28 18:26:26 +00:00
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Commands callbacks
|
|
|
|
|
|
|
|
Must have fro, chan and messages as arguments
|
|
|
|
fro -- name of who triggered the command
|
|
|
|
chan -- channel where the message was sent
|
|
|
|
message -- list containing arguments passed from the message
|
|
|
|
[0] = first argument
|
|
|
|
[1] = second argument
|
|
|
|
. . .
|
|
|
|
|
|
|
|
return the message or **False** if there's no response by the bot
|
|
|
|
"""
|
|
|
|
|
|
|
|
def faq(fro, chan, message):
|
|
|
|
if message[0] == "rules":
|
|
|
|
return "Please make sure to check (Ripple's rules)[http://ripple.moe/?p=23]."
|
|
|
|
elif message[0] == "swearing":
|
|
|
|
return "Please don't abuse swearing"
|
|
|
|
elif message[0] == "spam":
|
|
|
|
return "Please don't spam"
|
|
|
|
elif message[0] == "offend":
|
|
|
|
return "Please don't offend other players"
|
|
|
|
elif message[0] == "github":
|
|
|
|
return "(Ripple's Github page!)[https://github.com/osuripple/ripple]"
|
|
|
|
elif message[0] == "discord":
|
|
|
|
return "(Join Ripple's Discord!)[https://discord.gg/0rJcZruIsA6rXuIx]"
|
|
|
|
elif message[0] == "blog":
|
|
|
|
return "You can find the latest Ripple news on the (blog)[https://ripple.moe/blog/]!"
|
|
|
|
elif message[0] == "changelog":
|
|
|
|
return "Check the (changelog)[https://ripple.moe/index.php?p=17] !"
|
|
|
|
elif message[0] == "status":
|
|
|
|
return "Check the server status (here!)[https://ripple.moe/index.php?p=27]"
|
2016-05-19 18:33:46 +00:00
|
|
|
elif message[0] == "english":
|
|
|
|
return "Please keep this channel in english."
|
2016-05-28 18:26:26 +00:00
|
|
|
else:
|
|
|
|
return False
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def roll(fro, chan, message):
|
|
|
|
maxPoints = 100
|
|
|
|
if len(message) >= 1:
|
|
|
|
if message[0].isdigit() == True and int(message[0]) > 0:
|
|
|
|
maxPoints = int(message[0])
|
|
|
|
|
|
|
|
points = random.randrange(0,maxPoints)
|
|
|
|
return "{} rolls {} points!".format(fro, str(points))
|
|
|
|
|
|
|
|
def ask(fro, chan, message):
|
|
|
|
return random.choice(["yes", "no", "maybe"])
|
|
|
|
|
|
|
|
def alert(fro, chan, message):
|
|
|
|
glob.tokens.enqueueAll(serverPackets.notification(' '.join(message[:])))
|
|
|
|
return False
|
|
|
|
|
2016-05-28 18:26:26 +00:00
|
|
|
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."
|
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
def moderated(fro, chan, message):
|
|
|
|
try:
|
|
|
|
# Make sure we are in a channel and not PM
|
|
|
|
if chan.startswith("#") == False:
|
|
|
|
raise exceptions.moderatedPMException
|
|
|
|
|
|
|
|
# Get on/off
|
|
|
|
enable = True
|
|
|
|
if len(message) >= 1:
|
|
|
|
if message[0] == "off":
|
|
|
|
enable = False
|
|
|
|
|
|
|
|
# Turn on/off moderated mode
|
|
|
|
glob.channels.channels[chan].moderated = enable
|
|
|
|
return "This channel is {} in moderated mode!".format("now" if enable else "no longer")
|
|
|
|
except exceptions.moderatedPMException:
|
|
|
|
return "You are trying to put a private chat in moderated mode. Are you serious?!? You're fired."
|
|
|
|
|
|
|
|
def kickAll(fro, chan, message):
|
|
|
|
# Kick everyone but mods/admins
|
|
|
|
toKick = []
|
|
|
|
for key, value in glob.tokens.tokens.items():
|
2016-07-03 18:51:19 +00:00
|
|
|
if value.admin == False:
|
2016-04-19 17:40:59 +00:00
|
|
|
toKick.append(key)
|
|
|
|
|
|
|
|
# Loop though users to kick (we can't change dictionary size while iterating)
|
|
|
|
for i in toKick:
|
|
|
|
if i in glob.tokens.tokens:
|
|
|
|
glob.tokens.tokens[i].kick()
|
|
|
|
|
|
|
|
return "Whoops! Rip everyone."
|
|
|
|
|
|
|
|
def kick(fro, chan, message):
|
|
|
|
# Get parameters
|
|
|
|
target = message[0].replace("_", " ")
|
|
|
|
|
|
|
|
# Get target token and make sure is connected
|
|
|
|
targetToken = glob.tokens.getTokenFromUsername(target)
|
|
|
|
if targetToken == None:
|
|
|
|
return "{} is not online".format(target)
|
|
|
|
|
|
|
|
# Kick user
|
|
|
|
targetToken.kick()
|
|
|
|
|
|
|
|
# Bot response
|
|
|
|
return "{} has been kicked from the server.".format(target)
|
|
|
|
|
|
|
|
def fokabotReconnect(fro, chan, message):
|
|
|
|
# Check if fokabot is already connected
|
|
|
|
if glob.tokens.getTokenFromUserID(999) != None:
|
|
|
|
return"Fokabot is already connected to Bancho"
|
|
|
|
|
|
|
|
# Fokabot is not connected, connect it
|
|
|
|
fokabot.connect()
|
|
|
|
return False
|
|
|
|
|
|
|
|
def silence(fro, chan, message):
|
|
|
|
for i in message:
|
|
|
|
i = i.lower()
|
|
|
|
target = message[0].replace("_", " ")
|
|
|
|
amount = message[1]
|
|
|
|
unit = message[2]
|
|
|
|
reason = ' '.join(message[3:])
|
|
|
|
|
|
|
|
# Get target user ID
|
|
|
|
targetUserID = userHelper.getID(target)
|
2016-06-07 21:19:45 +00:00
|
|
|
userID = userHelper.getID(fro)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Make sure the user exists
|
|
|
|
if targetUserID == False:
|
|
|
|
return "{}: user not found".format(target)
|
|
|
|
|
|
|
|
# Calculate silence seconds
|
|
|
|
if unit == 's':
|
|
|
|
silenceTime = int(amount)
|
|
|
|
elif unit == 'm':
|
|
|
|
silenceTime = int(amount)*60
|
|
|
|
elif unit == 'h':
|
|
|
|
silenceTime = int(amount)*3600
|
|
|
|
elif unit == 'd':
|
|
|
|
silenceTime = int(amount)*86400
|
|
|
|
else:
|
|
|
|
return "Invalid time unit (s/m/h/d)."
|
|
|
|
|
|
|
|
# Max silence time is 7 days
|
|
|
|
if silenceTime > 604800:
|
|
|
|
return "Invalid silence time. Max silence time is 7 days."
|
|
|
|
|
|
|
|
# Send silence packet to target if he's connected
|
|
|
|
targetToken = glob.tokens.getTokenFromUsername(target)
|
|
|
|
if targetToken != None:
|
2016-06-07 21:19:45 +00:00
|
|
|
# user online, silence both in db and with packet
|
|
|
|
targetToken.silence(silenceTime, reason, userID)
|
|
|
|
else:
|
|
|
|
# User offline, silence user only in db
|
2016-06-08 09:33:27 +00:00
|
|
|
userHelper.silence(targetUserID, silenceTime, reason, userID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-06-02 17:22:02 +00:00
|
|
|
# Log message
|
|
|
|
msg = "{} has been silenced for the following reason: {}".format(target, reason)
|
|
|
|
return msg
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def removeSilence(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)
|
2016-06-07 21:19:45 +00:00
|
|
|
userID = userHelper.getID(fro)
|
2016-04-19 17:40:59 +00:00
|
|
|
if targetUserID == False:
|
|
|
|
return "{}: user not found".format(target)
|
|
|
|
|
|
|
|
# Send new silence end packet to user if he's online
|
|
|
|
targetToken = glob.tokens.getTokenFromUsername(target)
|
|
|
|
if targetToken != None:
|
2016-06-07 21:19:45 +00:00
|
|
|
# User online, remove silence both in db and with packet
|
|
|
|
targetToken.silence(0, "", userID)
|
|
|
|
else:
|
|
|
|
# user offline, remove islene ofnlt from db
|
|
|
|
userHelper.silence(targetUserID, 0, "", userID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
return "{}'s silence reset".format(target)
|
|
|
|
|
2016-04-24 09:46:33 +00:00
|
|
|
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)
|
2016-06-08 09:33:27 +00:00
|
|
|
userID = userHelper.getID(fro)
|
2016-04-24 09:46:33 +00:00
|
|
|
if targetUserID == False:
|
|
|
|
return "{}: user not found".format(target)
|
|
|
|
|
|
|
|
# Set allowed to 0
|
2016-07-03 18:51:19 +00:00
|
|
|
userHelper.ban(targetUserID)
|
2016-04-24 09:46:33 +00:00
|
|
|
|
|
|
|
# Send ban packet to the user if he's online
|
|
|
|
targetToken = glob.tokens.getTokenFromUsername(target)
|
|
|
|
if targetToken != None:
|
|
|
|
targetToken.enqueue(serverPackets.loginBanned())
|
|
|
|
|
2016-06-08 09:33:27 +00:00
|
|
|
log.rap(userID, "has banned {}".format(target), True)
|
2016-04-24 09:46:33 +00:00
|
|
|
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)
|
2016-06-08 09:33:27 +00:00
|
|
|
userID = userHelper.getID(fro)
|
2016-04-24 09:46:33 +00:00
|
|
|
if targetUserID == False:
|
|
|
|
return "{}: user not found".format(target)
|
|
|
|
|
|
|
|
# Set allowed to 1
|
2016-07-03 18:51:19 +00:00
|
|
|
userHelper.unban(targetUserID)
|
2016-04-24 09:46:33 +00:00
|
|
|
|
2016-06-08 09:33:27 +00:00
|
|
|
log.rap(userID, "has unbanned {}".format(target), True)
|
2016-04-24 09:46:33 +00:00
|
|
|
return "Welcome back {}!".format(target)
|
|
|
|
|
2016-07-03 18:51:19 +00:00
|
|
|
def restrict(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)
|
|
|
|
userID = userHelper.getID(fro)
|
|
|
|
if targetUserID == False:
|
|
|
|
return "{}: user not found".format(target)
|
|
|
|
|
|
|
|
# Put this user in restricted mode
|
|
|
|
userHelper.restrict(targetUserID)
|
|
|
|
|
|
|
|
# Send restricted mode packet to this user if he's online
|
|
|
|
targetToken = glob.tokens.getTokenFromUsername(target)
|
|
|
|
if targetToken != None:
|
|
|
|
targetToken.setRestricted()
|
|
|
|
|
|
|
|
log.rap(userID, "has put {} in restricted mode".format(target), True)
|
|
|
|
return "Bye bye {}. See you later, maybe.".format(target)
|
|
|
|
|
|
|
|
def unrestrict(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)
|
|
|
|
userID = userHelper.getID(fro)
|
|
|
|
if targetUserID == False:
|
|
|
|
return "{}: user not found".format(target)
|
|
|
|
|
|
|
|
# Set allowed to 1
|
|
|
|
userHelper.unrestrict(targetUserID)
|
|
|
|
|
|
|
|
log.rap(userID, "has removed restricted mode from {}".format(target), True)
|
|
|
|
return "Welcome back {}!".format(target)
|
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
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")
|
|
|
|
systemHelper.scheduleShutdown(5, restart, msg)
|
|
|
|
return msg
|
|
|
|
|
|
|
|
def systemRestart(fro, chan, message):
|
|
|
|
return restartShutdown(True)
|
|
|
|
|
|
|
|
def systemShutdown(fro, chan, message):
|
|
|
|
return restartShutdown(False)
|
|
|
|
|
|
|
|
def systemReload(fro, chan, message):
|
|
|
|
#Reload settings from bancho_settings
|
|
|
|
glob.banchoConf.loadSettings()
|
|
|
|
|
|
|
|
# Reload channels too
|
|
|
|
glob.channels.loadChannels()
|
|
|
|
|
|
|
|
# Send new channels and new bottom icon to everyone
|
|
|
|
glob.tokens.enqueueAll(serverPackets.mainMenuIcon(glob.banchoConf.config["menuIcon"]))
|
|
|
|
glob.tokens.enqueueAll(serverPackets.channelInfoEnd())
|
|
|
|
for key, _ in glob.channels.channels.items():
|
|
|
|
glob.tokens.enqueueAll(serverPackets.channelInfo(key))
|
|
|
|
|
|
|
|
return "Bancho settings reloaded!"
|
|
|
|
|
|
|
|
def systemMaintenance(fro, chan, message):
|
|
|
|
# Turn on/off bancho maintenance
|
|
|
|
maintenance = True
|
|
|
|
|
|
|
|
# Get on/off
|
|
|
|
if len(message) >= 2:
|
|
|
|
if message[1] == "off":
|
|
|
|
maintenance = False
|
|
|
|
|
|
|
|
# Set new maintenance value in bancho_settings table
|
|
|
|
glob.banchoConf.setMaintenance(maintenance)
|
|
|
|
|
|
|
|
if maintenance == True:
|
|
|
|
# We have turned on maintenance mode
|
|
|
|
# Users that will be disconnected
|
|
|
|
who = []
|
|
|
|
|
|
|
|
# Disconnect everyone but mod/admins
|
|
|
|
for _, value in glob.tokens.tokens.items():
|
2016-07-03 18:51:19 +00:00
|
|
|
if value.admin == False:
|
2016-04-19 17:40:59 +00:00
|
|
|
who.append(value.userID)
|
|
|
|
|
|
|
|
glob.tokens.enqueueAll(serverPackets.notification("Our bancho server is in maintenance mode. Please try to login again later."))
|
|
|
|
glob.tokens.multipleEnqueue(serverPackets.loginError(), who)
|
|
|
|
msg = "The server is now in maintenance mode!"
|
|
|
|
else:
|
|
|
|
# We have turned off maintenance mode
|
|
|
|
# Send message if we have turned off maintenance mode
|
|
|
|
msg = "The server is no longer in maintenance mode!"
|
|
|
|
|
|
|
|
# Chat output
|
|
|
|
return msg
|
|
|
|
|
|
|
|
def systemStatus(fro, chan, message):
|
|
|
|
# Print some server info
|
|
|
|
data = systemHelper.getSystemInfo()
|
|
|
|
|
|
|
|
# Final message
|
2016-07-03 18:51:19 +00:00
|
|
|
msg = "pep.py bancho server v{}".format(glob.VERSION)
|
2016-06-09 08:51:13 +00:00
|
|
|
msg += "made by the Ripple team\n"
|
2016-04-19 17:40:59 +00:00
|
|
|
msg += "\n"
|
|
|
|
msg += "=== BANCHO STATS ===\n"
|
2016-06-09 08:51:13 +00:00
|
|
|
msg += "Connected users: {}\n".format(data["connectedUsers"])
|
|
|
|
msg += "Multiplayer matches: {}\n".format(data["matches"])
|
2016-04-19 17:40:59 +00:00
|
|
|
msg += "\n"
|
|
|
|
msg += "=== SYSTEM STATS ===\n"
|
2016-06-09 08:51:13 +00:00
|
|
|
msg += "CPU: {}%\n".format(data["cpuUsage"])
|
|
|
|
msg += "RAM: {}GB/{}GB\n".format(data["usedMemory"], data["totalMemory"])
|
2016-04-19 17:40:59 +00:00
|
|
|
if data["unix"] == True:
|
2016-06-09 08:51:13 +00:00
|
|
|
msg += "Load average: {}/{}/{}\n".format(data["loadAverage"][0], data["loadAverage"][1], data["loadAverage"][2])
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
return msg
|
|
|
|
|
2016-05-19 18:17:20 +00:00
|
|
|
|
2016-06-14 17:51:54 +00:00
|
|
|
def getPPMessage(userID, just_data = False):
|
2016-05-19 18:17:20 +00:00
|
|
|
try:
|
2016-05-19 20:10:50 +00:00
|
|
|
# Get user token
|
|
|
|
token = glob.tokens.getTokenFromUserID(userID)
|
|
|
|
if token == None:
|
|
|
|
return False
|
|
|
|
|
2016-05-19 18:17:20 +00:00
|
|
|
# Send request to LETS api
|
2016-05-20 16:50:14 +00:00
|
|
|
resp = requests.get("http://127.0.0.1:5002/api/v1/pp?b={}&m={}&a={}".format(token.tillerino[0], token.tillerino[1], token.tillerino[2]), timeout=10).text
|
2016-05-19 18:17:20 +00:00
|
|
|
data = json.loads(resp)
|
|
|
|
|
|
|
|
# Make sure status is in response data
|
|
|
|
if "status" not in data:
|
|
|
|
raise exceptions.apiException
|
|
|
|
|
|
|
|
# Make sure status is 200
|
|
|
|
if data["status"] != 200:
|
|
|
|
if "message" in data:
|
|
|
|
return "Error in LETS API call ({}). Please tell this to a dev.".format(data["message"])
|
|
|
|
else:
|
|
|
|
raise exceptions.apiException
|
2016-05-20 16:53:09 +00:00
|
|
|
|
2016-06-14 17:51:54 +00:00
|
|
|
if just_data:
|
|
|
|
return data
|
|
|
|
|
2016-05-19 18:17:20 +00:00
|
|
|
# Return response in chat
|
2016-05-19 20:10:50 +00:00
|
|
|
# Song name and mods
|
|
|
|
msg = "{song}{plus}{mods} ".format(song=data["song_name"], plus="+" if token.tillerino[1] > 0 else "", mods=generalFunctions.readableMods(token.tillerino[1]))
|
|
|
|
|
|
|
|
# PP values
|
|
|
|
if token.tillerino[2] == -1:
|
|
|
|
msg += "95%: {pp95}pp | 98%: {pp98}pp | 99% {pp99}pp | 100%: {pp100}pp".format(pp100=data["pp"][0], pp99=data["pp"][1], pp98=data["pp"][2], pp95=data["pp"][3])
|
|
|
|
else:
|
|
|
|
msg += "{acc:.2f}%: {pp}pp".format(acc=token.tillerino[2], pp=data["pp"][0])
|
|
|
|
|
|
|
|
# Beatmap info
|
|
|
|
msg += " | {bpm} BPM | AR {ar} | {stars:.2f} stars".format(bpm=data["bpm"], stars=data["stars"], ar=data["ar"])
|
|
|
|
|
|
|
|
# Return final message
|
|
|
|
return msg
|
2016-05-19 18:17:20 +00:00
|
|
|
except requests.exceptions.RequestException:
|
|
|
|
# RequestException
|
2016-05-28 18:26:26 +00:00
|
|
|
return "API Timeout. Please try again in a few seconds."
|
2016-05-19 18:17:20 +00:00
|
|
|
except exceptions.apiException:
|
|
|
|
# API error
|
|
|
|
return "Unknown error in LETS API call. Please tell this to a dev."
|
|
|
|
except:
|
|
|
|
# Unknown exception
|
|
|
|
# TODO: print exception
|
|
|
|
return False
|
|
|
|
|
|
|
|
def tillerinoNp(fro, chan, message):
|
|
|
|
try:
|
|
|
|
# Run the command in PM only
|
|
|
|
if chan.startswith("#"):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Get URL from message
|
2016-05-19 21:31:48 +00:00
|
|
|
if message[1] == "listening":
|
|
|
|
beatmapURL = str(message[3][1:])
|
2016-06-13 17:54:07 +00:00
|
|
|
elif message[1] == "playing" or message[1] == "watching":
|
2016-05-19 21:31:48 +00:00
|
|
|
beatmapURL = str(message[2][1:])
|
|
|
|
else:
|
|
|
|
return False
|
2016-05-19 18:17:20 +00:00
|
|
|
|
|
|
|
# Get beatmap id from URL
|
2016-05-20 16:53:09 +00:00
|
|
|
beatmapID = fokabot.npRegex.search(beatmapURL).groups(0)[0]
|
2016-05-19 18:17:20 +00:00
|
|
|
|
|
|
|
# Update latest tillerino song for current token
|
|
|
|
token = glob.tokens.getTokenFromUsername(fro)
|
|
|
|
if token != None:
|
2016-05-19 20:10:50 +00:00
|
|
|
token.tillerino = [int(beatmapID), 0, -1.0]
|
|
|
|
userID = token.userID
|
2016-05-19 18:17:20 +00:00
|
|
|
|
|
|
|
# Return tillerino message
|
2016-05-19 20:10:50 +00:00
|
|
|
return getPPMessage(userID)
|
2016-05-19 18:17:20 +00:00
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def tillerinoMods(fro, chan, message):
|
2016-05-19 20:10:50 +00:00
|
|
|
try:
|
|
|
|
# Run the command in PM only
|
|
|
|
if chan.startswith("#"):
|
|
|
|
return False
|
2016-05-19 18:17:20 +00:00
|
|
|
|
2016-05-19 20:10:50 +00:00
|
|
|
# Get token and user ID
|
|
|
|
token = glob.tokens.getTokenFromUsername(fro)
|
|
|
|
if token == None:
|
|
|
|
return False
|
|
|
|
userID = token.userID
|
|
|
|
|
|
|
|
# Make sure the user has triggered the bot with /np command
|
|
|
|
if token.tillerino[0] == 0:
|
|
|
|
return "Please give me a beatmap first with /np command."
|
|
|
|
|
|
|
|
# Check passed mods and convert to enum
|
|
|
|
modsList = [message[0][i:i+2].upper() for i in range(0, len(message[0]), 2)]
|
|
|
|
modsEnum = 0
|
|
|
|
for i in modsList:
|
|
|
|
if i not in ["NO", "NF", "EZ", "HD", "HR", "DT", "HT", "NC", "FL", "SO"]:
|
|
|
|
return "Invalid mods. Allowed mods: NO, NF, EZ, HD, HR, DT, HT, NC, FL, SO. Do not use spaces for multiple mods."
|
|
|
|
if i == "NO":
|
|
|
|
modsEnum = 0
|
|
|
|
break
|
|
|
|
elif i == "NF":
|
|
|
|
modsEnum += mods.NoFail
|
|
|
|
elif i == "EZ":
|
|
|
|
modsEnum += mods.Easy
|
|
|
|
elif i == "HD":
|
|
|
|
modsEnum += mods.Hidden
|
|
|
|
elif i == "HR":
|
|
|
|
modsEnum += mods.HardRock
|
|
|
|
elif i == "DT":
|
|
|
|
modsEnum += mods.DoubleTime
|
|
|
|
elif i == "HT":
|
|
|
|
modsEnum += mods.HalfTime
|
|
|
|
elif i == "NC":
|
|
|
|
modsEnum += mods.Nightcore
|
|
|
|
elif i == "FL":
|
|
|
|
modsEnum += mods.Flashlight
|
|
|
|
elif i == "SO":
|
|
|
|
modsEnum += mods.SpunOut
|
|
|
|
|
|
|
|
# Set mods
|
|
|
|
token.tillerino[1] = modsEnum
|
|
|
|
|
|
|
|
# Return tillerino message for that beatmap with mods
|
|
|
|
return getPPMessage(userID)
|
|
|
|
except:
|
2016-05-19 18:17:20 +00:00
|
|
|
return False
|
|
|
|
|
2016-05-19 20:10:50 +00:00
|
|
|
def tillerinoAcc(fro, chan, message):
|
|
|
|
try:
|
|
|
|
# Run the command in PM only
|
|
|
|
if chan.startswith("#"):
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Get token and user ID
|
|
|
|
token = glob.tokens.getTokenFromUsername(fro)
|
|
|
|
if token == None:
|
|
|
|
return False
|
|
|
|
userID = token.userID
|
|
|
|
|
|
|
|
# Make sure the user has triggered the bot with /np command
|
|
|
|
if token.tillerino[0] == 0:
|
|
|
|
return "Please give me a beatmap first with /np command."
|
|
|
|
|
|
|
|
# Convert acc to float
|
|
|
|
acc = float(message[0])
|
|
|
|
|
|
|
|
# Set new tillerino list acc value
|
|
|
|
token.tillerino[2] = acc
|
|
|
|
|
|
|
|
# Return tillerino message for that beatmap with mods
|
|
|
|
return getPPMessage(userID)
|
|
|
|
except ValueError:
|
|
|
|
return "Invalid acc value"
|
|
|
|
except:
|
|
|
|
return False
|
2016-05-19 18:17:20 +00:00
|
|
|
|
2016-05-25 14:23:53 +00:00
|
|
|
def tillerinoLast(fro, chan, message):
|
|
|
|
try:
|
2016-06-06 17:10:32 +00:00
|
|
|
data = glob.db.fetch("""SELECT beatmaps.song_name as sn, scores.*,
|
2016-06-16 01:34:38 +00:00
|
|
|
beatmaps.beatmap_id as bid, beatmaps.difficulty, beatmaps.max_combo as fc
|
2016-05-25 14:23:53 +00:00
|
|
|
FROM scores
|
|
|
|
LEFT JOIN beatmaps ON beatmaps.beatmap_md5=scores.beatmap_md5
|
2016-05-28 20:33:05 +00:00
|
|
|
LEFT JOIN users ON users.id = scores.userid
|
2016-05-31 20:49:30 +00:00
|
|
|
WHERE users.username = %s
|
2016-05-25 14:23:53 +00:00
|
|
|
ORDER BY scores.time DESC
|
|
|
|
LIMIT 1""", [fro])
|
|
|
|
if data == None:
|
|
|
|
return False
|
2016-06-06 17:10:32 +00:00
|
|
|
|
|
|
|
rank = generalFunctions.getRank(data["play_mode"], data["mods"], data["accuracy"],\
|
|
|
|
data["300_count"], data["100_count"], data["50_count"], data["misses_count"])
|
|
|
|
|
2016-06-16 01:34:38 +00:00
|
|
|
ifPlayer = "{0} | ".format(fro) if chan != "FokaBot" else ""
|
|
|
|
beatmapLink = "[http://osu.ppy.sh/b/{1} {0}]".format(data["sn"], data["bid"])
|
|
|
|
|
|
|
|
ifFc = " (FC)" if data["max_combo"] == data["fc"] else " {0}x/{1}x".format(data["max_combo"], data["fc"])
|
|
|
|
|
|
|
|
if data["play_mode"] != gameModes.std:
|
|
|
|
msg = ifPlayer
|
|
|
|
msg += beatmapLink
|
|
|
|
if data["mods"]:
|
|
|
|
msg += ' +' + generalFunctions.readableMods(data["mods"])
|
|
|
|
msg += " | {0:,}".format(data["score"])
|
|
|
|
msg += ifFc
|
|
|
|
msg += " | {0:.2f}%, {1}".format(data["accuracy"], rank.upper())
|
|
|
|
msg += " {{ {0} / {1} / {2} / {3} }}".format(data["300_count"], data["100_count"], data["50_count"], data["misses_count"])
|
|
|
|
msg += " | {0:.2f} stars".format(data["difficulty"])
|
|
|
|
return msg
|
|
|
|
|
|
|
|
msg = ifPlayer
|
|
|
|
msg += beatmapLink
|
2016-06-06 17:10:32 +00:00
|
|
|
if data["mods"]:
|
|
|
|
msg += ' +' + generalFunctions.readableMods(data["mods"])
|
2016-06-16 01:34:38 +00:00
|
|
|
msg += " ({0:.2f}%, {1})".format(data["accuracy"], rank.upper())
|
|
|
|
msg += ifFc
|
|
|
|
msg += " | {0:.2f}pp".format(data["pp"])
|
2016-06-14 17:51:54 +00:00
|
|
|
|
2016-06-16 01:34:38 +00:00
|
|
|
stars = data["difficulty"]
|
|
|
|
if data["mods"]:
|
2016-06-14 17:51:54 +00:00
|
|
|
token = glob.tokens.getTokenFromUsername(fro)
|
|
|
|
if token == None:
|
|
|
|
return False
|
|
|
|
userID = token.userID
|
|
|
|
token.tillerino[0] = data["bid"]
|
|
|
|
token.tillerino[1] = data["mods"]
|
|
|
|
token.tillerino[2] = data["accuracy"]
|
|
|
|
oppaiData = getPPMessage(userID, just_data=True)
|
|
|
|
if "stars" in oppaiData:
|
|
|
|
stars = oppaiData["stars"]
|
|
|
|
|
|
|
|
msg += " | {0:.2f} stars".format(stars)
|
2016-06-06 17:10:32 +00:00
|
|
|
|
|
|
|
return msg
|
2016-05-25 14:23:53 +00:00
|
|
|
except Exception as a:
|
2016-06-04 10:44:54 +00:00
|
|
|
log.error(a)
|
2016-05-25 14:23:53 +00:00
|
|
|
return False
|
2016-05-19 18:17:20 +00:00
|
|
|
|
2016-05-28 18:30:34 +00:00
|
|
|
def mm00(fro, chan, message):
|
|
|
|
random.seed()
|
|
|
|
return random.choice(["meme", "MA MAURO ESISTE?"])
|
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Commands list
|
|
|
|
|
|
|
|
trigger: message that triggers the command
|
|
|
|
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: <arg1> <arg2>)
|
2016-07-03 18:51:19 +00:00
|
|
|
privileges: privileges needed to execute the command. Optional.
|
2016-05-28 18:26:26 +00:00
|
|
|
|
|
|
|
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.
|
2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
commands = [
|
|
|
|
{
|
|
|
|
"trigger": "!roll",
|
|
|
|
"callback": roll
|
|
|
|
}, {
|
|
|
|
"trigger": "!faq",
|
|
|
|
"syntax": "<name>",
|
|
|
|
"callback": faq
|
|
|
|
}, {
|
|
|
|
"trigger": "!report",
|
|
|
|
"response": "Report command isn't here yet :c"
|
|
|
|
}, {
|
|
|
|
"trigger": "!help",
|
|
|
|
"response": "Click (here)[https://ripple.moe/index.php?p=16&id=4] for FokaBot's full command list"
|
|
|
|
}, {
|
|
|
|
"trigger": "!ask",
|
|
|
|
"syntax": "<question>",
|
|
|
|
"callback": ask
|
|
|
|
}, {
|
|
|
|
"trigger": "!mm00",
|
2016-05-28 18:30:34 +00:00
|
|
|
"callback": mm00
|
2016-04-19 17:40:59 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!alert",
|
|
|
|
"syntax": "<message>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_SEND_ALERTS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": alert
|
2016-05-28 18:26:26 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!alertuser",
|
|
|
|
"syntax": "<username> <message>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_SEND_ALERTS,
|
2016-05-28 18:26:26 +00:00
|
|
|
"callback": alertUser,
|
2016-04-19 17:40:59 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!moderated",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_CHAT_MOD,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": moderated
|
|
|
|
}, {
|
|
|
|
"trigger": "!kickall",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_KICK_USERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": kickAll
|
|
|
|
}, {
|
|
|
|
"trigger": "!kick",
|
|
|
|
"syntax": "<target>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_KICK_USERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": kick
|
|
|
|
}, {
|
|
|
|
"trigger": "!fokabot reconnect",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_MANAGE_SERVERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": fokabotReconnect
|
|
|
|
}, {
|
|
|
|
"trigger": "!silence",
|
|
|
|
"syntax": "<target> <amount> <unit(s/m/h/d)> <reason>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_SILENCE_USERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": silence
|
|
|
|
}, {
|
|
|
|
"trigger": "!removesilence",
|
|
|
|
"syntax": "<target>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_SILENCE_USERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": removeSilence
|
|
|
|
}, {
|
|
|
|
"trigger": "!system restart",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_MANAGE_SERVERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": systemRestart
|
|
|
|
}, {
|
|
|
|
"trigger": "!system shutdown",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_MANAGE_SERVERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": systemShutdown
|
|
|
|
}, {
|
|
|
|
"trigger": "!system reload",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_MANAGE_SETTINGS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": systemReload
|
|
|
|
}, {
|
|
|
|
"trigger": "!system maintenance",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_MANAGE_SERVERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": systemMaintenance
|
|
|
|
}, {
|
|
|
|
"trigger": "!system status",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_MANAGE_SERVERS,
|
2016-04-19 17:40:59 +00:00
|
|
|
"callback": systemStatus
|
2016-04-24 09:46:33 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!ban",
|
|
|
|
"syntax": "<target>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_BAN_USERS,
|
2016-04-24 09:46:33 +00:00
|
|
|
"callback": ban
|
|
|
|
}, {
|
|
|
|
"trigger": "!unban",
|
|
|
|
"syntax": "<target>",
|
2016-07-03 18:51:19 +00:00
|
|
|
"privileges": privileges.ADMIN_BAN_USERS,
|
2016-04-24 09:46:33 +00:00
|
|
|
"callback": unban
|
2016-07-03 18:51:19 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!restrict",
|
|
|
|
"syntax": "<target>",
|
|
|
|
"privileges": privileges.ADMIN_BAN_USERS,
|
|
|
|
"callback": restrict
|
|
|
|
}, {
|
|
|
|
"trigger": "!unrestrict",
|
|
|
|
"syntax": "<target>",
|
|
|
|
"privileges": privileges.ADMIN_BAN_USERS,
|
|
|
|
"callback": unrestrict
|
2016-05-19 18:17:20 +00:00
|
|
|
}, {
|
2016-05-29 12:14:27 +00:00
|
|
|
"trigger": "\x01ACTION is listening to",
|
2016-05-19 18:17:20 +00:00
|
|
|
"callback": tillerinoNp
|
2016-05-19 21:31:48 +00:00
|
|
|
}, {
|
2016-05-29 12:14:27 +00:00
|
|
|
"trigger": "\x01ACTION is playing",
|
2016-05-19 21:31:48 +00:00
|
|
|
"callback": tillerinoNp
|
2016-06-13 17:54:07 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "\x01ACTION is watching",
|
|
|
|
"callback": tillerinoNp
|
2016-05-19 18:17:20 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!with",
|
|
|
|
"callback": tillerinoMods,
|
|
|
|
"syntax": "<mods>"
|
2016-05-25 14:23:53 +00:00
|
|
|
}, {
|
|
|
|
"trigger": "!last",
|
|
|
|
"callback": tillerinoLast
|
|
|
|
}
|
2016-05-19 20:10:50 +00:00
|
|
|
#
|
|
|
|
# "trigger": "!acc",
|
|
|
|
# "callback": tillerinoAcc,
|
|
|
|
# "syntax": "<accuarcy>"
|
|
|
|
#}
|
2016-04-19 17:40:59 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# Commands list default values
|
|
|
|
for cmd in commands:
|
|
|
|
cmd.setdefault("syntax", "")
|
2016-07-03 18:51:19 +00:00
|
|
|
cmd.setdefault("privileges", None)
|
2016-04-19 17:40:59 +00:00
|
|
|
cmd.setdefault("callback", None)
|
|
|
|
cmd.setdefault("response", "u w0t m8?")
|