mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Merge pull request #204 from Cooldude2606/feature/report-jail
Auto jail for reports and other fixes
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
|
||||
25
modules/addons/report-jail.lua
Normal file
25
modules/addons/report-jail.lua
Normal file
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user