-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathafk.lua
87 lines (78 loc) · 2.55 KB
/
afk.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
local chat = peripheral.find("chatBox")
local config
local function clear()
term.clear()
term.setCursorPos(1,1)
end
local function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
local function check(list_words,list_triggers)
for k,v in pairs(list_words) do
for k2,v2 in pairs(list_triggers) do
if v == v2 then
return true
end
end
end
return false
end
if fs.exists("/afk.txt") then
local configfile = io.open("/afk.txt","r")
config = textutils.unserialise(configfile:read("*a"))
configfile:close()
else
local newconfig = {}
print("no config!")
os.sleep(0.5)
clear()
print("Username:")
newconfig.username = io.read()
clear()
print("Triggers: (separated by \",\")")
newconfig.triggers = split(io.read(),",")
clear()
print("Computer Name:")
newconfig.displayname = io.read()
clear()
print("Message to Send:")
print("(Vars: %user% %author%)")
newconfig.message = io.read()
local configfile = io.open("/afk.txt","w")
configfile:write(textutils.serialise(newconfig))
configfile:close()
config = newconfig
end
local afkEnabled = true
while true do
local _, username, message, _, isHidden = os.pullEvent("chat")
message = message:lower()
local cmd = split(message," ")
if isHidden and username == config.username then
if cmd[1] == "afk" then
if cmd[2] == "on" then
afkEnabled = true
chat.sendMessageToPlayer("AFK Enabled",username,config.displayname)
elseif cmd[2] == "off" then
afkEnabled = false
chat.sendMessageToPlayer("AFK Disabled",username,config.displayname)
elseif cmd[2] == "toggle" then
afkEnabled = not afkEnabled
chat.sendMessageToPlayer("AFK Toggled ("..tostring(afkEnabled)..")",username,config.displayname)
end
end
elseif check(cmd,config.triggers) and username ~= config.username then
local newmsg = config.message
newmsg = newmsg:gsub("%%user%%","%%s")
newmsg = string.format(newmsg,config.username)
newmsg = newmsg:gsub("%%author%%","%%s")
newmsg = string.format(newmsg,username)
chat.sendMessage(newmsg,config.displayname)
os.sleep(1.1)
chat.sendMessageToPlayer("§cYou have been mentionned by §6"..username,config.username,config.displayname)
end
end