mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
User groups refactoring. Changed names to ignore case.
This commit is contained in:
parent
57ca9ddd6b
commit
a931ef6d9e
@ -3,7 +3,6 @@ require "config"
|
|||||||
require "utils.utils"
|
require "utils.utils"
|
||||||
require "utils.list_utils"
|
require "utils.list_utils"
|
||||||
require "base_data"
|
require "base_data"
|
||||||
require "user_groups"
|
|
||||||
require "info"
|
require "info"
|
||||||
require "player_list"
|
require "player_list"
|
||||||
require "poll"
|
require "poll"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
local Task = require "utils.Task"
|
local Task = require "utils.Task"
|
||||||
local Event = require "utils.event"
|
local Event = require "utils.event"
|
||||||
|
local UserGroups = require "user_groups"
|
||||||
|
|
||||||
function player_print(str)
|
function player_print(str)
|
||||||
if game.player then
|
if game.player then
|
||||||
@ -14,7 +15,7 @@ function cant_run(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function invoke(cmd)
|
local function invoke(cmd)
|
||||||
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
|
if not game.player or not (game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -29,7 +30,7 @@ local function invoke(cmd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function teleport_player(cmd)
|
local function teleport_player(cmd)
|
||||||
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
|
if not game.player or not (game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -45,7 +46,7 @@ local function teleport_player(cmd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function teleport_location(cmd)
|
local function teleport_location(cmd)
|
||||||
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
|
if not game.player or not (game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -65,7 +66,7 @@ end
|
|||||||
|
|
||||||
global.walking = {}
|
global.walking = {}
|
||||||
local function walkabout(cmd)
|
local function walkabout(cmd)
|
||||||
if not ((not game.player) or game.player.admin or is_mod(game.player.name)) then
|
if not ((not game.player) or game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -133,7 +134,7 @@ function custom_commands_return_player(args)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function regular(cmd)
|
local function regular(cmd)
|
||||||
if not ((not game.player) or game.player.admin or is_mod(game.player.name)) then
|
if not ((not game.player) or game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -148,9 +149,9 @@ local function regular(cmd)
|
|||||||
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
|
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
|
||||||
return
|
return
|
||||||
elseif (params[1] == "promote") then
|
elseif (params[1] == "promote") then
|
||||||
add_regular(params[2])
|
UserGroups.add_regular(params[2])
|
||||||
elseif (params[1] == "demote") then
|
elseif (params[1] == "demote") then
|
||||||
remove_regular(params[2])
|
UserGroups.remove_regular(params[2])
|
||||||
else
|
else
|
||||||
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
|
player_print("Command failed. Usage: /regular <promote, demote>, <player>")
|
||||||
end
|
end
|
||||||
@ -172,9 +173,9 @@ local function mod(cmd)
|
|||||||
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
|
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
|
||||||
return
|
return
|
||||||
elseif (params[1] == "promote") then
|
elseif (params[1] == "promote") then
|
||||||
add_mod(params[2])
|
UserGroups.add_mod(params[2])
|
||||||
elseif (params[1] == "demote") then
|
elseif (params[1] == "demote") then
|
||||||
remove_mod(params[2])
|
UserGroups.remove_mod(params[2])
|
||||||
else
|
else
|
||||||
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
|
player_print("Command failed. Usage: /mod <promote, demote>, <player>")
|
||||||
end
|
end
|
||||||
@ -259,7 +260,7 @@ end
|
|||||||
Event.add(defines.events.on_built_entity, built_entity)
|
Event.add(defines.events.on_built_entity, built_entity)
|
||||||
|
|
||||||
local function toggle_tp_mode(cmd)
|
local function toggle_tp_mode(cmd)
|
||||||
if not game.player or not (game.player.admin or is_mod(game.player.name)) then
|
if not game.player or not (game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -279,7 +280,7 @@ end
|
|||||||
global.old_force = {}
|
global.old_force = {}
|
||||||
global.force_toggle_init = true
|
global.force_toggle_init = true
|
||||||
local function forcetoggle(cmd)
|
local function forcetoggle(cmd)
|
||||||
if not game.player or not (game.player.admin or is_mod(game.player.name)) or (not game.player.character) then
|
if not game.player or not (game.player.admin or UserGroups.is_mod(game.player.name)) or (not game.player.character) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -370,7 +371,7 @@ function custom_commands_untempban(param)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function tempban(cmd)
|
local function tempban(cmd)
|
||||||
if (not game.player) or not (game.player.admin or is_mod(game.player.name)) then
|
if (not game.player) or not (game.player.admin or UserGroups.is_mod(game.player.name)) then
|
||||||
cant_run(cmd.name)
|
cant_run(cmd.name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -389,7 +390,11 @@ local function tempban(cmd)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local group = get_group()
|
local group = get_group()
|
||||||
game.print(get_actor() .. " put " .. params[1] .. " in timeout for " .. params[2] .. " minutes.")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
game.print(UserGroups.get_actor() .. " put " .. params[1] .. " in timeout for " .. params[2] .. " minutes.")
|
||||||
if group then
|
if group then
|
||||||
group.add_player(params[1])
|
group.add_player(params[1])
|
||||||
if not tonumber(cmd.parameter) then
|
if not tonumber(cmd.parameter) then
|
||||||
@ -464,9 +469,9 @@ commands.add_command("invoke", "<player> - Teleports the player to you. (Admins
|
|||||||
commands.add_command("tppos", "Teleports you to a selected entity. (Admins only)", teleport_location)
|
commands.add_command("tppos", "Teleports you to a selected entity. (Admins only)", teleport_location)
|
||||||
commands.add_command("walkabout", '<player> <duration> - Send someone on a walk. (Admins and moderators)', walkabout)
|
commands.add_command("walkabout", '<player> <duration> - Send someone on a walk. (Admins and moderators)', walkabout)
|
||||||
commands.add_command("market", 'Places a fish market near you. (Admins only)', spawn_market)
|
commands.add_command("market", 'Places a fish market near you. (Admins only)', spawn_market)
|
||||||
commands.add_command("regulars", 'Prints a list of game regulars.', print_regulars)
|
commands.add_command("regulars", 'Prints a list of game regulars.', UserGroups.print_regulars)
|
||||||
commands.add_command("regular", '<promote, demote>, <player> Change regular status of a player. (Admins and moderators)', regular)
|
commands.add_command("regular", '<promote, demote>, <player> Change regular status of a player. (Admins and moderators)', regular)
|
||||||
commands.add_command("mods", 'Prints a list of game mods.', print_mods)
|
commands.add_command("mods", 'Prints a list of game mods.', UserGroups.print_mods)
|
||||||
commands.add_command("mod", '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)
|
commands.add_command("mod", '<promote, demote>, <player> Changes moderator status of a player. (Admins only)', mod)
|
||||||
commands.add_command("afk", 'Shows how long players have been afk.', afk)
|
commands.add_command("afk", 'Shows how long players have been afk.', afk)
|
||||||
commands.add_command("tag", '<player> <tag> Sets a players tag. (Admins only)', tag)
|
commands.add_command("tag", '<player> <tag> Sets a players tag. (Admins only)', tag)
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
global.mods = {}
|
global.mods = {}
|
||||||
global.regualrs = {}
|
global.regualrs = {}
|
||||||
|
local Event = require "utils.event"
|
||||||
|
|
||||||
function update_group(position)
|
local Module = {}
|
||||||
|
|
||||||
|
local function update_group(position)
|
||||||
local file = position .. ".lua"
|
local file = position .. ".lua"
|
||||||
game.write_file(file, "{", false, 0)
|
game.write_file(file, "{", false, 0)
|
||||||
local group = global[position]
|
local group = global[position]
|
||||||
@ -13,26 +16,40 @@ function update_group(position)
|
|||||||
game.write_file(file, "}", true, 0)
|
game.write_file(file, "}", true, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_actor()
|
Module.get_actor = function()
|
||||||
if game.player then return game.player.name end
|
if game.player then return game.player.name end
|
||||||
return "<server>"
|
return "<server>"
|
||||||
end
|
end
|
||||||
|
|
||||||
function is_mod(player_name)
|
local function cast_bool(value)
|
||||||
return global.mods[player_name:lower()]
|
if value then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function is_regular(player_name)
|
Module.is_mod = function(player_name)
|
||||||
return global.regulars[player_name:lower()]
|
if global.mods[player_name] then
|
||||||
|
return cast_bool(global.mods[player_name:lower()]) --to make it backwards compatible
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function add_regular(player_name)
|
local is_regular = function(player_name)
|
||||||
|
if not global.regulars[player_name] then
|
||||||
|
return cast_bool(global.regulars[player_name:lower()]) --to make it backwards compatible
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
Module.add_regular = function(player_name)
|
||||||
local actor = get_actor()
|
local actor = get_actor()
|
||||||
if is_regular(player_name) then player_print(player_name .. " is already a regular.")
|
if is_regular(player_name) then player_print(player_name .. " is already a regular.")
|
||||||
else
|
else
|
||||||
if game.players[player_name] then
|
if game.players[player_name] then
|
||||||
game.print(actor .. " promoted " .. player_name .. " to regular.")
|
game.print(actor .. " promoted " .. player_name .. " to regular.")
|
||||||
global.regulars[player_name:lower()] = ""
|
global.regulars[player_name] = true
|
||||||
update_group("regulars")
|
update_group("regulars")
|
||||||
else
|
else
|
||||||
player_print(player_name .. " does not exist.")
|
player_print(player_name .. " does not exist.")
|
||||||
@ -40,13 +57,13 @@ function add_regular(player_name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function add_mod(player_name)
|
Module.add_mod = function(player_name)
|
||||||
local actor = get_actor()
|
local actor = get_actor()
|
||||||
if is_mod(player_name) then player_print(player_name .. " is already a moderator.")
|
if is_mod(player_name) then player_print(player_name .. " is already a moderator.")
|
||||||
else
|
else
|
||||||
if game.players[player_name] then
|
if game.players[player_name] then
|
||||||
game.print(actor .. " promoted " .. player_name .. " to moderator.")
|
game.print(actor .. " promoted " .. player_name .. " to moderator.")
|
||||||
global.mods[player_name:lower()] = ""
|
global.mods[player_name] = true
|
||||||
update_group("mods")
|
update_group("mods")
|
||||||
else
|
else
|
||||||
player_print(player_name .. " does not exist.")
|
player_print(player_name .. " does not exist.")
|
||||||
@ -54,28 +71,50 @@ function add_mod(player_name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function remove_regular(player_name)
|
Module.remove_regular = function(player_name)
|
||||||
local actor = get_actor()
|
local actor = get_actor()
|
||||||
if is_regular(player_name) then game.print(player_name .. " was demoted from regular by " .. actor .. ".") end
|
if is_regular(player_name) then game.print(player_name .. " was demoted from regular by " .. actor .. ".") end
|
||||||
global.regulars[player_name] = nil
|
global.regulars[player_name] = nil
|
||||||
update_group("regulars")
|
update_group("regulars")
|
||||||
end
|
end
|
||||||
|
|
||||||
function remove_mod(player_name)
|
Module.remove_mod = function(player_name)
|
||||||
local actor = get_actor()
|
local actor = get_actor()
|
||||||
if is_mod(player_name) then game.print(player_name .. " was demoted from mod by " .. actor .. ".") end
|
if is_mod(player_name) then game.print(player_name .. " was demoted from mod by " .. actor .. ".") end
|
||||||
global.mods[player_name] = nil
|
global.mods[player_name] = nil
|
||||||
update_group("mods")
|
update_group("mods")
|
||||||
end
|
end
|
||||||
|
|
||||||
function print_regulars()
|
Module.print_regulars = function()
|
||||||
for k,_ in pairs(global.regulars) do
|
for k,_ in pairs(global.regulars) do
|
||||||
player_print(k)
|
player_print(k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function print_mods()
|
Module.print_mods = function()
|
||||||
for k,_ in pairs(global.mods) do
|
for k,_ in pairs(global.mods) do
|
||||||
player_print(k)
|
player_print(k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Event.add(defines.events.on_player_joined_game, function(event)
|
||||||
|
local correctCaseName = game.players[event.player_index].name
|
||||||
|
if global.mods[correctCaseName:lower()] and not global.mods[correctCaseName] then
|
||||||
|
global.mods[correctCaseName:lower()] = nil
|
||||||
|
global.mods[correctCaseName] = true
|
||||||
|
update_group("mods")
|
||||||
|
end
|
||||||
|
if global.regulars[correctCaseName:lower()] and not global.regulars[correctCaseName] then
|
||||||
|
global.regulars[correctCaseName:lower()] = nil
|
||||||
|
global.regulars[correctCaseName] = true
|
||||||
|
update_group("regulars")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Event.add(-1, function()
|
||||||
|
if not global.regulars then global.regulars = {} end
|
||||||
|
if not global.mods then global.mods = {} end
|
||||||
|
end)
|
||||||
|
|
||||||
|
return Module
|
||||||
|
Loading…
Reference in New Issue
Block a user