Skip to content

Commit

Permalink
Merge pull request #204 from Cooldude2606/feature/report-jail
Browse files Browse the repository at this point in the history
Auto jail for reports and other fixes
  • Loading branch information
Cooldude2606 authored Apr 24, 2021
2 parents 7381541 + 70664ff commit 13c1684
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions config/_file_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ return {
'modules.addons.discord-alerts',
'modules.addons.chat-reply',
'modules.addons.tree-decon',
'modules.addons.report-jail',

--- Data
'modules.data.statistics',
Expand Down
1 change: 1 addition & 0 deletions config/gui/player_list_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ return {
},
['command/report'] = {
auth=function(player,selected_player)
if player == selected_player then return false end
if not Roles.player_allowed(player,'command/give-warning') then
return not Roles.player_has_flag(selected_player,'report-immune')
end
Expand Down
5 changes: 4 additions & 1 deletion locale/en/addons.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ get-mead-1= Filling the drinking horn
get-mead-2= Skål!
get-beer-1= 🍺 Pouring A Glass 🍺
get-beer-2= 🍻 Chears Mate 🍻
verify=Please return to our discord and type r!verify __1__
verify=Please return to our discord and type r!verify __1__
[report-jail]
jail=__1__ was jailed because they were reported too many times.
1 change: 1 addition & 0 deletions locale/en/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ not-jailed=__1__ is not currently in jail.

[expcom-report]
player-immune=This player can not be reported.
self-report=You cannot report yourself.
non-admin=__1__ was reported for __2__.
admin=__1__ was reported by __2__ for __3__.
already-reported=You can only report a player once, you can ask a moderator to clear this report.
Expand Down
25 changes: 25 additions & 0 deletions modules/addons/report-jail.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- When a player is reported, the player is automatically jailed if the combined playtime of the reporters exceeds the reported player
-- @addon report-jail

local Event = require 'utils.event' ---@dep utils.event
local Jail = require 'modules.control.jail' ---@dep modules.control.jail
local Reports = require 'modules.control.reports' --- @dep modules.control.reports
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common

--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters
local function reporter_playtime(_, by_player_name, _)
local player = game.get_player(by_player_name)
if player == nil then return 0 end
return player.online_time
end

--- Tests the combined playtime of all reporters against the reported player
Event.add(Reports.events.on_player_reported, function(event)
local player = game.get_player(event.player_index)
local total_playtime = Reports.count_reports(player, reporter_playtime)
if total_playtime < player.online_time*1.5 then return end
-- Combined playtime is greater than 150% of the reported's playtime
local player_name_color = format_chat_player_name(player)
Jail.jail_player(player, '<reports>', 'Reported by too many players, please wait for a moderator.')
game.print{'report-jail.jail', player_name_color}
end)
15 changes: 13 additions & 2 deletions modules/commands/reports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ local Reports = require 'modules.control.reports' --- @dep modules.control.repor
local format_chat_player_name = _C.format_chat_player_name--- @dep expcore.common
require 'config.expcore.command_general_parse'

--- Print a message to all players who match the value of admin
local function print_to_players(admin, message)
for _, player in ipairs(game.connected_players) do
if player.admin == admin then
player.print(message)
end
end
end

--- Reports a player and notifies moderators
-- @command report
-- @tparam LuaPlayer player the player to report, some players are immune
Expand All @@ -19,6 +28,8 @@ Commands.new_command('report', 'Reports a player and notifies moderators')
if not input then return end
if Roles.player_has_flag(input, 'report-immune') then
return reject{'expcom-report.player-immune'}
elseif player == input then
return reject{'expcom-report.self-report'}
else
return input
end
Expand All @@ -30,8 +41,8 @@ end)
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
if Reports.report_player(action_player, player.name, reason) then
game.print{'expcom-report.non-admin', action_player_name_color, reason}
Roles.print_to_roles_higher('Trainee', {'expcom-report.admin', action_player_name_color, by_player_name_color, reason})
print_to_players(false, {'expcom-report.non-admin', action_player_name_color, reason})
print_to_players(true, {'expcom-report.admin', action_player_name_color, by_player_name_color, reason})
else
return Commands.error{'expcom-report.already-reported'}
end
Expand Down
2 changes: 1 addition & 1 deletion modules/control/reports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function Reports.report_player(player, by_player_name, reason)
if not player then return end
local player_name = player.name

reason = reason or 'Non given.'
if reason == nil or not reason:find("/S") then reason = 'No reason given' end

local reports = user_reports[player_name]
if not reports then
Expand Down
3 changes: 2 additions & 1 deletion modules/gui/player-list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ Gui.element{
}
:style(Gui.sprite_style(30, -1, { left_margin = -2, right_margin = -1 }))
:on_click(function(player, element)
local reason = element.parent.entry.text or 'Non Given'
local reason = element.parent.entry.text
local action_name = SelectedAction:get(player)
local reason_callback = config.buttons[action_name].reason_callback
if reason == nil or not reason:find("/S") then reason = 'no reason given' end
reason_callback(player, reason)
SelectedPlayer:remove(player)
SelectedAction:remove(player)
Expand Down

0 comments on commit 13c1684

Please sign in to comment.