forked from M3wM3w/ComfyFactorio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.lua
153 lines (140 loc) · 5.59 KB
/
chatbot.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
local event = require 'utils.event'
local session = require 'utils.session_data'
local message_color = {r = 0.5, g = 0.3, b = 1}
local brain = {
[1] = {"Our Discord server is at https://getcomfy.eu/discord"},
[2] = {"Need an admin? Type @Mods in game chat to notify moderators,", "or put a message in the discord help channel."}
}
local links = {
["discord"] = brain[1],
["admin"] = brain[2],
["administrator"] = brain[2],
["mod"] = brain[2],
["moderator"] = brain[2],
["grief"] = brain[2],
["troll"] = brain[2],
["trolling"] = brain[2],
["stealing"] = brain[2],
["stole"] = brain[2],
["griefer"] = brain[2],
["greifer"] = brain[2]
}
local function on_player_created(event)
local player = game.players[event.player_index]
player.print("Join the comfy discord >> getcomfy.eu/discord", message_color)
end
commands.add_command(
'trust',
'Promotes a player to trusted!',
function(cmd)
local trusted = session.get_trusted_table()
local server = 'server'
local player = game.player
local p
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
return
end
else
p = log
end
if cmd.parameter == nil then return end
local target_player = game.players[cmd.parameter]
if target_player then
if trusted[target_player.name] == true then game.print(target_player.name .. " is already trusted!") return end
trusted[target_player.name] = true
game.print(target_player.name .. " is now a trusted player.", {r=0.22, g=0.99, b=0.99})
for _, a in pairs(game.connected_players) do
if a.admin == true and a.name ~= player.name then
a.print("[ADMIN]: " .. player.name .. " trusted " .. target_player.name, {r = 1, g = 0.5, b = 0.1})
end
end
end
else
if cmd.parameter == nil then return end
local target_player = game.players[cmd.parameter]
if target_player then
if trusted[target_player.name] == true then game.print(target_player.name .. " is already trusted!") return end
trusted[target_player.name] = true
game.print(target_player.name .. " is now a trusted player.", {r=0.22, g=0.99, b=0.99})
end
end
end
)
commands.add_command(
'untrust',
'Demotes a player from trusted!',
function(cmd)
local trusted = session.get_trusted_table()
local server = 'server'
local player = game.player
local p
if player then
if player ~= nil then
p = player.print
if not player.admin then
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
return
end
else
p = log
end
if cmd.parameter == nil then return end
local target_player = game.players[cmd.parameter]
if target_player then
if trusted[target_player.name] == false then game.print(target_player.name .. " is already untrusted!") return end
trusted[target_player.name] = false
game.print(target_player.name .. " is now untrusted.", {r=0.22, g=0.99, b=0.99})
for _, a in pairs(game.connected_players) do
if a.admin == true and a.name ~= player.name then
a.print("[ADMIN]: " .. player.name .. " untrusted " .. target_player.name, {r = 1, g = 0.5, b = 0.1})
end
end
end
else
if cmd.parameter == nil then return end
local target_player = game.players[cmd.parameter]
if target_player then
if trusted[target_player.name] == false then game.print(target_player.name .. " is already untrusted!") return end
trusted[target_player.name] = false
game.print(target_player.name .. " is now untrusted.", {r=0.22, g=0.99, b=0.99})
end
end
end
)
local function process_bot_answers(event)
local player = game.players[event.player_index]
if player.admin == true then return end
local message = event.message
message = string.lower(message)
for word in string.gmatch(message, "%g+") do
if links[word] then
local player = game.players[event.player_index]
for _, bot_answer in pairs(links[word]) do
player.print(bot_answer, message_color)
end
return
end
end
end
local function on_console_chat(event)
if not event.player_index then return end
process_bot_answers(event)
end
--share vision of silent-commands with other admins
local function on_console_command(event)
if event.command ~= "silent-command" then return end
if not event.player_index then return end
local player = game.players[event.player_index]
for _, p in pairs(game.connected_players) do
if p.admin == true and p.name ~= player.name then
p.print(player.name .. " did a silent-command: " .. event.parameters, {r=0.22, g=0.99, b=0.99})
end
end
end
event.add(defines.events.on_player_created, on_player_created)
event.add(defines.events.on_console_chat, on_console_chat)
event.add(defines.events.on_console_command, on_console_command)