Skip to content

Commit 3aeaa5d

Browse files
committed
Refactor chat auto reply
1 parent ec41738 commit 3aeaa5d

File tree

12 files changed

+245
-228
lines changed

12 files changed

+245
-228
lines changed

exp_legacy/module/config/_file_loader.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ return {
1515
"modules.addons.pollution-grading",
1616
"modules.addons.station-auto-name",
1717
"modules.addons.discord-alerts",
18-
"modules.addons.chat-reply",
1918
"modules.addons.tree-decon",
2019
"modules.addons.afk-kick",
2120
"modules.addons.report-jail",

exp_legacy/module/config/chat_reply.lua

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
local ExpUtil = require("modules/exp_util")
55
local Async = require("modules/exp_util/async")
66

7+
local floor = math.floor
8+
local random = math.random
9+
local format_string = string.format
10+
local locale_reply = "exp_chat-auto-reply.chat-reply"
11+
712
local send_message_async =
813
Async.register(function(player, message)
9-
if player == true then
14+
if player == nil then
1015
game.print(message)
1116
else
1217
player.print(message)
@@ -18,9 +23,7 @@ local afk_time_units = {
1823
seconds = true,
1924
}
2025

21-
-- luacheck:ignore 212/player 212/is_command
2226
return {
23-
allow_command_prefix_for_messages = true, --- @setting allow_command_prefix_for_messages when true any message trigger will print to all player when prefixed
2427
messages = { --- @setting messages will trigger when ever the word is said
2528
["discord"] = { "info.discord" },
2629
["expgaming"] = { "info.website" },
@@ -32,99 +35,100 @@ return {
3235
["command"] = { "info.custom-commands" },
3336
["commands"] = { "info.custom-commands" },
3437
["softmod"] = { "info.softmod" },
38+
["plugin"] = { "info.softmod" },
3539
["script"] = { "info.softmod" },
36-
["loop"] = { "chat-bot.loops" },
40+
["redmew"] = { "info.redmew" },
41+
["comfy"] = { "info.redmew" },
3742
["rhd"] = { "info.lhd" },
3843
["lhd"] = { "info.lhd" },
39-
["roundabout"] = { "chat-bot.loops" },
40-
["roundabouts"] = { "chat-bot.loops" },
41-
["redmew"] = { "info.redmew" },
42-
["afk"] = function(player, _is_command)
44+
["loop"] = { "exp_chat-auto-reply.reply-loops" },
45+
["roundabout"] = { "exp_chat-auto-reply.reply-loops" },
46+
["roundabouts"] = { "exp_chat-auto-reply.reply-loops" },
47+
["clusterio"] = { "exp_chat-auto-reply.reply-clusterio" },
48+
["players"] = function()
49+
return { "exp_chat-auto-reply.reply-players", #game.players }
50+
end,
51+
["online"] = function()
52+
return { "exp_chat-auto-reply.reply-online", #game.connected_players }
53+
end,
54+
["afk"] = function(player)
4355
local max = player
4456
for _, next_player in pairs(game.connected_players) do
4557
if max.afk_time < next_player.afk_time then
4658
max = next_player
4759
end
4860
end
4961

50-
return { "chat-bot.afk", max.name, ExpUtil.format_time_locale(max.afk_time, "long", afk_time_units) }
51-
end,
52-
["players"] = function(_player, _is_command)
53-
return { "chat-bot.players", #game.players }
54-
end,
55-
["online"] = function(_player, _is_command)
56-
return { "chat-bot.players-online", #game.connected_players }
57-
end,
58-
["r!verify"] = function(player, _is_command)
59-
return { "chat-bot.verify", player.name }
62+
return { "exp_chat-auto-reply.reply-afk", max.name, ExpUtil.format_time_locale(max.afk_time, "long", afk_time_units) }
6063
end,
6164
},
65+
allow_command_prefix_for_messages = true, --- @setting allow_command_prefix_for_messages when true any message trigger will print to all player when prefixed
6266
command_admin_only = false, --- @setting command_admin_only when true will only allow chat commands for admins
63-
command_permission = "command/chat-bot", --- @setting command_permission the permission used to allow command prefixes
67+
command_permission = "command/chat-commands", --- @setting command_permission the permission used to allow command prefixes
6468
command_prefix = "!", --- @setting command_prefix prefix used for commands below and to print to all players (if enabled above)
6569
commands = { --- @setting commands will trigger only when command prefix is given
66-
["dev"] = { "chat-bot.not-real-dev" },
67-
["blame"] = function(player, _is_command)
70+
["dev"] = { "exp_chat-auto-reply.reply-dev" },
71+
["magic"] = { "exp_chat-auto-reply.reply-magic" },
72+
["aids"] = { "exp_chat-auto-reply.reply-aids" },
73+
["riot"] = { "exp_chat-auto-reply.reply-riot" },
74+
["lenny"] = { "exp_chat-auto-reply.reply-lenny" },
75+
["blame"] = function(player)
6876
local names = { "Cooldude2606", "arty714", "badgamernl", "mark9064", "aldldl", "Drahc_pro", player.name }
6977
for _, next_player in pairs(game.connected_players) do
7078
names[#names + 1] = next_player.name
7179
end
7280

73-
return { "chat-bot.blame", table.get_random(names) }
81+
return { "exp_chat-auto-reply.reply-blame", table.get_random(names) }
7482
end,
75-
["magic"] = { "chat-bot.magic" },
76-
["aids"] = { "chat-bot.aids" },
77-
["riot"] = { "chat-bot.riot" },
78-
["lenny"] = { "chat-bot.lenny" },
79-
["hodor"] = function(_player, _is_command)
83+
["hodor"] = function()
8084
local options = { "?", ".", "!", "!!!" }
81-
return { "chat-bot.hodor", table.get_random(options) }
85+
return { "exp_chat-auto-reply.reply-hodor", table.get_random(options) }
8286
end,
83-
["evolution"] = function(player, _is_command)
84-
return { "chat-bot.current-evolution", string.format("%.2f", game.forces["enemy"].get_evolution_factor(player.surface)) }
87+
["evolution"] = function(player)
88+
return { "exp_chat-auto-reply.reply-evolution", format_string("%.2f", game.forces["enemy"].get_evolution_factor(player.surface)) }
8589
end,
86-
["makepopcorn"] = function(player, _is_command)
87-
local timeout = math.floor(180 * (math.random() + 0.5))
88-
send_message_async(true, { "chat-bot.reply", { "chat-bot.get-popcorn-1" } })
89-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-popcorn-2", player.name } })
90+
["makepopcorn"] = function(player)
91+
local timeout = floor(180 * (random() + 0.5))
92+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-popcorn-2", player.name } })
93+
return { locale_reply, { "exp_chat-auto-reply.reply-popcorn-1" } }
9094
end,
91-
["passsomesnaps"] = function(player, _is_command)
92-
local timeout = math.floor(180 * (math.random() + 0.5))
93-
send_message_async(player, { "chat-bot.reply", { "chat-bot.get-snaps-1" } })
94-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-snaps-2", player.name } })
95-
send_message_async:start_after(timeout * (math.random() + 0.5), true, { "chat-bot.reply", { "chat-bot.get-snaps-3", player.name } })
95+
["passsomesnaps"] = function(player)
96+
local timeout = floor(180 * (random() + 0.5))
97+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-snaps-2", player.name } })
98+
send_message_async:start_after(timeout * (random() + 0.5), nil, { locale_reply, { "exp_chat-auto-reply.reply-snaps-3", player.name } })
99+
return { locale_reply, { "exp_chat-auto-reply.reply-snaps-1" } }
96100
end,
97-
["makecocktail"] = function(player, _is_command)
98-
local timeout = math.floor(180 * (math.random() + 0.5))
99-
send_message_async(true, { "chat-bot.reply", { "chat-bot.get-cocktail-1" } })
100-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-cocktail-2", player.name } })
101-
send_message_async:start_after(timeout * (math.random() + 0.5), true, { "chat-bot.reply", { "chat-bot.get-cocktail-3", player.name } })
101+
["makecocktail"] = function(player)
102+
local timeout = floor(180 * (random() + 0.5))
103+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-cocktail-2", player.name } })
104+
send_message_async:start_after(timeout * (random() + 0.5), nil, { locale_reply, { "exp_chat-auto-reply.reply-cocktail-3", player.name } })
105+
return { locale_reply, { "exp_chat-auto-reply.reply-cocktail-1" } }
102106
end,
103-
["makecoffee"] = function(player, _is_command)
104-
local timeout = math.floor(180 * (math.random() + 0.5))
105-
send_message_async(true, { "chat-bot.reply", { "chat-bot.make-coffee-1" } })
106-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.make-coffee-2", player.name } })
107+
["makecoffee"] = function(player)
108+
local timeout = floor(180 * (random() + 0.5))
109+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-coffee-2", player.name } })
110+
return { locale_reply, { "exp_chat-auto-reply.reply-coffee-1" } }
107111
end,
108-
["orderpizza"] = function(player, _is_command)
109-
local timeout = math.floor(180 * (math.random() + 0.5))
110-
send_message_async(true, { "chat-bot.reply", { "chat-bot.order-pizza-1" } })
111-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.order-pizza-2", player.name } })
112-
send_message_async:start_after(timeout * (math.random() + 0.5), true, { "chat-bot.reply", { "chat-bot.order-pizza-3", player.name } })
112+
["orderpizza"] = function(player)
113+
local timeout = floor(180 * (random() + 0.5))
114+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-pizza-2", player.name } })
115+
send_message_async:start_after(timeout * (random() + 0.5), nil, { locale_reply, { "exp_chat-auto-reply.reply-pizza-3", player.name } })
116+
return { locale_reply, { "exp_chat-auto-reply.reply-pizza-1" } }
113117
end,
114-
["maketea"] = function(player, _is_command)
115-
local timeout = math.floor(180 * (math.random() + 0.5))
116-
send_message_async(true, { "chat-bot.reply", { "chat-bot.make-tea-1" } })
117-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.make-tea-2", player.name } })
118+
["maketea"] = function(player)
119+
local timeout = floor(180 * (random() + 0.5))
120+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-tea-2", player.name } })
121+
return { locale_reply, { "exp_chat-auto-reply.reply-tea-1" } }
118122
end,
119-
["meadplease"] = function(player, _is_command)
120-
local timeout = math.floor(180 * (math.random() + 0.5))
121-
send_message_async(true, { "chat-bot.reply", { "chat-bot.get-mead-1" } })
122-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-mead-2", player.name } })
123+
["meadplease"] = function(player)
124+
local timeout = floor(180 * (random() + 0.5))
125+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-mead-2", player.name } })
126+
return { locale_reply, { "exp_chat-auto-reply.reply-mead-1" } }
123127
end,
124-
["passabeer"] = function(player, _is_command)
125-
local timeout = math.floor(180 * (math.random() + 0.5))
126-
send_message_async(true, { "chat-bot.reply", { "chat-bot.get-beer-1" } })
127-
send_message_async:start_after(timeout, true, { "chat-bot.reply", { "chat-bot.get-beer-2", player.name } })
128+
["passabeer"] = function(player)
129+
local timeout = floor(180 * (random() + 0.5))
130+
send_message_async:start_after(timeout, nil, { locale_reply, { "exp_chat-auto-reply.reply-beer-2", player.name } })
131+
return { locale_reply, { "exp_chat-auto-reply.reply-beer-1" } }
128132
end,
129133
},
130134
}

exp_legacy/module/config/expcore/roles.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Roles.new_role("Veteran", "Vet")
204204
:set_custom_color{ r = 140, g = 120, b = 200 }
205205
:set_parent("Member")
206206
:allow{
207-
"command/chat-bot",
207+
"command/chat-commands",
208208
"command/clear-ground-items",
209209
"command/clear-blueprints-radius",
210210
"command/set-trains-to-automatic",

exp_legacy/module/locale/en/addons.cfg

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,6 @@ script-warning=You are receiving script warnings; if you recive too many you wil
3434
script-warning-removed=A script warning has expired (__1__/__2__)
3535
script-warning-limit=__1__ has received a permanent warning from the script.
3636
37-
[chat-bot]
38-
reply=[Chat Bot] __1__
39-
disallow=You can't use global chat commands
40-
players-online=There are __1__ players online
41-
players=There have been __1__ players on this map
42-
not-real-dev=Cooldude2606 is a dev for this server and makes the softmod and is not a factorio dev.
43-
softmod=A softmod is a custom scenario that runs on this server,an example is the player list.
44-
blame=Blame __1__ for what just happened!
45-
afk=You're afk? Look at __1__, that player has been afk for: __2__
46-
current-evolution=Current evolution factor is __1__
47-
magic=Fear the admin magic (ノ゚∀゚)ノ⌒・*:.。. .。.:*・゜゚・*☆
48-
aids=≖ ‿ ≖ Fear the aids of a public server ≖ ‿ ≖
49-
riot=(admins) ┬┴┬┴┤ᵒ_ᵒ)├┬┴┬┴ ‹ ‹\(´ω` )/››‹‹\ (  ´)/››‹‹\ ( ´ω`)/›› (rest of server)
50-
loops=NO LOOPS; LOOPS ARE BAD; JUST NO LOOPS!!!!!; IF YOU MAKE A LOOP.... IT WILL NOT END WELL!!!!!!!
51-
lenny=( ͡° ͜ʖ ͡°)
52-
hodor=Hodor
53-
get-popcorn-1=Heating the oil and waiting for the popping sound...
54-
get-popcorn-2=__1__ your popcorn is finished. Lean backwards and watch the drama unfold.
55-
get-snaps-1=Pouring the glasses and finding the correct song book...
56-
get-snaps-2=Singing a song...🎤🎶
57-
get-snaps-3=schkål, my friends!
58-
get-cocktail-1= 🍸 Inintiating mind reading unit... 🍸
59-
get-cocktail-2= 🍸 Mixing favourite ingredients of __1__ 🍸
60-
get-cocktail-3=🍸 __1__ your cocktail is done.🍸
61-
make-coffee-1= ☕ Boiling the water and grinding the coffee beans... ☕
62-
make-coffee-2= ☕ __1__ we ran out of coffe beans! Have some tea instead. ☕
63-
order-pizza-1= 🍕 Finding nearest pizza supplier... 🍕
64-
order-pizza-2= 🍕 Figuring out the favourite pizza of __1__ 🍕
65-
order-pizza-3= 🍕 __1__ your pizza is here! 🍕
66-
make-tea-1= ☕ Boiling the water... ☕
67-
make-tea-2= ☕ __1__ your tea is done! ☕
68-
get-mead-1= Filling the drinking horn
69-
get-mead-2= Skål!
70-
get-beer-1= 🍺 Pouring A Glass 🍺
71-
get-beer-2= 🍻 Chears Mate 🍻
72-
verify=Please return to our discord and type r!verify __1__
73-
7437
[afk-kick]
7538
message=All players were kicked because everyone was AFK.
7639

exp_legacy/module/locale/zh-CN/addons.cfg

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,6 @@ script-warning=這是系統發出的自動警告 (__1__/__2__)
3434
script-warning-removed=系統發出的自動警告已失效 (__1__/__2__)
3535
script-warning-limit=__1__ 已被系統發出了一則自動警告。
3636

37-
[chat-bot]
38-
reply=[Chat Bot] __1__
39-
disallow=你沒有權限使用這個指令。
40-
players-online=現在有 __1__ 人上線。
41-
players=本地圖現在有 __1__ 人曾上線。
42-
not-real-dev=Cooldude2606 只是本場境的開發者
43-
softmod=這裹用了自設情境。
44-
blame=責怪 __1__ 吧。
45-
afk=看看 __1__, 他已掛機 __2__ 。
46-
current-evolution=現在敵人進化度為 __1__ 。
47-
magic=Fear the admin magic (ノ゚∀゚)ノ⌒・*:.。. .。.:*・゜゚・*☆
48-
aids=≖ ‿ ≖ Fear the aids of a public server ≖ ‿ ≖
49-
riot=(admins) ┬┴┬┴┤ᵒ_ᵒ)├┬┴┬┴ ‹ ‹\(´ω` )/››‹‹\ (  ´)/››‹‹\ ( ´ω`)/›› (rest of server)
50-
loops=架設迴旋處最終後果都不好。
51-
lenny=( ͡° ͜ʖ ͡°)
52-
hodor=Hodor
53-
get-popcorn-1=Heating the oil and waiting for the popping sound...
54-
get-popcorn-2=__1__ your popcorn is finished. Lean backwards and watch the drama unfold.
55-
get-snaps-1=Pouring the glasses and finding the correct song book...
56-
get-snaps-2=Singing a song...🎤🎶
57-
get-snaps-3=schkål, my friends!
58-
get-cocktail-1= 🍸 Inintiating mind reading unit... 🍸
59-
get-cocktail-2= 🍸 Mixing favourite ingredients of __1__ 🍸
60-
get-cocktail-3=🍸 __1__ your cocktail is done.🍸
61-
make-coffee-1= ☕ Boiling the water and grinding the coffee beans... ☕
62-
make-coffee-2= ☕ __1__ we ran out of coffe beans! Have some tea instead. ☕
63-
order-pizza-1= 🍕 Finding nearest pizza supplier... 🍕
64-
order-pizza-2= 🍕 Figuring out the favourite pizza of __1__ 🍕
65-
order-pizza-3= 🍕 __1__ your pizza is here! 🍕
66-
make-tea-1= ☕ Boiling the water... ☕
67-
make-tea-2= ☕ __1__ your tea is done! ☕
68-
get-mead-1= Filling the drinking horn
69-
get-mead-2= Skål!
70-
get-beer-1= 🍺 Pouring A Glass 🍺
71-
get-beer-2= 🍻 Chears Mate 🍻
72-
verify=Please return to our discord and type r!verify __1__
73-
7437
[afk-kick]
7538
message=因地圖中沒有活躍玩家,所以所有人都已被請離。
7639

exp_legacy/module/locale/zh-TW/addons.cfg

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,6 @@ script-warning=這是系統發出的自動警告 (__1__/__2__)
3434
script-warning-removed=系統發出的自動警告已失效 (__1__/__2__)
3535
script-warning-limit=__1__ 已被系統發出了一則自動警告。
3636

37-
[chat-bot]
38-
reply=[Chat Bot] __1__
39-
disallow=你沒有權限使用這個指令。
40-
players-online=現在有 __1__ 人上線。
41-
players=本地圖現在有 __1__ 人曾上線。
42-
not-real-dev=Cooldude2606 只是本場境的開發者
43-
softmod=這裹用了自設情境。
44-
blame=責怪 __1__ 吧。
45-
afk=看看 __1__, 他已掛機 __2__ 。
46-
current-evolution=現在敵人進化度為 __1__ 。
47-
magic=Fear the admin magic (ノ゚∀゚)ノ⌒・*:.。. .。.:*・゜゚・*☆
48-
aids=≖ ‿ ≖ Fear the aids of a public server ≖ ‿ ≖
49-
riot=(admins) ┬┴┬┴┤ᵒ_ᵒ)├┬┴┬┴ ‹ ‹\(´ω` )/››‹‹\ (  ´)/››‹‹\ ( ´ω`)/›› (rest of server)
50-
loops=架設迴旋處最終後果都不好。
51-
lenny=( ͡° ͜ʖ ͡°)
52-
hodor=Hodor
53-
get-popcorn-1=Heating the oil and waiting for the popping sound...
54-
get-popcorn-2=__1__ your popcorn is finished. Lean backwards and watch the drama unfold.
55-
get-snaps-1=Pouring the glasses and finding the correct song book...
56-
get-snaps-2=Singing a song...🎤🎶
57-
get-snaps-3=schkål, my friends!
58-
get-cocktail-1= 🍸 Inintiating mind reading unit... 🍸
59-
get-cocktail-2= 🍸 Mixing favourite ingredients of __1__ 🍸
60-
get-cocktail-3=🍸 __1__ your cocktail is done.🍸
61-
make-coffee-1= ☕ Boiling the water and grinding the coffee beans... ☕
62-
make-coffee-2= ☕ __1__ we ran out of coffe beans! Have some tea instead. ☕
63-
order-pizza-1= 🍕 Finding nearest pizza supplier... 🍕
64-
order-pizza-2= 🍕 Figuring out the favourite pizza of __1__ 🍕
65-
order-pizza-3= 🍕 __1__ your pizza is here! 🍕
66-
make-tea-1= ☕ Boiling the water... ☕
67-
make-tea-2= ☕ __1__ your tea is done! ☕
68-
get-mead-1= Filling the drinking horn
69-
get-mead-2= Skål!
70-
get-beer-1= 🍺 Pouring A Glass 🍺
71-
get-beer-2= 🍻 Chears Mate 🍻
72-
verify=Please return to our discord and type r!verify __1__
73-
7437
[afk-kick]
7538
message=因地圖中沒有活躍玩家,所以所有人都已被請離。
7639

0 commit comments

Comments
 (0)