.HIDE. .BANCHO. Add public (discord) and private (file) chat logging
This commit is contained in:
@@ -6,6 +6,7 @@ from objects import glob
|
||||
from objects import fokabot
|
||||
from constants import exceptions
|
||||
from constants import messageTemplates
|
||||
from time import gmtime, strftime
|
||||
|
||||
def handle(userToken, packetData):
|
||||
"""
|
||||
@@ -47,6 +48,10 @@ def handle(userToken, packetData):
|
||||
|
||||
# Console output
|
||||
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:
|
||||
# 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)
|
||||
|
@@ -5,6 +5,7 @@ from objects import fokabot
|
||||
from helpers import consoleHelper
|
||||
from constants import bcolors
|
||||
from constants import serverPackets
|
||||
from helpers import discordBotHelper
|
||||
|
||||
def handle(userToken, packetData):
|
||||
"""
|
||||
@@ -15,7 +16,7 @@ def handle(userToken, packetData):
|
||||
"""
|
||||
|
||||
try:
|
||||
# Get uesrToken data
|
||||
# Get userToken data
|
||||
userID = userToken.userID
|
||||
username = userToken.username
|
||||
userRank = userToken.rank
|
||||
@@ -99,7 +100,10 @@ def handle(userToken, packetData):
|
||||
consoleHelper.printColored("> FokaBot@{}: {}".format(packetData["to"], str(fokaMessage.encode("UTF-8"))), bcolors.PINK)
|
||||
|
||||
# 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:
|
||||
consoleHelper.printColored("[!] {} tried to send a message to a channel that is in moderated mode ({})".format(username, packetData["to"]), bcolors.RED)
|
||||
except exceptions.channelUnknownException:
|
||||
|
Reference in New Issue
Block a user