forked from hjpotter92/ptokax-scripts
-
Notifications
You must be signed in to change notification settings - Fork 11
/
startup.lua
163 lines (147 loc) · 5.13 KB
/
startup.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
154
155
156
157
158
159
160
161
162
163
--[[
This file is part of HiT Hi FiT Hai's PtokaX scripts
Copyright: © 2014 HiT Hi FiT Hai group
Licence: GNU General Public Licence v3 https://www.gnu.org/licenses/gpl-3.0.html
--]]
function OnStartup()
tConfig = {
sBotName = SetMan.GetString( 21 ),
sAsBot = "<"..( SetMan.GetString(21) or "PtokaX" ).."> ",
sPath = Core.GetPtokaXPath().."scripts/",
sFunctionsFile = "functions.lua",
sGeneralMenu = "clickMenu.txt",
sPickleFile = "pickle.lua",
sNotifyFunctionFile = "notify.lua",
sAllowedProfiles = "01237",
tIndividualMenu = {
["[BOT]Offliner"] = "offlinerMenu.txt",
["[BOT]Info"] = "infoMenu.txt",
["[BOT]GameServer"] = "gameServerMenu.txt",
["#[ChatRoom]"] = "roomsMenu.txt",
},
tFiles = {
lostnfound = "lost.txt",
notices = "notice.txt",
trainplace = "tnp.txt",
}
}
tPaths = {
sTextPath = tConfig.sPath.."texts/",
sFunctionsPath = tConfig.sPath.."dependency/",
sExternalPath = tConfig.sPath.."external/",
}
local sTextPath, sFunctionsPath = tPaths.sTextPath, tPaths.sFunctionsPath
dofile( sFunctionsPath..tConfig.sFunctionsFile )
dofile( sFunctionsPath..tConfig.sPickleFile )
dofile( tPaths.sExternalPath..tConfig.sNotifyFunctionFile )
local tFileHandles = {
fGeneral = io.open( sTextPath..tConfig.sGeneralMenu, "r+" ),
fOffliner = io.open( sTextPath..tConfig.tIndividualMenu["[BOT]Offliner"], "r+" ),
fInfo = io.open( sTextPath..tConfig.tIndividualMenu["[BOT]Info"], "r+" ),
fGameServer = io.open( sTextPath..tConfig.tIndividualMenu["[BOT]GameServer"], "r+" ),
fChatrooms = io.open( sTextPath..tConfig.tIndividualMenu["#[ChatRoom]"], "r+" )
}
sGeneral, tMenuText = tFileHandles.fGeneral:read("*a"), {
["[BOT]Offliner"] = tFileHandles.fOffliner:read("*a"):gsub("%%%[bot%]", "[BOT]Offliner"),
["[BOT]Info"] = tFileHandles.fInfo:read("*a"):gsub("%%%[bot%]", "[BOT]Info"),
["[BOT]GameServer"] = tFileHandles.fGameServer:read("*a"),
["#[ChatRoom]"] = tFileHandles.fChatrooms:read("*a"),
}
for _, fHandle in pairs( tFileHandles ) do
fHandle:close()
end
tFileHandles, tConfig.tIndividualMenu, sTempPath = nil, nil, nil
Core.SendToAll( sGeneral )
for sAbout, sCommand in pairs(tMenuText) do
Core.SendToAll( sCommand )
end
end
function UserConnected( tUser )
for sName, sFile in pairs( tConfig.tFiles ) do
local fHandle = io.open( tPaths.sTextPath..sFile, "r+" )
if fHandle then
dofile( tPaths.sTextPath..tConfig.tFiles[sName] )
fHandle:close()
Core.SendPmToUser( tUser, tConfig.sBotName, CreateMessage(tTemp) )
tTemp = nil
end
end
Core.SendToUser( tUser, sGeneral )
for sAbout, sCommand in pairs(tMenuText) do
Core.SendToUser( tUser, sCommand )
end
end
OpConnected, RegConnected = UserConnected, UserConnected
function ChatArrival( tUser, sMessage )
local sCommand, sData = sMessage:match "%b<> [%!%#%?%.%+%-%/%*](%w+)%s?(.*)|"
if not sCommand or not ( sCommand == "check" or sCommand == "addto" or sCommand == "removefrom" ) then
return false
end
local tBreak, Result, sError = Explode( sData ), nil, nil
if not tBreak[1] then
Core.SendToUser( tUser, tConfig.sAsBot.."No argument passed." )
return false
end
sCommand = sCommand:lower()
tBreak[1] = tBreak[1]:lower()
if sCommand == "check" then
if tBreak[1] == "lnf" or tBreak[1] == "lostnfound" then
Result, sError = SendFile("lostnfound")
elseif tBreak[1] == "notice" or tBreak[1] == "notices" then
Result, sError = SendFile("notices")
elseif tBreak[1] == "tnp" then
Result, sError = SendFile("trainplace")
end
elseif sCommand == "addto" then
if not tBreak[2] then
Core.SendToUser( tUser, tConfig.sAsBot.."No message was provided." )
return false
end
local bSendToAll = false
if tBreak[#tBreak] == "-m" then
bSendToAll = true
table.remove( tBreak, #tBreak )
end
local sMsg = table.concat( tBreak, " ", 2 )
if tBreak[1] == "lnf" or tBreak[1] == "lostnfound" then
Result, sError = StoreMessage( "lostnfound", sMsg )
elseif tBreak[1] == "notice" or tBreak[1] == "notices" then
Result, sError = StoreMessage( "notices", sMsg )
elseif tBreak[1] == "tnp" then
Result, sError = StoreMessage( "trainplace", sMsg )
end
if bSendToAll and Result then
Core.SendToAll( tConfig.sAsBot..sMsg )
end
elseif sCommand == "removefrom" then
if not tonumber(tBreak[2]) then
Core.SendToUser( tUser, tConfig.sAsBot.."No ID was passed." )
return false
end
tBreak[2] = tonumber(tBreak[2])
if tBreak[1] == "lnf" or tBreak[1] == "lostnfound" then
Result, sError = RemoveMessage( "lostnfound", tBreak[2] )
elseif tBreak[1] == "notice" or tBreak[1] == "notices" then
Result, sError = RemoveMessage( "notices", tBreak[2] )
elseif tBreak[1] == "tnp" then
Result, sError = RemoveMessage( "trainplace", tBreak[2] )
end
end
if sError then
Core.SendToUser( tUser, tConfig.sAsBot..sError )
return true
end
if Result then
Core.SendToUser( tUser, tConfig.sAsBot..Result )
InformAll()
return true
end
return false
end
function ToArrival( tUser, sMessage )
local sTo = sMessage:match "^$To: (%S+) From:"
if sTo ~= tConfig.sBotName or not tConfig.sAllowedProfiles:find( tUser.iProfile ) then
return false
end
return ChatArrival( tUser, sMessage:match "%b$$(.*)" )
end