.BANCHO. Add !report command
This commit is contained in:
@@ -95,4 +95,10 @@ class userAlreadyInChannelException(Exception):
|
||||
pass
|
||||
|
||||
class userNotInChannelException(Exception):
|
||||
pass
|
||||
|
||||
class missingReportInfoException(Exception):
|
||||
pass
|
||||
|
||||
class invalidUserException(Exception):
|
||||
pass
|
@@ -1,7 +1,9 @@
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
|
||||
import requests
|
||||
import time
|
||||
|
||||
from common import generalUtils
|
||||
from common.constants import mods
|
||||
@@ -14,6 +16,7 @@ from constants import serverPackets
|
||||
from helpers import systemHelper
|
||||
from objects import fokabot
|
||||
from objects import glob
|
||||
from helpers import chatHelper as chat
|
||||
|
||||
"""
|
||||
Commands callbacks
|
||||
@@ -694,6 +697,64 @@ def updateBeatmap(fro, chan, message):
|
||||
except:
|
||||
return False
|
||||
|
||||
def report(fro, chan, message):
|
||||
msg = ""
|
||||
try:
|
||||
# TODO: Rate limit
|
||||
# Regex on message
|
||||
reportRegex = re.compile("^(.+) \((.+)\)\:(?: )?(.+)?$")
|
||||
result = reportRegex.search(" ".join(message))
|
||||
|
||||
# Make sure the message matches the regex
|
||||
if result is None:
|
||||
raise exceptions.invalidArgumentsException()
|
||||
|
||||
# Get username, report reason and report info
|
||||
target, reason, additionalInfo = result.groups()
|
||||
target = chat.fixUsernameForBancho(target)
|
||||
|
||||
# Make sure the target is not foka
|
||||
if target.lower() == "fokabot":
|
||||
raise exceptions.invalidUserException()
|
||||
|
||||
# Make sure the user exists
|
||||
targetID = userUtils.getID(target)
|
||||
if targetID == 0:
|
||||
raise exceptions.userNotFoundException()
|
||||
|
||||
# Make sure that the user has specified additional info if report reason is 'Other'
|
||||
if reason.lower() == "other" and additionalInfo is None:
|
||||
raise exceptions.missingReportInfoException()
|
||||
|
||||
# Get the token if possible
|
||||
chatlog = ""
|
||||
token = glob.tokens.getTokenFromUsername(target)
|
||||
if token is not None:
|
||||
chatlog = token.getMessagesBufferString()
|
||||
|
||||
# Everything is fine, submit report
|
||||
glob.db.execute("INSERT INTO reports (id, from_uid, to_uid, reason, chatlog, time) VALUES (NULL, %s, %s, %s, %s, %s)", [userUtils.getID(fro), targetID, "{reason} - ingame {info}".format(reason=reason, info="({})".format(additionalInfo) if additionalInfo is not None else ""), chatlog, int(time.time())])
|
||||
msg = "You've reported {target} for {reason}{info}. A Community Manager will check your report as soon as possible. Every !report message you may see in chat wasn't sent to anyone, so nobody in chat, but admins, know about your report. Thank you for reporting!".format(target=target, reason=reason, info="" if additionalInfo is None else " (" + 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
|
||||
chat.sendMessage("FokaBot", "#admin", adminMsg)
|
||||
log.warning(adminMsg, discord="cm")
|
||||
except exceptions.invalidUserException:
|
||||
msg = "You can't report. I won't forget what you've tried to do. Watch out."
|
||||
except exceptions.invalidArgumentsException:
|
||||
msg = "Invalid report command syntax. To report an user, click on it and select 'Report user'."
|
||||
except exceptions.userNotFoundException:
|
||||
msg = "The user you've tried to report doesn't exist."
|
||||
except exceptions.missingReportInfoException:
|
||||
msg = "Please specify the reason of your report."
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
if msg != "":
|
||||
chat.sendMessage("FokaBot", fro, msg)
|
||||
return False
|
||||
|
||||
"""
|
||||
Commands list
|
||||
|
||||
@@ -713,7 +774,7 @@ commands = [
|
||||
"callback": faq
|
||||
}, {
|
||||
"trigger": "!report",
|
||||
"response": "Report command isn't here yet :c"
|
||||
"callback": report
|
||||
}, {
|
||||
"trigger": "!help",
|
||||
"response": "Click (here)[https://ripple.moe/index.php?p=16&id=4] for FokaBot's full command list"
|
||||
|
Reference in New Issue
Block a user