diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 8e6c911..a12b032 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -12,6 +12,7 @@ from constants import mods from helpers import generalFunctions from helpers import consoleHelper +from helpers import discordBotHelper from constants import bcolors """ @@ -176,7 +177,10 @@ def silence(fro, chan, message): if targetToken != None: targetToken.enqueue(serverPackets.silenceEndTime(silenceTime)) - return "{} has been silenced for the following reason: {}".format(target, reason) + # Log message + msg = "{} has been silenced for the following reason: {}".format(target, reason) + discordBotHelper.sendConfidential(msg) + return msg def removeSilence(fro, chan, message): # Get parameters diff --git a/events/loginEvent.py b/events/loginEvent.py index a3bb3b6..a25f05c 100644 --- a/events/loginEvent.py +++ b/events/loginEvent.py @@ -12,6 +12,7 @@ from events import channelJoinEvent import sys import traceback from helpers import requestHelper +from helpers import discordBotHelper def handle(tornadoRequest): # Data to return @@ -183,4 +184,8 @@ def handle(tornadoRequest): if err == True: consoleHelper.printColored("> {}'s login failed".format(loginData[0]), bcolors.YELLOW) + # Discord message + discordBotHelper.sendConfidential("Bancho login request from {} for user {} ({})".format(requestIP, loginData[0], "failed" if err == True else "success")) + + # Return token string and data return (responseTokenString, responseData) diff --git a/handlers/mainHandler.py b/handlers/mainHandler.py index f4a9613..04f7399 100644 --- a/handlers/mainHandler.py +++ b/handlers/mainHandler.py @@ -81,7 +81,7 @@ class handler(requestHelper.asyncRequestHandler): # Token exists, get its object and lock it userToken = glob.tokens.tokens[requestTokenString] userToken.lock.acquire() - consoleHelper.printColored("[{}] locked".format(userToken.token), bcolors.YELLOW) + #consoleHelper.printColored("[{}] locked".format(userToken.token), bcolors.YELLOW) # Keep reading packets until everything has been read while pos < len(requestData): @@ -171,7 +171,7 @@ class handler(requestHelper.asyncRequestHandler): finally: # Unlock token if userToken != None: - consoleHelper.printColored("[{}] unlocked".format(userToken.token), bcolors.GREEN) + #consoleHelper.printColored("[{}] unlocked".format(userToken.token), bcolors.GREEN) userToken.lock.release() if glob.requestTime == True: @@ -194,32 +194,38 @@ class handler(requestHelper.asyncRequestHandler): self.add_header("Content-Encoding", "gzip") self.write(gzip.compress(responseData, 6)) except: - msg = "**asyncppytornadovroom error** *(aka test server, ignore this)*\nUnhandled exception in mainHandler:\n```\n{}\n{}\n```".format(sys.exc_info(), traceback.format_exc()) + msg = "Unhandled exception in mainHandler:\n```\n{}\n{}\n```".format(sys.exc_info(), traceback.format_exc()) consoleHelper.printColored("[!] {}".format(msg), bcolors.RED) - discordBotHelper.sendConfidential(msg) + discordBotHelper.sendConfidential(msg, True) finally: - self.finish() + try: + if not self._finished: + self.finish() + except: + pass def asyncGet(self): - html = "MA MAURO ESISTE?
"
-		html += "           _                 __
" - html += " (_) / /
" - html += " ______ __ ____ ____ / /____
" - html += " / ___/ / _ \\/ _ \\/ / _ \\
" - html += " / / / / /_) / /_) / / ____/
" - html += "/__/ /__/ .___/ .___/__/ \\_____/
" - html += " / / / /
" - html += " /__/ /__/
" - html += "PYTHON > ALL VERSION

" - html += "
" - html += " .. o .
" - html += " o.o o . o
" - html += " oo...
" - html += " __[]__
" - html += " phwr--> _\\:D/_/o_o_o_|__ u wot m8
" - html += " \\\"\"\"\"\"\"\"\"\"\"\"\"\"\"/
" - html += " \\ . .. .. . /
" - html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
" - html += "

reverse engineering a protocol impossible to reverse engineer since always
we are actually reverse engineering bancho successfully. for the third time.
" - self.write(html) - self.finish() + try: + html = "MA MAURO ESISTE?
"
+			html += "           _                 __
" + html += " (_) / /
" + html += " ______ __ ____ ____ / /____
" + html += " / ___/ / _ \\/ _ \\/ / _ \\
" + html += " / / / / /_) / /_) / / ____/
" + html += "/__/ /__/ .___/ .___/__/ \\_____/
" + html += " / / / /
" + html += " /__/ /__/
" + html += "PYTHON > ALL VERSION

" + html += "
" + html += " .. o .
" + html += " o.o o . o
" + html += " oo...
" + html += " __[]__
" + html += " phwr--> _\\:D/_/o_o_o_|__ u wot m8
" + html += " \\\"\"\"\"\"\"\"\"\"\"\"\"\"\"/
" + html += " \\ . .. .. . /
" + html += "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
" + html += "

reverse engineering a protocol impossible to reverse engineer since always
we are actually reverse engineering bancho successfully. for the third time.
" + self.write(html) + finally: + self.finish() diff --git a/helpers/configHelper.py b/helpers/configHelper.py index fba87e1..8e46895 100644 --- a/helpers/configHelper.py +++ b/helpers/configHelper.py @@ -58,6 +58,7 @@ class config: self.config.get("discord","enable") self.config.get("discord","boturl") + self.config.get("discord","devgroup") self.config.get("ci","key") return True @@ -95,6 +96,7 @@ class config: self.config.add_section("discord") self.config.set("discord", "enable", "False") self.config.set("discord", "boturl", "") + self.config.set("discord", "devgroup", "") # Write ini to file and close self.config.write(f) diff --git a/helpers/discordBotHelper.py b/helpers/discordBotHelper.py index 33ecd0a..491d143 100644 --- a/helpers/discordBotHelper.py +++ b/helpers/discordBotHelper.py @@ -2,35 +2,36 @@ import requests from objects import glob from helpers import generalFunctions from urllib.parse import urlencode +from helpers import consoleHelper +from constants import bcolors -def sendDiscordMessage(channel, message): +def sendDiscordMessage(channel, message, alertDev = False, prefix = "**pep.py**"): """ Send a message to a discord server. This is used with ripple's schiavobot. channel -- bunk, staff or general message -- message to send + alertDev -- if True, hl developers group + prefix -- string to prepend to message """ - if generalFunctions.stringToBool(glob.conf.config["discord"]["enable"]) == True: - requests.get("{}/{}?{}".format(glob.conf.config["discord"]["boturl"], channel, urlencode({ "message": message }))) + if glob.discord == True: + for _ in range(0,20): + try: + finalMsg = "{prefix} {message}".format(prefix=prefix, message=message) if alertDev == False else "{prefix} {hl} - {message}".format(prefix=prefix, hl=glob.conf.config["discord"]["devgroup"], message=message) + requests.get("{}/{}?{}".format(glob.conf.config["discord"]["boturl"], channel, urlencode({ "message": finalMsg }))) + break + except: + continue -def sendConfidential(message): +def sendConfidential(message, alertDev = False): """ Send a message to #bunker message -- message to send """ - sendDiscordMessage("bunk", message) - - -def sendChatlog(message): - """ - Send a message to #chatlog - - message -- message to send - """ - sendDiscordMessage("chatlog", message) + sendDiscordMessage("bunk", message, alertDev) def sendStaff(message): @@ -49,3 +50,12 @@ def sendGeneral(message): message -- message to send """ sendDiscordMessage("general", message) + + +def sendChatlog(message): + """ + Send a message to #chatlog + + message -- message to send + """ + sendDiscordMessage("chatlog", message, prefix="") diff --git a/objects/glob.py b/objects/glob.py index 40c5f95..3cec445 100644 --- a/objects/glob.py +++ b/objects/glob.py @@ -3,7 +3,6 @@ from objects import tokenList from objects import channelList from objects import matchList -import threading VERSION = "1.2" @@ -13,7 +12,7 @@ banchoConf = None tokens = tokenList.tokenList() channels = channelList.channelList() matches = matchList.matchList() -memes = True restarting = False pool = None requestTime = False +discord = False diff --git a/pep.py b/pep.py index bb15258..a2122f4 100644 --- a/pep.py +++ b/pep.py @@ -176,15 +176,20 @@ if __name__ == "__main__": raise # Localize warning - if(generalFunctions.stringToBool(glob.conf.config["server"]["localizeusers"]) == False): + if generalFunctions.stringToBool(glob.conf.config["server"]["localizeusers"]) == False: consoleHelper.printColored("[!] Warning! users localization is disabled!", bcolors.YELLOW) + # Discord + glob.discord = generalFunctions.stringToBool(glob.conf.config["discord"]["enable"]) + if glob.discord == False: + consoleHelper.printColored("[!] Discord logging is disabled!", bcolors.YELLOW) + # Get server parameters from config.ini serverPort = int(glob.conf.config["server"]["port"]) glob.requestTime = generalFunctions.stringToBool(glob.conf.config["server"]["outputrequesttime"]) # Server start message and console output - discordBotHelper.sendConfidential("**asyncppytornadovroom** Server started!") + discordBotHelper.sendConfidential("Server started!") consoleHelper.printColored("> Tornado listening for clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN) # Start tornado