.BANCHO. Silences are now logged in RAP and on discord

This commit is contained in:
Nyo 2016-06-07 23:19:45 +02:00
parent ef35697772
commit e11ae27b36
4 changed files with 46 additions and 13 deletions

View File

@ -143,6 +143,7 @@ def silence(fro, chan, message):
# Get target user ID
targetUserID = userHelper.getID(target)
userID = userHelper.getID(fro)
# Make sure the user exists
if targetUserID == False:
@ -167,11 +168,14 @@ def silence(fro, chan, message):
# Send silence packet to target if he's connected
targetToken = glob.tokens.getTokenFromUsername(target)
if targetToken != None:
targetToken.silence(silenceTime, reason)
# user online, silence both in db and with packet
targetToken.silence(silenceTime, reason, userID)
else:
# User offline, silence user only in db
userHelper.silence(targetUserID, int(time.time())+silenceTime, reason, userID)
# Log message
msg = "{} has been silenced for the following reason: {}".format(target, reason)
discordBotHelper.sendConfidential(msg)
return msg
def removeSilence(fro, chan, message):
@ -182,16 +186,18 @@ def removeSilence(fro, chan, message):
# Make sure the user exists
targetUserID = userHelper.getID(target)
userID = userHelper.getID(fro)
if targetUserID == False:
return "{}: user not found".format(target)
# Reset user silence time and reason in db
userHelper.silence(targetUserID, 0, "")
# Send new silence end packet to user if he's online
targetToken = glob.tokens.getTokenFromUsername(target)
if targetToken != None:
targetToken.enqueue(serverPackets.silenceEndTime(0))
# User online, remove silence both in db and with packet
targetToken.silence(0, "", userID)
else:
# user offline, remove islene ofnlt from db
userHelper.silence(targetUserID, 0, "", userID)
return "{}'s silence reset".format(target)

View File

@ -3,6 +3,8 @@ from helpers import discordBotHelper
from helpers import generalFunctions
from helpers.systemHelper import runningUnderUnix
from objects import glob
from helpers import userHelper
import time
ENDL = "\n" if runningUnderUnix() else "\r\n"
@ -114,3 +116,17 @@ def pm(message):
message -- chat message
"""
logMessage(message, "CHAT", bcolors.BLUE, of="chatlog_private.txt")
def rap(userID, message, discord=False, through="FokaBot"):
"""
Log a private message to Admin logs
userID -- userID of who made the action
message -- message without subject (eg: "is a meme" becomes "user is a meme")
discord -- if True, send message to discord
through -- "through" thing string. Optional. Default: "FokaBot"
"""
glob.db.execute("INSERT INTO rap_logs (id, userid, text, datetime, through) VALUES (NULL, %s, %s, %s, %s)", [userID, message, int(time.time()), through])
if discord == True:
username = userHelper.getUsername(userID)
logMessage("{} {}".format(username, message), discord=True)

View File

@ -2,6 +2,8 @@ from helpers import passwordHelper
from constants import gameModes
from helpers import generalFunctions
from objects import glob
from helpers import logHelper as log
import time
def getID(username):
"""
@ -98,7 +100,8 @@ def getSilenceEnd(userID):
return glob.db.fetch("SELECT silence_end FROM users WHERE id = %s", [userID])["silence_end"]
def silence(userID, silenceEndTime, silenceReason):
def silence(userID, silenceEndTime, silenceReason, author = 999):
# TODO: user seconds insteaf od silenceEndTime
"""
Set userID's **ABSOLUTE** silence end UNIX time
Remember to add time.time() to the silence length
@ -106,10 +109,20 @@ def silence(userID, silenceEndTime, silenceReason):
userID -- userID
silenceEndtime -- UNIX time when the silence ends
silenceReason -- Silence reason shown on website
author -- userID of who silenced the user. Default: 999
"""
# db qurey
glob.db.execute("UPDATE users SET silence_end = %s, silence_reason = %s WHERE id = %s", [silenceEndTime, silenceReason, userID])
# Loh
seconds = silenceEndTime-int(time.time())
targetUsername = getUsername(userID)
# TODO: exists check im drunk rn i need to sleep (stampa piede ubriaco confirmed)
if seconds > 0:
log.rap(author, "has silenced {} for {} seconds for the following reason: \"{}\"".format(targetUsername, seconds, silenceReason), True)
else:
log.rap(author, "has removed {}'s silence".format(targetUsername), True)
def getRankedScore(userID, gameMode):
"""
Get userID's ranked score relative to gameMode

View File

@ -242,15 +242,16 @@ class token:
# Logout event
logoutEvent.handle(self, None)
def silence(self, seconds, reason):
def silence(self, seconds, reason, author = 999):
"""
Silences this user (both db and packet)
seconds -- silence length in seconds
reason -- silence reason
author -- userID of who has silenced the target. Optional. Default: 999 (fokabot)
"""
# Silence user in db
userHelper.silence(self.userID, int(time.time())+seconds, reason)
userHelper.silence(self.userID, int(time.time())+seconds, reason, author)
# Send silence packet to target
self.enqueue(serverPackets.silenceEndTime(seconds))
@ -258,9 +259,6 @@ class token:
# Send silenced packet to everyone else
glob.tokens.enqueueAll(serverPackets.userSilenced(self.userID))
# Log
log.info("{} has been silenced for {} seconds for the following reason: {}".format(self.username, seconds, reason), True)
def spamProtection(self, increaseSpamRate = True):
"""
Silences the user if is spamming.