Use whatever account that is in id 999 as bot

This commit is contained in:
Sunpy 2018-02-14 17:44:37 +01:00
parent 29db61fd12
commit 27a5f9c000
10 changed files with 30 additions and 27 deletions

View File

@ -135,7 +135,7 @@ def kickAll(fro, chan, message):
def kick(fro, chan, message): def kick(fro, chan, message):
# Get parameters # Get parameters
target = message[0].lower() target = message[0].lower()
if target == "fokabot": if target == glob.BOT_NAME.lower():
return "Nope." return "Nope."
# Get target token and make sure is connected # Get target token and make sure is connected
@ -153,7 +153,7 @@ def kick(fro, chan, message):
def fokabotReconnect(fro, chan, message): def fokabotReconnect(fro, chan, message):
# Check if fokabot is already connected # Check if fokabot is already connected
if glob.tokens.getTokenFromUserID(999) is not None: 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 is not connected, connect it
fokabot.connect() fokabot.connect()
@ -602,7 +602,7 @@ def tillerinoLast(fro, chan, message):
rank = generalUtils.getRank(data["play_mode"], data["mods"], data["accuracy"], rank = generalUtils.getRank(data["play_mode"], data["mods"], data["accuracy"],
data["300_count"], data["100_count"], data["50_count"], data["misses_count"]) 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"]) 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"]) 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) target = chat.fixUsernameForBancho(target)
# Make sure the target is not foka # Make sure the target is not foka
if target.lower() == "fokabot": if target.lower() == glob.BOT_NAME.lower():
raise exceptions.invalidUserException() raise exceptions.invalidUserException()
# Make sure the user exists # 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) adminMsg = "{user} has reported {target} for {reason} ({info})".format(user=fro, target=target, reason=reason, info=additionalInfo)
# Log report in #admin and on discord # Log report in #admin and on discord
chat.sendMessage("FokaBot", "#admin", adminMsg) chat.sendMessage(glob.BOT_NAME, "#admin", adminMsg)
log.warning(adminMsg, discord="cm") log.warning(adminMsg, discord="cm")
except exceptions.invalidUserException: 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: except exceptions.invalidArgumentsException:
msg = "Invalid report command syntax. To report an user, click on it and select 'Report user'." msg = "Invalid report command syntax. To report an user, click on it and select 'Report user'."
except exceptions.userNotFoundException: except exceptions.userNotFoundException:
@ -761,7 +761,7 @@ def report(fro, chan, message):
token = glob.tokens.getTokenFromUsername(fro) token = glob.tokens.getTokenFromUsername(fro)
if token is not None: if token is not None:
if token.irc: if token.irc:
chat.sendMessage("FokaBot", fro, msg) chat.sendMessage(glob.BOT_NAME, fro, msg)
else: else:
token.enqueue(serverPackets.notification(msg)) token.enqueue(serverPackets.notification(msg))
return False return False
@ -853,10 +853,10 @@ def multiplayer(fro, chan, message):
matchID = getMatchIDFromChannel(chan) matchID = getMatchIDFromChannel(chan)
success = glob.matches.matches[matchID].start() success = glob.matches.matches[matchID].start()
if not success: 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.") "teams are valid. The match has been unlocked.")
else: else:
chat.sendMessage("FokaBot", chan, "Have fun!") chat.sendMessage(glob.BOT_NAME, chan, "Have fun!")
def _decreaseTimer(t): def _decreaseTimer(t):
@ -864,7 +864,7 @@ def multiplayer(fro, chan, message):
_start() _start()
else: else:
if t % 10 == 0 or t <= 5: 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() threading.Timer(1.00, _decreaseTimer, [t - 1]).start()
if len(message) < 2 or not message[1].isdigit(): 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.") raise exceptions.invalidUserException("That user is not connected to bancho right now.")
_match = glob.matches.matches[getMatchIDFromChannel(chan)] _match = glob.matches.matches[getMatchIDFromChannel(chan)]
_match.invite(999, userID) _match.invite(999, userID)
token.enqueue(serverPackets.notification("Please accept the invite you've just received from FokaBot to " token.enqueue(serverPackets.notification("Please accept the invite you've just received from {} to "
"enter your tourney match.")) "enter your tourney match.".format(glob.BOT_NAME)))
return "An invite to this match has been sent to {}".format(username) return "An invite to this match has been sent to {}".format(username)
def mpMap(): def mpMap():
@ -1154,7 +1154,7 @@ commands = [
"callback": report "callback": report
}, { }, {
"trigger": "!help", "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", #"trigger": "!ask",
#"syntax": "<question>", #"syntax": "<question>",
@ -1187,7 +1187,7 @@ commands = [
"privileges": privileges.ADMIN_KICK_USERS, "privileges": privileges.ADMIN_KICK_USERS,
"callback": kick "callback": kick
}, { }, {
"trigger": "!fokabot reconnect", "trigger": "!{} reconnect".format(glob.BOT_NAME.lower()),
"privileges": privileges.ADMIN_MANAGE_SERVERS, "privileges": privileges.ADMIN_MANAGE_SERVERS,
"callback": fokabotReconnect "callback": fokabotReconnect
}, { }, {

View File

@ -94,7 +94,7 @@ def userPanel(userID, force = False):
# Get username color according to rank # Get username color according to rank
# Only admins and normal users are currently supported # Only admins and normal users are currently supported
userRank = 0 userRank = 0
if username == "FokaBot": if username == glob.BOT_NAME:
userRank |= userRanks.MOD userRank |= userRanks.MOD
elif userUtils.isInPrivilegeGroup(userID, "developer"): elif userUtils.isInPrivilegeGroup(userID, "developer"):
userRank |= userRanks.ADMIN userRank |= userRanks.ADMIN

View File

@ -1,6 +1,7 @@
from common.log import logUtils as log from common.log import logUtils as log
from constants import clientPackets from constants import clientPackets
from constants import serverPackets from constants import serverPackets
from objects import glob
def handle(userToken, packetData): def handle(userToken, packetData):
@ -18,5 +19,5 @@ def handle(userToken, packetData):
fokaMessage = "Your away message has been reset" fokaMessage = "Your away message has been reset"
else: else:
fokaMessage = "Your away message is now: {}".format(packetData["awayMessage"]) 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"])) log.info("{} has changed their away message to: {}".format(username, packetData["awayMessage"]))

View File

@ -28,7 +28,7 @@ class handler(requestsManager.asyncRequestHandler):
raise exceptions.invalidArgumentsException() raise exceptions.invalidArgumentsException()
chatHelper.sendMessage( chatHelper.sendMessage(
"FokaBot", glob.BOT_NAME,
self.get_argument("to").encode().decode("ASCII", "ignore"), self.get_argument("to").encode().decode("ASCII", "ignore"),
self.get_argument("msg").encode().decode("ASCII", "ignore") self.get_argument("msg").encode().decode("ASCII", "ignore")
) )

View File

@ -177,7 +177,7 @@ def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
# Redirect !report to FokaBot # Redirect !report to FokaBot
if message.startswith("!report"): if message.startswith("!report"):
to = "FokaBot" to = glob.BOT_NAME
# Determine internal name if needed # Determine internal name if needed
# (toclient is used clientwise for #multiplayer and #spectator channels) # (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() # raise exceptions.userTournamentException()
# Make sure the recipient is not restricted or we are FokaBot # 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() raise exceptions.userRestrictedException()
# TODO: Make sure the recipient has not disabled PMs for non-friends or he's our friend # 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() token.spamProtection()
# Fokabot message # 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) fokaMessage = fokabot.fokabotResponse(token.username, to, message)
if fokaMessage: 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) # File and discord logs (public chat only)
if to.startswith("#") and not (message.startswith("\x01ACTION is playing") and to.startswith("#spect_")): if to.startswith("#") and not (message.startswith("\x01ACTION is playing") and to.startswith("#spect_")):

View File

@ -17,6 +17,7 @@ def connect():
:return: :return:
""" """
glob.BOT_NAME = userUtils.getUsername(999)
token = glob.tokens.addToken(999) token = glob.tokens.addToken(999)
token.actionID = actions.IDLE token.actionID = actions.IDLE
glob.streams.broadcast("main", serverPackets.userPanel(999)) glob.streams.broadcast("main", serverPackets.userPanel(999))

View File

@ -18,6 +18,7 @@ except:
VERSION = "Unknown" VERSION = "Unknown"
DATADOG_PREFIX = "peppy" DATADOG_PREFIX = "peppy"
BOT_NAME = "FokaBot"
application = None application = None
db = None db = None
redis = None redis = None

View File

@ -433,7 +433,7 @@ class match:
# saying that the match has completed. # saying that the match has completed.
chanName = "#multi_{}".format(self.matchID) chanName = "#multi_{}".format(self.matchID)
if self.isTourney and (chanName in glob.channels.channels): 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): def resetSlots(self):
for i in range(0,16): for i in range(0,16):
@ -665,7 +665,7 @@ class match:
# FokaBot is too busy # FokaBot is too busy
if to == 999: 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 # Send message
message = "Come join my multiplayer match: \"[osump://{}/{} {}]\"".format(self.matchID, self.matchPassword.replace(" ", "_"), self.matchName) message = "Come join my multiplayer match: \"[osump://{}/{} {}]\"".format(self.matchID, self.matchPassword.replace(" ", "_"), self.matchName)
@ -855,7 +855,7 @@ class match:
if totalUsers == 0: if totalUsers == 0:
message = "The match is now empty." message = "The match is now empty."
chat.sendMessage("FokaBot", chanName, message) chat.sendMessage(glob.BOT_NAME, chanName, message)
def __enter__(self): def __enter__(self):
# 🌚🌚🌚🌚🌚 # 🌚🌚🌚🌚🌚

View File

@ -487,7 +487,7 @@ class token:
:return: :return:
""" """
self.restricted = True 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): def resetRestricted(self):
""" """
@ -496,7 +496,7 @@ class token:
:return: :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): def joinStream(self, name):
""" """

2
pep.py
View File

@ -156,7 +156,7 @@ if __name__ == "__main__":
raise raise
# Start fokabot # Start fokabot
consoleHelper.printNoNl("> Connecting FokaBot... ") consoleHelper.printNoNl("> Connecting bot... ")
fokabot.connect() fokabot.connect()
consoleHelper.printDone() consoleHelper.printDone()