From 27a5f9c000be1328641e348741750cb5f7588aea Mon Sep 17 00:00:00 2001 From: Sunpy Date: Wed, 14 Feb 2018 17:44:37 +0100 Subject: [PATCH] Use whatever account that is in id 999 as bot --- constants/fokabotCommands.py | 28 ++++++++++++++-------------- constants/serverPackets.py | 2 +- events/setAwayMessageEvent.py | 3 ++- handlers/apiFokabotMessageHandler.py | 2 +- helpers/chatHelper.py | 8 ++++---- objects/fokabot.py | 1 + objects/glob.py | 1 + objects/match.py | 6 +++--- objects/osuToken.py | 4 ++-- pep.py | 2 +- 10 files changed, 30 insertions(+), 27 deletions(-) diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 4228db2..f5336e3 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -135,7 +135,7 @@ def kickAll(fro, chan, message): def kick(fro, chan, message): # Get parameters target = message[0].lower() - if target == "fokabot": + if target == glob.BOT_NAME.lower(): return "Nope." # Get target token and make sure is connected @@ -153,7 +153,7 @@ def kick(fro, chan, message): def fokabotReconnect(fro, chan, message): # Check if fokabot is already connected if glob.tokens.getTokenFromUserID(999) is not None: - return "Fokabot is already connected to Bancho" + return "{} is already connected to Bancho".format(glob.BOT_NAME) # Fokabot is not connected, connect it fokabot.connect() @@ -602,7 +602,7 @@ def tillerinoLast(fro, chan, message): rank = generalUtils.getRank(data["play_mode"], data["mods"], data["accuracy"], data["300_count"], data["100_count"], data["50_count"], data["misses_count"]) - ifPlayer = "{0} | ".format(fro) if chan != "FokaBot" else "" + ifPlayer = "{0} | ".format(fro) if chan != glob.BOT_NAME else "" ifFc = " (FC)" if data["max_combo"] == data["fc"] else " {0}x/{1}x".format(data["max_combo"], data["fc"]) beatmapLink = "[http://osu.ppy.sh/b/{1} {0}]".format(data["sn"], data["bid"]) @@ -720,7 +720,7 @@ def report(fro, chan, message): target = chat.fixUsernameForBancho(target) # Make sure the target is not foka - if target.lower() == "fokabot": + if target.lower() == glob.BOT_NAME.lower(): raise exceptions.invalidUserException() # Make sure the user exists @@ -744,10 +744,10 @@ def report(fro, chan, message): adminMsg = "{user} has reported {target} for {reason} ({info})".format(user=fro, target=target, reason=reason, info=additionalInfo) # Log report in #admin and on discord - chat.sendMessage("FokaBot", "#admin", adminMsg) + chat.sendMessage(glob.BOT_NAME, "#admin", adminMsg) log.warning(adminMsg, discord="cm") except exceptions.invalidUserException: - msg = "Hello, FokaBot here! You can't report me. I won't forget what you've tried to do. Watch out." + msg = "Hello, {} here! You can't report me. I won't forget what you've tried to do. Watch out.".format(glob.BOT_NAME) except exceptions.invalidArgumentsException: msg = "Invalid report command syntax. To report an user, click on it and select 'Report user'." except exceptions.userNotFoundException: @@ -761,7 +761,7 @@ def report(fro, chan, message): token = glob.tokens.getTokenFromUsername(fro) if token is not None: if token.irc: - chat.sendMessage("FokaBot", fro, msg) + chat.sendMessage(glob.BOT_NAME, fro, msg) else: token.enqueue(serverPackets.notification(msg)) return False @@ -853,10 +853,10 @@ def multiplayer(fro, chan, message): matchID = getMatchIDFromChannel(chan) success = glob.matches.matches[matchID].start() if not success: - chat.sendMessage("FokaBot", chan, "Couldn't start match. Make sure there are enough players and " + chat.sendMessage(glob.BOT_NAME, chan, "Couldn't start match. Make sure there are enough players and " "teams are valid. The match has been unlocked.") else: - chat.sendMessage("FokaBot", chan, "Have fun!") + chat.sendMessage(glob.BOT_NAME, chan, "Have fun!") def _decreaseTimer(t): @@ -864,7 +864,7 @@ def multiplayer(fro, chan, message): _start() else: if t % 10 == 0 or t <= 5: - chat.sendMessage("FokaBot", chan, "Match starts in {} seconds.".format(t)) + chat.sendMessage(glob.BOT_NAME, chan, "Match starts in {} seconds.".format(t)) threading.Timer(1.00, _decreaseTimer, [t - 1]).start() if len(message) < 2 or not message[1].isdigit(): @@ -909,8 +909,8 @@ def multiplayer(fro, chan, message): raise exceptions.invalidUserException("That user is not connected to bancho right now.") _match = glob.matches.matches[getMatchIDFromChannel(chan)] _match.invite(999, userID) - token.enqueue(serverPackets.notification("Please accept the invite you've just received from FokaBot to " - "enter your tourney match.")) + token.enqueue(serverPackets.notification("Please accept the invite you've just received from {} to " + "enter your tourney match.".format(glob.BOT_NAME))) return "An invite to this match has been sent to {}".format(username) def mpMap(): @@ -1154,7 +1154,7 @@ commands = [ "callback": report }, { "trigger": "!help", - "response": "Click (here)[https://ripple.moe/index.php?p=16&id=4] for FokaBot's full command list" + "response": "Click (here)[https://ripple.moe/index.php?p=16&id=4] for {}'s full command list".format(glob.BOT_NAME) }, #{ #"trigger": "!ask", #"syntax": "", @@ -1187,7 +1187,7 @@ commands = [ "privileges": privileges.ADMIN_KICK_USERS, "callback": kick }, { - "trigger": "!fokabot reconnect", + "trigger": "!{} reconnect".format(glob.BOT_NAME.lower()), "privileges": privileges.ADMIN_MANAGE_SERVERS, "callback": fokabotReconnect }, { diff --git a/constants/serverPackets.py b/constants/serverPackets.py index 299d0b1..e33e283 100644 --- a/constants/serverPackets.py +++ b/constants/serverPackets.py @@ -94,7 +94,7 @@ def userPanel(userID, force = False): # Get username color according to rank # Only admins and normal users are currently supported userRank = 0 - if username == "FokaBot": + if username == glob.BOT_NAME: userRank |= userRanks.MOD elif userUtils.isInPrivilegeGroup(userID, "developer"): userRank |= userRanks.ADMIN diff --git a/events/setAwayMessageEvent.py b/events/setAwayMessageEvent.py index f69a6e6..4b2058b 100644 --- a/events/setAwayMessageEvent.py +++ b/events/setAwayMessageEvent.py @@ -1,6 +1,7 @@ from common.log import logUtils as log from constants import clientPackets from constants import serverPackets +from objects import glob def handle(userToken, packetData): @@ -18,5 +19,5 @@ def handle(userToken, packetData): fokaMessage = "Your away message has been reset" else: fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"]) - userToken.enqueue(serverPackets.sendMessage("FokaBot", username, fokaMessage)) + userToken.enqueue(serverPackets.sendMessage(glob.BOT_NAME, username, fokaMessage)) log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"])) diff --git a/handlers/apiFokabotMessageHandler.py b/handlers/apiFokabotMessageHandler.py index 85e2729..eed14ef 100644 --- a/handlers/apiFokabotMessageHandler.py +++ b/handlers/apiFokabotMessageHandler.py @@ -28,7 +28,7 @@ class handler(requestsManager.asyncRequestHandler): raise exceptions.invalidArgumentsException() chatHelper.sendMessage( - "FokaBot", + glob.BOT_NAME, self.get_argument("to").encode().decode("ASCII", "ignore"), self.get_argument("msg").encode().decode("ASCII", "ignore") ) diff --git a/helpers/chatHelper.py b/helpers/chatHelper.py index 440442b..1ed89a9 100644 --- a/helpers/chatHelper.py +++ b/helpers/chatHelper.py @@ -177,7 +177,7 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True): # Redirect !report to FokaBot if message.startswith("!report"): - to = "FokaBot" + to = glob.BOT_NAME # Determine internal name if needed # (toclient is used clientwise for #multiplayer and #spectator channels) @@ -236,7 +236,7 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True): # raise exceptions.userTournamentException() # Make sure the recipient is not restricted or we are FokaBot - if recipientToken.restricted == True and fro.lower() != "fokabot": + if recipientToken.restricted == True and fro.lower() != glob.BOT_NAME.lower(): raise exceptions.userRestrictedException() # TODO: Make sure the recipient has not disabled PMs for non-friends or he's our friend @@ -265,10 +265,10 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True): token.spamProtection() # Fokabot message - if isChannel == True or to.lower() == "fokabot": + if isChannel == True or to.lower() == glob.BOT_NAME.lower(): fokaMessage = fokabot.fokabotResponse(token.username, to, message) if fokaMessage: - sendMessage("FokaBot", to if isChannel else fro, fokaMessage) + sendMessage(glob.BOT_NAME, to if isChannel else fro, fokaMessage) # File and discord logs (public chat only) if to.startswith("#") and not (message.startswith("\x01ACTION is playing") and to.startswith("#spect_")): diff --git a/objects/fokabot.py b/objects/fokabot.py index d45a43c..24afa43 100644 --- a/objects/fokabot.py +++ b/objects/fokabot.py @@ -17,6 +17,7 @@ def connect(): :return: """ + glob.BOT_NAME = userUtils.getUsername(999) token = glob.tokens.addToken(999) token.actionID = actions.IDLE glob.streams.broadcast("main", serverPackets.userPanel(999)) diff --git a/objects/glob.py b/objects/glob.py index c47a78e..0e10eb7 100644 --- a/objects/glob.py +++ b/objects/glob.py @@ -18,6 +18,7 @@ except: VERSION = "Unknown" DATADOG_PREFIX = "peppy" +BOT_NAME = "FokaBot" application = None db = None redis = None diff --git a/objects/match.py b/objects/match.py index 5f1f271..f706906 100644 --- a/objects/match.py +++ b/objects/match.py @@ -433,7 +433,7 @@ class match: # saying that the match has completed. chanName = "#multi_{}".format(self.matchID) if self.isTourney and (chanName in glob.channels.channels): - chat.sendMessage("FokaBot", chanName, "Match has just finished.") + chat.sendMessage(glob.BOT_NAME, chanName, "Match has just finished.") def resetSlots(self): for i in range(0,16): @@ -665,7 +665,7 @@ class match: # FokaBot is too busy if to == 999: - chat.sendMessage("FokaBot", froToken.username, "I would love to join your match, but I'm busy keeping ripple up and running. Sorry. Beep Boop.") + chat.sendMessage(glob.BOT_NAME, froToken.username, "I would love to join your match, but I'm busy keeping ripple up and running. Sorry. Beep Boop.") # Send message message = "Come join my multiplayer match: \"[osump://{}/{} {}]\"".format(self.matchID, self.matchPassword.replace(" ", "_"), self.matchName) @@ -855,7 +855,7 @@ class match: if totalUsers == 0: message = "The match is now empty." - chat.sendMessage("FokaBot", chanName, message) + chat.sendMessage(glob.BOT_NAME, chanName, message) def __enter__(self): # 🌚🌚🌚🌚🌚 diff --git a/objects/osuToken.py b/objects/osuToken.py index a4b0a43..627c595 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -487,7 +487,7 @@ class token: :return: """ self.restricted = True - chat.sendMessage("FokaBot", self.username, "Your account is currently in restricted mode. Please visit ripple's website for more information.") + chat.sendMessage(glob.BOT_NAME, self.username, "Your account is currently in restricted mode. Please visit ripple's website for more information.") def resetRestricted(self): """ @@ -496,7 +496,7 @@ class token: :return: """ - chat.sendMessage("FokaBot", self.username, "Your account has been unrestricted! Please log in again.") + chat.sendMessage(glob.BOT_NAME, self.username, "Your account has been unrestricted! Please log in again.") def joinStream(self, name): """ diff --git a/pep.py b/pep.py index 372c1bf..ef6e10e 100644 --- a/pep.py +++ b/pep.py @@ -156,7 +156,7 @@ if __name__ == "__main__": raise # Start fokabot - consoleHelper.printNoNl("> Connecting FokaBot... ") + consoleHelper.printNoNl("> Connecting bot... ") fokabot.connect() consoleHelper.printDone()