Skip to content

Commit

Permalink
feat: Added support of a discord integration bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajick2013 committed Jan 3, 2024
1 parent c26408f commit 534f1b5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 9 deletions.
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Fed1sServerMod",
"version": "1.2.5",
"version": "1.2.6",
"title": "Fed1sServerMod",
"author": "danbka33",
"contact": "",
Expand Down
5 changes: 4 additions & 1 deletion locale/en/strings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ yellowchest_start_button=Start
yellowchest_stop_button=Stop

[players-inventory]
caption=Players inventory
caption-action-ban=Ban the player __1__?
caption-action-kick=Kick the player __1__?
caption-action-warn=Warn the player __1__?
Expand Down Expand Up @@ -80,7 +81,7 @@ caption-status=Connection status
caption-undecided=Undecided
caption-warned=Warnings
caption-warriors=Wariors
caption=Players inventory
caption-whitelist=Whitelist
description-open=Open players inventory
label-admin-badge=[color=#ffff00][admin][/color]
label-banned-badge=[banned]
Expand All @@ -103,6 +104,8 @@ message-now-admin=__1__ is now an Admin
message-now-manager=__1__ is now a Manager
message-warning=__1__ has been warned __2__ times: __3__
tooltip-ban=Ban
tooltip-bot-connected=Bot connected
tooltip-bot-disconnected=Bot disconnected
tooltip-clear-textfield=Clear text field
tooltip-favorite=Add to Favorites
tooltip-fix-permissions=Fix the prermissions
Expand Down
5 changes: 4 additions & 1 deletion locale/ru/strings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ yellowchest_start_button=Запустить
yellowchest_stop_button=Остановить

[players-inventory]
caption=Закрома игроков
caption-action-ban=Забанить игрока __1__?
caption-action-kick=Выгнать игрока __1__?
caption-action-warn=Вынести предупреждение игроку __1__?
Expand Down Expand Up @@ -80,7 +81,7 @@ caption-status=Статус подключения
caption-undecided=Неопределившиеся
caption-warned=Предупреждённые
caption-warriors=Атакующие
caption=Закрома игроков
caption-whitelist=Белый список
description-open=Открыть закрома игроков
label-admin-badge=[color=#ffff00][админ][/color]
label-banned-badge=[забанен]
Expand All @@ -103,6 +104,8 @@ message-now-admin=__1__ теперь Админ
message-now-manager=__1__ теперь Руководитель
message-warning=Игроку __1__ вынесено предупреждение __2__: __3__
tooltip-ban=Забанить
tooltip-bot-connected=Бот в сети
tooltip-bot-disconnected=Бот не в сети
tooltip-clear-textfield=Очистить поле ввода
tooltip-favorite=Добавить в Избранные
tooltip-fix-permissions=Починить права
Expand Down
79 changes: 77 additions & 2 deletions scripts/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

local mod_gui = require("__core__/lualib/mod-gui")


commands.add_command("fix-permissions", nil, function(command)
if not command or not command.player_index then
return
Expand Down Expand Up @@ -110,4 +109,80 @@ commands.add_command("reinit", nil, function(command)

::continue::
end
end)
end)

commands.add_command("wlist-state", nil, function(command)
if not command then
return
end

local player

if command.player_index then
player = game.get_player(command.player_index)
else
player = rcon
end

if not player then
return
end

if global.wlist_state then
player.print("1")
else
player.print("0")
end

PlayersInventory.wlist_bot_connected = true
PlayersInventory.wlist_bot_last_tick = game.tick
end)

--[[ commands.add_command("bot-state", nil, function(command)
if not command or not command.parameter then
return
end
local parameter = command.parameter
if not parameter then
return
end
if parameter == "on" then
PlayersInventory.wlist_bot_enabled = true
elseif parameter == "off" then
PlayersInventory.wlist_bot_enabled = false
else
return
end
PlayersInventory.wlist_bot_connected = true
PlayersInventory.wlist_bot_last_tick = game.tick
end) ]]

--[[ commands.add_command("voice-in", nil, function(command)
if not command or not command.parameter then
return
end
local parameter = command.parameter
if not parameter then
return
end
local channel, player_name = string.match(parameter, "(.+)%s(.+)")
if not channel or not player_name then
return
end
local player = game.get_player(player_name)
if not player then
return
end
--
end) ]]
27 changes: 27 additions & 0 deletions scripts/players_inventory/main_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ function MainWindow.create(player_index)
local settings_spacer = settings_panel.add{type="empty-widget", ignored_by_interaction=true}
settings_spacer.style.horizontally_stretchable = true

-- Whitelist checkbox
local wlist_bot_connected

if PlayersInventory.wlist_bot_connected then
wlist_bot_connected = {"players-inventory.tooltip-bot-connected"}
else
wlist_bot_connected = {"players-inventory.tooltip-bot-disconnected"}
end

local whitelist = settings_panel.add{
type = "checkbox",
name = "players_inventory_whitelist_checkbox",
caption = {"players-inventory.caption-whitelist"},
tooltip = wlist_bot_connected,
state = global.wlist_state,
enabled = (player.admin and PlayersInventory.wlist_bot_connected)
}

-- Friendly fire checkbox
local friendly_fire = settings_panel.add{
type = "checkbox",
Expand Down Expand Up @@ -1638,6 +1656,8 @@ function MainWindow.on_gui_checked_state_changed(event)
end

player.force.friendly_fire = element.state
elseif element.name == "players_inventory_whitelist_checkbox" then
global.wlist_state = element.state
end
end

Expand Down Expand Up @@ -2269,6 +2289,13 @@ event_handlers.events = {
EventHandler.add_lib(event_handlers)


-- /wlist-state
-- > 0|1

-- /bot-state on|off

-- /voice-in канал ник,

-- Return --

return MainWindow
22 changes: 19 additions & 3 deletions scripts/players_inventory/players_inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ local ConfirmWindow = require("scripts.players_inventory.confirm_window")

local PlayersInventory = {
main_window = require("scripts.players_inventory.main_window"),
roles = {}
roles = {},
wlist_bot_connected = false,
wlist_bot_last_tick = 0
}

PlayersInventory.inventories = {
Expand Down Expand Up @@ -172,9 +174,13 @@ function PlayersInventory.on_init()
if not global.players_inventory.bans then
global.players_inventory.bans = {}
end

if not global.wlist_state then
global.wlist_state = false
end
end

-- Conguguration changed
-- Configuration changed
---@param data ConfigurationChangedData
function PlayersInventory.on_configuration_changed(data)
if not data or not data.mod_changes then
Expand All @@ -188,6 +194,15 @@ function PlayersInventory.on_configuration_changed(data)
end
end

-- N-th tick rised
---@param data NthTickEventData
function PlayersInventory.on_nth_tick(data)
-- 2 minutes
if game.tick-PlayersInventory.wlist_bot_last_tick > 7200 then
PlayersInventory.wlist_bot_connected = false
end
end

-- Player created
---@param event Event
function PlayersInventory.on_player_created(event)
Expand Down Expand Up @@ -270,7 +285,8 @@ end

local event_handlers = {
on_init = PlayersInventory.on_init,
on_configuration_changed = PlayersInventory.on_configuration_changed
on_configuration_changed = PlayersInventory.on_configuration_changed,
on_nth_tick = {[600]=PlayersInventory.on_nth_tick}
}
event_handlers.events = {
[defines.events.on_player_created] = PlayersInventory.on_player_created,
Expand Down
5 changes: 4 additions & 1 deletion settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ data:extend{
default_value = 5,
minimum_value = 1,
maximum_value = 1000,
order = "a",
order = "1",
},
{
type = "bool-setting",
name = "server_mod-show-overhead-button",
setting_type = "runtime-per-user",
default_value = true,
order = "1"
},
{
type = "bool-setting",
name = "server_mod_admin_message_on_center",
setting_type = "runtime-per-user",
default_value = true,
order = "2"
},
{
type = "bool-setting",
name = "server_mod_show_stats",
setting_type = "runtime-per-user",
default_value = true,
order = "3"
}
}

0 comments on commit 534f1b5

Please sign in to comment.