-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.lua
More file actions
107 lines (98 loc) · 3.02 KB
/
Copy pathscript.lua
File metadata and controls
107 lines (98 loc) · 3.02 KB
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
io.output(io.stdout)
Client = IRC.Client()
local test = function(f,s) if f then print(s) else return true end end
if test(Client:Init(), "Socket initialized") then return end
if test(Client:Connect("Burstfire.UK.EU.GameSurge.net", 6667), "Connected to IRC; Logging in") then return end
if test(Client:Login("robottie", "robottie"), "Logged in") then return end
function table.contains(table, element)
for key, value in pairs(table) do
if key == element then
return true
end
end
return false
end
function split(p,d)
local t, ll
t={}
ll=0
if(#p == 1) then return {p} end
while true do
l=string.find(p,d,ll,true)
if l~=nil then
table.insert(t, string.sub(p,ll,l-1))
ll=l+1
else
table.insert(t, string.sub(p,ll))
break
end
end
return t
end
function string.slice(array, S, E)
local result = {}
local length = #array
S = S or 1
E = E or length
if E < 0 then
E = length + E + 1
elseif E > length then
E = length
end
if S < 1 or S > length then
return {}
end
local i = 1
for j = S, E do
result[i] = array[j]
i = i + 1
end
return result
end
local channels = {}
local sendType = function(t,n,s,...)
local msg = "requests a " .. t
if s and s ~= "" then msg = msg .. " at " .. Tracker.GetSeggestion(s) end
if #{...} > 0 and ({...})[1] ~= "" then msg = msg .. " (" .. table.concat({...}, " ") .. ")" end
for i,c in pairs(channels) do
Client:Send("PRIVMSG " .. c .. " :" .. n .. " " .. msg .. "; join #sauercom to respond")
end
end
local commands = {
duel = function(user, channel, server, ...)
sendType("duel", user.Nick:c_str(), server, ...)
end,
clanwar = function(user, channel, server, ...)
sendType("clanwar", user.Nick:c_str(), server, ...)
end,
mix = function(user, channel, server, ...)
sendType("mix", user.Nick:c_str(), server, ...)
end,
help = function(user)
Client:Send("NOTICE " .. user.Nick:c_str() .. " :Commands: .duel .clanwar .mix | Usage: .command <server> [list of comments]")
end
}
function is_valid_command(cmd)
return table.contains(commands, cmd)
end
local pcount = false
local hooks = {
PRIVMSG = function(self, msg)
parts = split(msg.Parameters:at(1):c_str(), " ")
if string.sub(parts[1], 1, 1) == "." then
local cmd, args = string.gsub(parts[1], ".", "", 1), string.slice(parts, 2)
if is_valid_command(cmd) then
commands[cmd](msg.Prefix, msg.Parameters:at(0):c_str(), table.unpack(args))
end
end
end,
["396"] = function() if pcount then return end; pcount = true; for k,i in pairs({"sauercom", "novi", "vaq", "rC", "impressivesquad"}) do Client:Send("JOIN #" .. i) end end,
CTCP = function(self, msg) Client:Send("NOTICE " .. msg.Prefix.Nick:c_str() .. " :\001VERSION C++ Lua bot by gear4 \001") end,
JOIN = function(self, msg) if msg.Prefix.Nick:c_str() == "robottie" then channels[#channels + 1] = msg.Parameters:at(0):c_str() end end
}
for h,c in pairs(hooks) do
Client:Hook(h, c)
end
while true do
Client:Receive()
end