.HIDE. .BANCHO. Add public (discord) and private (file) chat logging
This commit is contained in:
parent
0e1c8696ba
commit
035c934d99
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
**/__pycache__
|
**/__pycache__
|
||||||
config.ini
|
config.ini
|
||||||
|
.data
|
||||||
|
|
|
@ -6,6 +6,7 @@ from objects import glob
|
||||||
from objects import fokabot
|
from objects import fokabot
|
||||||
from constants import exceptions
|
from constants import exceptions
|
||||||
from constants import messageTemplates
|
from constants import messageTemplates
|
||||||
|
from time import gmtime, strftime
|
||||||
|
|
||||||
def handle(userToken, packetData):
|
def handle(userToken, packetData):
|
||||||
"""
|
"""
|
||||||
|
@ -47,6 +48,10 @@ def handle(userToken, packetData):
|
||||||
|
|
||||||
# Console output
|
# Console output
|
||||||
consoleHelper.printColored("> {}>{}: {}".format(username, packetData["to"], packetData["message"]), bcolors.PINK)
|
consoleHelper.printColored("> {}>{}: {}".format(username, packetData["to"], packetData["message"]), bcolors.PINK)
|
||||||
|
|
||||||
|
# Log to file
|
||||||
|
with open(".data/chatlog_private.txt", "a") as f:
|
||||||
|
f.write("[{date}] {fro} -> {to}: {message}\n".format(date=strftime("%Y-%m-%d %H:%M:%S", gmtime()), fro=username, to=packetData["to"], message=str(packetData["message"].encode("utf-8"))[2:-1]))
|
||||||
except exceptions.tokenNotFoundException:
|
except exceptions.tokenNotFoundException:
|
||||||
# Token not found, user disconnected
|
# Token not found, user disconnected
|
||||||
consoleHelper.printColored("[!] {} tried to send a message to {}, but their token couldn't be found".format(username, packetData["to"]), bcolors.RED)
|
consoleHelper.printColored("[!] {} tried to send a message to {}, but their token couldn't be found".format(username, packetData["to"]), bcolors.RED)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from objects import fokabot
|
||||||
from helpers import consoleHelper
|
from helpers import consoleHelper
|
||||||
from constants import bcolors
|
from constants import bcolors
|
||||||
from constants import serverPackets
|
from constants import serverPackets
|
||||||
|
from helpers import discordBotHelper
|
||||||
|
|
||||||
def handle(userToken, packetData):
|
def handle(userToken, packetData):
|
||||||
"""
|
"""
|
||||||
|
@ -15,7 +16,7 @@ def handle(userToken, packetData):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get uesrToken data
|
# Get userToken data
|
||||||
userID = userToken.userID
|
userID = userToken.userID
|
||||||
username = userToken.username
|
username = userToken.username
|
||||||
userRank = userToken.rank
|
userRank = userToken.rank
|
||||||
|
@ -99,7 +100,10 @@ def handle(userToken, packetData):
|
||||||
consoleHelper.printColored("> FokaBot@{}: {}".format(packetData["to"], str(fokaMessage.encode("UTF-8"))), bcolors.PINK)
|
consoleHelper.printColored("> FokaBot@{}: {}".format(packetData["to"], str(fokaMessage.encode("UTF-8"))), bcolors.PINK)
|
||||||
|
|
||||||
# Console output
|
# Console output
|
||||||
consoleHelper.printColored("> {}@{}: {}".format(username, packetData["to"], str(packetData["message"].encode("UTF-8"))), bcolors.PINK)
|
consoleHelper.printColored("> {}@{}: {}".format(username, packetData["to"], str(packetData["message"].encode("utf-8"))), bcolors.PINK)
|
||||||
|
|
||||||
|
# Discord/file log
|
||||||
|
discordBotHelper.sendChatlog("**{fro}{type}{to}:** {message}".format(fro=username, type="@" if packetData["to"].startswith("#") else ">", to=packetData["to"], message=str(packetData["message"].encode("utf-8"))[2:-1]))
|
||||||
except exceptions.channelModeratedException:
|
except exceptions.channelModeratedException:
|
||||||
consoleHelper.printColored("[!] {} tried to send a message to a channel that is in moderated mode ({})".format(username, packetData["to"]), bcolors.RED)
|
consoleHelper.printColored("[!] {} tried to send a message to a channel that is in moderated mode ({})".format(username, packetData["to"]), bcolors.RED)
|
||||||
except exceptions.channelUnknownException:
|
except exceptions.channelUnknownException:
|
||||||
|
|
|
@ -63,6 +63,9 @@ class config:
|
||||||
self.config.get("flask","debug")
|
self.config.get("flask","debug")
|
||||||
self.config.get("flask","logger")
|
self.config.get("flask","logger")
|
||||||
|
|
||||||
|
self.config.get("discord","enable")
|
||||||
|
self.config.get("discord","boturl")
|
||||||
|
|
||||||
self.config.get("ci","key")
|
self.config.get("ci","key")
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
|
@ -102,6 +105,10 @@ class config:
|
||||||
self.config.add_section("ci")
|
self.config.add_section("ci")
|
||||||
self.config.set("ci", "key", "changeme")
|
self.config.set("ci", "key", "changeme")
|
||||||
|
|
||||||
|
self.config.add_section("discord")
|
||||||
|
self.config.set("discord", "enable", "False")
|
||||||
|
self.config.set("discord", "boturl", "")
|
||||||
|
|
||||||
# Write ini to file and close
|
# Write ini to file and close
|
||||||
self.config.write(f)
|
self.config.write(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
51
helpers/discordBotHelper.py
Normal file
51
helpers/discordBotHelper.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import requests
|
||||||
|
from objects import glob
|
||||||
|
from helpers import generalFunctions
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
def sendDiscordMessage(channel, message):
|
||||||
|
"""
|
||||||
|
Send a message to a discord server.
|
||||||
|
This is used with ripple's schiavobot.
|
||||||
|
|
||||||
|
channel -- bunk, staff or general
|
||||||
|
message -- message to send
|
||||||
|
"""
|
||||||
|
if generalFunctions.stringToBool(glob.conf.config["discord"]["enable"]) == True:
|
||||||
|
requests.get("{}/{}?{}".format(glob.conf.config["discord"]["boturl"], channel, urlencode({ "message": message })))
|
||||||
|
|
||||||
|
|
||||||
|
def sendConfidential(message):
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
def sendStaff(message):
|
||||||
|
"""
|
||||||
|
Send a message to #staff
|
||||||
|
|
||||||
|
message -- message to send
|
||||||
|
"""
|
||||||
|
sendDiscordMessage("staff", message)
|
||||||
|
|
||||||
|
|
||||||
|
def sendGeneral(message):
|
||||||
|
"""
|
||||||
|
Send a message to #general
|
||||||
|
|
||||||
|
message -- message to send
|
||||||
|
"""
|
||||||
|
sendDiscordMessage("general", message)
|
13
pep.py
13
pep.py
|
@ -3,6 +3,7 @@ import logging
|
||||||
import sys
|
import sys
|
||||||
import flask
|
import flask
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
# Tornado server
|
# Tornado server
|
||||||
from tornado.wsgi import WSGIContainer
|
from tornado.wsgi import WSGIContainer
|
||||||
|
@ -14,6 +15,7 @@ from constants import bcolors
|
||||||
from constants import packetIDs
|
from constants import packetIDs
|
||||||
from constants import serverPackets
|
from constants import serverPackets
|
||||||
from helpers import configHelper
|
from helpers import configHelper
|
||||||
|
from helpers import discordBotHelper
|
||||||
from constants import exceptions
|
from constants import exceptions
|
||||||
from objects import glob
|
from objects import glob
|
||||||
from objects import fokabot
|
from objects import fokabot
|
||||||
|
@ -289,6 +291,14 @@ if __name__ == "__main__":
|
||||||
consoleHelper.printColored("[!] Error while loading bancho_settings. Please make sure the table in DB has all the required rows", bcolors.RED)
|
consoleHelper.printColored("[!] Error while loading bancho_settings. Please make sure the table in DB has all the required rows", bcolors.RED)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
# Create data folder if needed
|
||||||
|
consoleHelper.printNoNl("> Checking folders... ")
|
||||||
|
paths = [".data"]
|
||||||
|
for i in paths:
|
||||||
|
if not os.path.exists(i):
|
||||||
|
os.makedirs(i, 0o770)
|
||||||
|
consoleHelper.printDone()
|
||||||
|
|
||||||
# Initialize chat channels
|
# Initialize chat channels
|
||||||
consoleHelper.printNoNl("> Initializing chat channels... ")
|
consoleHelper.printNoNl("> Initializing chat channels... ")
|
||||||
glob.channels.loadChannels()
|
glob.channels.loadChannels()
|
||||||
|
@ -321,6 +331,9 @@ if __name__ == "__main__":
|
||||||
serverOutputPackets = generalFunctions.stringToBool(glob.conf.config["server"]["outputpackets"])
|
serverOutputPackets = generalFunctions.stringToBool(glob.conf.config["server"]["outputpackets"])
|
||||||
serverOutputRequestTime = generalFunctions.stringToBool(glob.conf.config["server"]["outputrequesttime"])
|
serverOutputRequestTime = generalFunctions.stringToBool(glob.conf.config["server"]["outputrequesttime"])
|
||||||
|
|
||||||
|
# Send server start message
|
||||||
|
discordBotHelper.sendConfidential("w00t p00t! (pep.py started)")
|
||||||
|
|
||||||
# Run server sanic way
|
# Run server sanic way
|
||||||
if serverName == "tornado":
|
if serverName == "tornado":
|
||||||
# Tornado server
|
# Tornado server
|
||||||
|
|
Loading…
Reference in New Issue
Block a user