Added report commands

This commit is contained in:
Cooldude2606
2019-04-18 15:16:12 +01:00
parent 2c108e6792
commit 17e61e710b
4 changed files with 124 additions and 0 deletions

View File

@@ -108,6 +108,10 @@
>>>>Functions List (see function for more detail):
Roles.debug() --- Returns a string which contains all roles in index order displaying all data for them
Roles.print_to_roles(roles,message) --- Prints a message to all players in the given roles, may send duplicate message however factorio blocks spam
Roles.print_to_roles_higher(role,message) --- Prints a message to all players who have the given role or one which is higher (excluding default)
Roles.print_to_roles_lower(role,message) --- Prints a message to all players who have the given role or one which is lower (excluding default)
Roles.get_role_by_name(name) --- Get a role for the given name
Roles.get_role_by_order(index) --- Get a role with the given order index
Roles.get_role_from_any(any) --- Gets a role from a name,index or role object (where it is just returned)
@@ -240,6 +244,46 @@ function Roles.debug()
return output
end
--- Prints a message to all players in the given roles, may send duplicate message however factorio blocks spam
-- @tparam roles table a table of roles which to send the message to
-- @tparam message string the message to send to the players
function Roles.print_to_roles(roles,message)
for _,role in pairs(roles) do
role = Roles.get_role_from_any(role)
if role then role:print(message) end
end
end
--- Prints a message to all players who have the given role or one which is higher (excluding default)
-- @tparam role string the name of the role to send the message to
-- @tparam message string the message to send to the players
function Roles.print_to_roles_higher(role,message)
role = Roles.get_role_from_any(role)
if not role then return end
local roles = {}
for index,role_name in pairs(Roles.config.order) do
if index <= role.index and role_name ~= Roles.config.internal.default then
table.insert(roles,role_name)
end
end
Roles.print_to_roles(roles,message)
end
--- Prints a message to all players who have the given role or one which is lower (excluding default)
-- @tparam role string the name of the role to send the message to
-- @tparam message string the message to send to the players
function Roles.print_to_roles_lower(role,message)
role = Roles.get_role_from_any(role)
if not role then return end
local roles = {}
for index,role_name in pairs(Roles.config.order) do
if index >= role.index and role_name ~= Roles.config.internal.default then
table.insert(roles,role_name)
end
end
Roles.print_to_roles(roles,message)
end
--- Get a role for the given name
-- @tparam name string the name of the role to get
-- @treturn Roles._prototype the role with that name or nil

View File

@@ -20,3 +20,12 @@ jail-temp-ban=__1__ was temp banned until next reset by __2__. Reason: __3__
jail-temp-ban-clear=__1__ was cleared from temp banned by __2__.
jail-not-temp-banned=__1__ is not currently temp banned.
jail-already-banned=__1__ is already banned.
report-player-immune=This player can not be reported.
report-non-admin=__1__ was reported for __2__.
report-admin=__1__ was reported by __2__ for __3__.
report-already-reported=You can only report a player once, you can ask a moderator to clear this report.
report-not-reported=The player had no reports on them.
report-player-count-title=The following players have reports against them:
report-player-report-title=__1__ has the following reports agasinst them:
report-list=__1__: __2__
report-removed=__1__ has one or more reports removed by __2__.

View File

@@ -20,6 +20,7 @@ end)
Commands.new_command('unjail','Puts a player into jail and removes all other roles.')
:add_param('player',false,'player-role')
:add_alias('clear-jail','remove-jail')
:enable_auto_concat()
:register(function(player,action_player,raw)
local action_player_name_color = format_chat_player_name(action_player)
@@ -48,6 +49,7 @@ end)
Commands.new_command('clear-temp-ban','Removes temp ban from a player; this will not restore they items.')
:add_param('player',false,'player-role')
:add_param('reason',false)
:add_alias('untemp-ban','remove-temp-ban')
:enable_auto_concat()
:register(function(player,action_player,reason,raw)
local action_player_name_color = format_chat_player_name(action_player)

View File

@@ -0,0 +1,69 @@
local Roles = require 'expcore.roles'
local Commands = require 'expcore.commands'
local ReportsControl = require 'modules.addons.reports-control'
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name')
require 'config.command_parse_general'
Commands.new_command('report','Reports a player and notifies moderators')
:add_param('player',false,function(input,player,reject)
input = Commands.parse('player',input,player,reject)
if not input then return end
if Roles.player_has_flag(player,'report-immune') then
return reject{'exp-command.report-player-immune'}
else
return input
end
end)
:add_param('reason',false)
:add_alias('report-player')
:enable_auto_concat()
:register(function(player,action_player,reason,raw)
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
if ReportsControl.report_player(action_player,reason,player.name) then
game.print{'exp-commands.report-non-admin',action_player_name_color,reason}
Roles.print_to_roles_higher('Trainee',{'exp-commands.report-admin',action_player_name_color,by_player_name_color,reason})
else
return Commands.error{'exp-commands.report-already-reported'}
end
end)
Commands.new_command('get-reports','Gets a list of all reports that a player has on them. If no player then lists all players and the number of reports on them.')
:add_param('player',true,'player')
:add_alias('reports','list-reports')
:register(function(player,action_player,raw)
if action_player then
local reports = ReportsControl.get_player_reports(action_player)
local action_player_name_color = format_chat_player_name(action_player)
Commands.print{'exp-commands.report-player-report-title',action_player_name_color}
for player_name,reason in pairs(reports) do
local by_player_name_color = format_chat_player_name(player_name)
Commands.print{'exp-commands.report-list',by_player_name_color,reason}
end
else
local user_reports = ReportsControl.user_reports
Commands.print{'exp-commands.report-player-count-title'}
for player_name,reports in pairs(user_reports) do
local player_name_color = format_chat_player_name(player_name)
Commands.print{'exp-commands.report-list',player_name_color,#reports}
end
end
end)
Commands.new_command('clear-reports','Clears all reports from a player or just the report from one player.')
:add_param('player',false,'player')
:add_param('from-player',true,'player')
:register(function(player,action_player,from_player,raw)
if from_player then
if not ReportsControl.remove_player_report(action_player,from_player) then
return Commands.error{'exp-commands.report-not-reported'}
end
else
if not ReportsControl.clear_player_reports(action_player) then
return Commands.error{'exp-commands.report-not-reported'}
end
end
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
game.print{'exp-commands.report-removed',action_player_name_color,by_player_name_color}
end)