Skip to content

Commit

Permalink
Merge pull request #1125 from grilledham/reports-ping-channel
Browse files Browse the repository at this point in the history
Reports ping channel
  • Loading branch information
grilledham authored Dec 27, 2020
2 parents 2758b21 + 2f53b43 commit c35909c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
44 changes: 44 additions & 0 deletions features/report.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ local Command = require 'utils.command'
local Popup = require 'features.gui.popup'
local Color = require 'resources.color_presets'
local Event = require 'utils.event'
local Server = require 'features.server'
local Discord = require 'resources.discord'

local helpdesk_channel = Discord.channel_names.helpdesk
local moderation_log_channel = Discord.channel_names.moderation_log
local moderator_role_mention = Discord.role_mentions.moderator

local format = string.format

Expand Down Expand Up @@ -143,6 +149,29 @@ Module.show_reports = function(player)
draw_report(report_body, #reports)
end

local function send_report_to_discord(reporting_player, reported_player, message)
local text = {}
if reporting_player and reporting_player.valid then
text[#text + 1] = reporting_player.name
else
text[#text + 1] = '<script>'
end

text[#text + 1] = ' reported '
text[#text + 1] = reported_player.name
text[#text + 1] = ' - game time '
text[#text + 1] = Utils.format_time(game.tick)
text[#text + 1] = ':\\n\\n'
text[#text + 1] = message

text = table.concat(text)

Server.to_discord_named_embed(helpdesk_channel, text)
Server.to_discord_named_raw(helpdesk_channel, moderator_role_mention)

Server.to_discord_named_embed(moderation_log_channel, text)
end

function Module.report(reporting_player, reported_player, message)
local player_index
if reporting_player then
Expand All @@ -156,6 +185,8 @@ function Module.report(reporting_player, reported_player, message)
tick = game.tick
})

send_report_to_discord(reporting_player, reported_player, message)

local notified = false
for _, p in pairs(game.players) do
if p.admin and p.connected then
Expand All @@ -175,6 +206,17 @@ function Module.report(reporting_player, reported_player, message)
end
end

local function send_jail_to_discord(target_player, player)
local message = table.concat {
target_player.name,
' has been jailed by ',
player.name,
' - game time ',
Utils.format_time(game.tick)
}
Server.to_discord_named_embed(moderation_log_channel, message)
end

--- Places a target in jail
-- @param target_player <LuaPlayer> the target to jail
-- @param player <LuaPlayer|nil> the admin as LuaPlayer or server as nil
Expand Down Expand Up @@ -274,6 +316,8 @@ function Module.jail(target_player, player)

target_player.color = Color.white
target_player.chat_color = Color.white

send_jail_to_discord(target_player, player)
else
-- Let admin know it didn't work.
print(format('Something went wrong in the jailing of %s. You can still change their group via /permissions.',
Expand Down
9 changes: 5 additions & 4 deletions map_gen/maps/crash_site/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ local Core = require 'utils.core'
local Color = require 'resources.color_presets'
local Toast = require 'features.gui.toast'
local Utils = require 'utils.core'
local DiscordChannelNames = require 'resources.discord_channel_names'
local Discord = require 'resources.discord'
local set_timeout_in_ticks = Task.set_timeout_in_ticks
local ScoreTracker = require 'utils.score_tracker'

local map_promotion_channel = Discord.channel_names.map_promotion
local crash_site_role_mention = Discord.role_mentions.crash_site

local Public = {}

function Public.control(config)
Expand Down Expand Up @@ -86,9 +89,7 @@ function Public.control(config)
return
elseif state == 1 then
local time_string = Core.format_time(game.ticks_played)
local discord_crashsite_role = '<@&762441731194748958>' -- @crash_site
-- local discord_crashsite_role = '<@&593534612051984431>' -- @test
Server.to_discord_named_raw(DiscordChannelNames.map_promotion, discord_crashsite_role
Server.to_discord_named_raw(map_promotion_channel, crash_site_role_mention
.. ' **Crash Site has just restarted! Previous map lasted: ' .. time_string .. '!**')

local end_epoch = Server.get_current_time()
Expand Down
18 changes: 18 additions & 0 deletions resources/discord.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- Resources for use in interacting with discord.
return {
--- The names of the discord channels that can be referenced by name.
-- See features.server.to_discord_named
channel_names = {
bot_playground = 'bot-playground',
map_promotion = 'map-promotion',
moderation_log = 'moderation-log',
helpdesk = 'helpdesk'
},
--- The strings that mention the discord role.
-- Has to be used with features.server.to_discord_raw variants else the mention is sanitized server side.
role_mentions = {
test = '<@&593534612051984431>',
crash_site = '<@&762441731194748958>',
moderator = '<@&454192594633883658>'
}
}
5 changes: 0 additions & 5 deletions resources/discord_channel_names.lua

This file was deleted.

0 comments on commit c35909c

Please sign in to comment.