mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
Merge pull request #1162 from grilledham/discord_report_player_time
Add Player online time to discord report/jail embeds.
This commit is contained in:
commit
902fe0d81c
@ -153,34 +153,38 @@ local function send_report_to_discord(reporting_player, reported_player, message
|
|||||||
local server_id = Server.get_server_id()
|
local server_id = Server.get_server_id()
|
||||||
local server_name = Server.get_server_name()
|
local server_name = Server.get_server_name()
|
||||||
|
|
||||||
local text = {}
|
local text = {'**'}
|
||||||
if reporting_player and reporting_player.valid then
|
if reporting_player and reporting_player.valid then
|
||||||
text[#text + 1] = reporting_player.name
|
text[#text + 1] = Utils.sanitise_string_for_discord(reporting_player.name)
|
||||||
else
|
else
|
||||||
text[#text + 1] = '<script>'
|
text[#text + 1] = '<script>'
|
||||||
end
|
end
|
||||||
|
|
||||||
text[#text + 1] = ' reported '
|
text[#text + 1] = ' reported '
|
||||||
text[#text + 1] = reported_player.name
|
text[#text + 1] = Utils.sanitise_string_for_discord(reported_player.name)
|
||||||
|
text[#text + 1] = '**\\n'
|
||||||
|
|
||||||
if server_id ~= '' then
|
if server_id ~= '' then
|
||||||
text[#text + 1] = ' s'
|
text[#text + 1] = 'Server: s'
|
||||||
text[#text + 1] = server_id
|
text[#text + 1] = Utils.sanitise_string_for_discord(server_id)
|
||||||
text[#text + 1] = '-'
|
text[#text + 1] = ' - '
|
||||||
text[#text + 1] = server_name
|
text[#text + 1] = Utils.sanitise_string_for_discord(server_name)
|
||||||
|
text[#text + 1] = '\\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
text[#text + 1] = ' Game time '
|
text[#text + 1] = ' Game time: '
|
||||||
text[#text + 1] = Utils.format_time(game.tick)
|
text[#text + 1] = Utils.format_time(game.tick)
|
||||||
text[#text + 1] = ':\\n\\n'
|
text[#text + 1] = '\\nPlayer online time: '
|
||||||
text[#text + 1] = message
|
text[#text + 1] = Utils.format_time(reported_player.online_time)
|
||||||
|
text[#text + 1] = '\\nMessage: '
|
||||||
|
text[#text + 1] = Utils.sanitise_string_for_discord(message)
|
||||||
|
|
||||||
text = table.concat(text)
|
text = table.concat(text)
|
||||||
|
|
||||||
Server.to_discord_named_embed(helpdesk_channel, text)
|
Server.to_discord_named_embed_raw(helpdesk_channel, text)
|
||||||
Server.to_discord_named_raw(helpdesk_channel, moderator_role_mention)
|
Server.to_discord_named_raw(helpdesk_channel, moderator_role_mention)
|
||||||
|
|
||||||
Server.to_discord_named_embed(moderation_log_channel, text)
|
Server.to_discord_named_embed_raw(moderation_log_channel, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Module.report(reporting_player, reported_player, message)
|
function Module.report(reporting_player, reported_player, message)
|
||||||
@ -221,20 +225,27 @@ local function send_jail_to_discord(target_player, player)
|
|||||||
local server_id = Server.get_server_id()
|
local server_id = Server.get_server_id()
|
||||||
local server_name = Server.get_server_name()
|
local server_name = Server.get_server_name()
|
||||||
|
|
||||||
local text = {target_player.name, ' has been jailed by ', player.name}
|
local text = {'**'}
|
||||||
|
text[#text+ 1] = Utils.sanitise_string_for_discord(player.name)
|
||||||
|
text[#text+ 1] = ' has jailed '
|
||||||
|
text[#text+ 1] = Utils.sanitise_string_for_discord(target_player.name)
|
||||||
|
text[#text+ 1] = '**\\n'
|
||||||
|
|
||||||
if server_id ~= '' then
|
if server_id ~= '' then
|
||||||
text[#text + 1] = ' s'
|
text[#text + 1] = 'Server: s'
|
||||||
text[#text + 1] = server_id
|
text[#text + 1] = Utils.sanitise_string_for_discord(server_id)
|
||||||
text[#text + 1] = '-'
|
text[#text + 1] = ' - '
|
||||||
text[#text + 1] = server_name
|
text[#text + 1] = Utils.sanitise_string_for_discord(server_name)
|
||||||
|
text[#text + 1] = '\\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
text[#text + 1] = ' Game time '
|
text[#text + 1] = 'Game time: '
|
||||||
text[#text + 1] = Utils.format_time(game.tick)
|
text[#text + 1] = Utils.format_time(game.tick)
|
||||||
|
text[#text + 1] = '\\nPlayer online time: '
|
||||||
|
text[#text + 1] = Utils.format_time(target_player.online_time)
|
||||||
|
|
||||||
local message = table.concat(text)
|
local message = table.concat(text)
|
||||||
Server.to_discord_named_embed(moderation_log_channel, message)
|
Server.to_discord_named_embed_raw(moderation_log_channel, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Places a target in jail
|
--- Places a target in jail
|
||||||
|
@ -256,6 +256,29 @@ function Module.validate_player(player_ident)
|
|||||||
return player, player.name, player.index
|
return player, player.name, player.index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local non_breaking_space = '' -- This is \u200B an invisible space charcater.
|
||||||
|
local sensitive_characters_map = {
|
||||||
|
['\\'] = '\\\\',
|
||||||
|
['*'] = '\\*',
|
||||||
|
['_'] = '\\_',
|
||||||
|
['~'] = '\\~',
|
||||||
|
['`'] = '\\`',
|
||||||
|
['|'] = '\\|',
|
||||||
|
['>'] = '\\>',
|
||||||
|
['@'] = '@' .. non_breaking_space
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Escapes markdown characters mentions. Intended to make it safe to send user input to discord.
|
||||||
|
-- @param message <string>
|
||||||
|
-- @return <string>
|
||||||
|
function Module.sanitise_string_for_discord(message)
|
||||||
|
for character, replace in pairs(sensitive_characters_map) do
|
||||||
|
message = string.gsub(message, character, replace)
|
||||||
|
end
|
||||||
|
|
||||||
|
return message
|
||||||
|
end
|
||||||
|
|
||||||
-- add utility functions that exist in base factorio/util
|
-- add utility functions that exist in base factorio/util
|
||||||
require 'util'
|
require 'util'
|
||||||
|
|
||||||
|
25
utils/core_tests.lua
Normal file
25
utils/core_tests.lua
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
local Declare = require 'utils.test.declare'
|
||||||
|
local Assert = require 'utils.test.assert'
|
||||||
|
local Core = require 'utils.core'
|
||||||
|
|
||||||
|
local non_breaking_space = '' -- This is \u200B an invisible space charcater.
|
||||||
|
|
||||||
|
Declare.module({'utils', 'Core'}, function()
|
||||||
|
Declare.module('sanitise_string_for_discord', function()
|
||||||
|
Declare.test('escapes markdown', function()
|
||||||
|
local actual = Core.sanitise_string_for_discord('**a**_b_~c~`d`|e|>f')
|
||||||
|
Assert.equal('\\*\\*a\\*\\*\\_b\\_\\~c\\~\\`d\\`\\|e\\|\\>f', actual)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- This test is making sure backslash '\' is escaped first, else there would be a different number of backslashes.
|
||||||
|
Declare.test('escapes backslash', function()
|
||||||
|
local actual = Core.sanitise_string_for_discord('\\*abc\\*')
|
||||||
|
Assert.equal('\\\\\\*abc\\\\\\*', actual)
|
||||||
|
end)
|
||||||
|
|
||||||
|
Declare.test('escapes mention', function()
|
||||||
|
local actual = Core.sanitise_string_for_discord('@grilledham')
|
||||||
|
Assert.equal('@' .. non_breaking_space .. 'grilledham', actual)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
Loading…
x
Reference in New Issue
Block a user