-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathircbot.lua
More file actions
274 lines (254 loc) · 8.61 KB
/
Copy pathircbot.lua
File metadata and controls
274 lines (254 loc) · 8.61 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
--dofile("A:/LUA/ircbot.lua")
print("[++++]First Start")
--filepathdir="C:/Users/Nickoplier/Dropbox/FORMATTINGSAVE/LUA/TheYouSrslyBot"
botmoderators={} --Bot Host Names DONT ADD HERE, IT IS ADDED ON BOTMODS.LUA
fullnameindex={} --When someone chats, their nick is added here for future reference.
ignorehosts={} --When someone requests to be ignored by the bot, host is added.
isbotforcednotice=false --Is the bot required to always use notice?
isbotinhushmode=false --Is the bot in a hush mode?
isbotinnoticetriggermode=false --Require the bot to use notices if a trigger was found.
isbotinnoticemode=false --Require the bot to be in full notice mode..
isbotletsrollblockedwait={}
isbotletsrollwinner={"botfilefail"}
--Don't modify Required to stay for default operation, Modification may fuck bot up.
botforcereboot=false --Scripted variable to force hault.
botforcerefresh=false --Scripted variable to force chatted refresh.
isbothushdatalastmsgtime=0 --For hush lastmsg os.timeout
isbothushdatahushlength=30 --For default 30 seconds of hush.
--oldpackagepath=package.path
--package.path = filepathdir..'/?.lua;' .. package.path
require("settings")
do --TableSave and Load functions.
-- declare local variables
--// exportstring( string )
--// returns a "Lua" portable version of the string
local function exportstring( s )
return string.format("%q", s)
end
--// The Save Function
function table.save( tbl,filename )
local charS,charE = " ","\n"
local file,err = io.open( filename, "wb" )
if err then return err end
-- initiate variables for save procedure
local tables,lookup = { tbl },{ [tbl] = 1 }
file:write( "return {"..charE )
for idx,t in ipairs( tables ) do
file:write( "-- Table: {"..idx.."}"..charE )
file:write( "{"..charE )
local thandled = {}
for i,v in ipairs( t ) do
thandled[i] = true
local stype = type( v )
-- only handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables, v )
lookup[v] = #tables
end
file:write( charS.."{"..lookup[v].."},"..charE )
elseif stype == "string" then
file:write( charS..exportstring( v )..","..charE )
elseif stype == "number" then
file:write( charS..tostring( v )..","..charE )
end
end
for i,v in pairs( t ) do
-- escape handled values
if (not thandled[i]) then
local str = ""
local stype = type( i )
-- handle index
if stype == "table" then
if not lookup[i] then
table.insert( tables,i )
lookup[i] = #tables
end
str = charS.."[{"..lookup[i].."}]="
elseif stype == "string" then
str = charS.."["..exportstring( i ).."]="
elseif stype == "number" then
str = charS.."["..tostring( i ).."]="
end
if str ~= "" then
stype = type( v )
-- handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables,v )
lookup[v] = #tables
end
file:write( str.."{"..lookup[v].."},"..charE )
elseif stype == "string" then
file:write( str..exportstring( v )..","..charE )
elseif stype == "number" then
file:write( str..tostring( v )..","..charE )
end
end
end
end
file:write( "},"..charE )
end
file:write( "}" )
file:close()
end
--// The Load Function
function table.load( sfile )
local ftables,err = loadfile( sfile )
if err then return _,err end
local tables = ftables()
for idx = 1,#tables do
local tolinki = {}
for i,v in pairs( tables[idx] ) do
if type( v ) == "table" then
tables[idx][i] = tables[v[1]]
end
if type( i ) == "table" and tables[i[1]] then
table.insert( tolinki,{ i,tables[i[1]] } )
end
end
-- link indices
for _,v in ipairs( tolinki ) do
tables[idx][v[2]],tables[idx][v[1]] = tables[idx][v[1]],nil
end
end
return tables[1]
end
-- close do
end
do --Load data tables..
local function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
if file_exists("BotMods")==false then
table.save(botmoderators,"BotMods")
end
if file_exists("TimeoutWaitRoll")==false then
table.save(isbotletsrollblockedwait,"TimeoutWaitRoll")
end
if file_exists("TimeoutWaitWin")==false then
table.save(isbotletsrollwinner,"TimeoutWaitWin")
end
botmoderators=table.load("BotMods")
isbotletsrollblockedwait=table.load("TimeoutWaitRoll")
isbotletsrollwinner=table.load("TimeoutWaitWin")
end
function CheckPerm(p)
local ok=false
for a=1,#botmoderators do
if p==botmoderators[a] then
ok=true
end
end
return ok
end
function SendRAWMessage(msg)
IRCSend(msg)
end
function SendMessage(msg,nick,torr,channel,forces,wasatrigger)
if (channel=="NickoplierBot" and torr=="NOTICE") or forces==true then
IRCSend("NOTICE "..nick.." :NOTICE: "..msg)
elseif channel:sub(1,1)~="#" then
IRCSend(torr.." "..nick.." :MSG: "..msg)
else
if isbotinnoticemode==true then
IRCSend("NOTICE "..nick.." :FNM:|"..nick..": "..msg)
elseif (isbotinnoticetriggermode==true and wasatrigger==true) then
IRCSend("NOTICE "..nick.." :FNMT|"..nick..": "..msg)
elseif isbotinhushmode==true then
if isbothushdatalastmsgtime>tonumber(os.time()) then
IRCSend("NOTICE "..nick.." :HUSH|"..nick..": "..msg)
else
IRCSend(torr.." "..channel.." :"..nick..": "..msg)
isbothushdatalastmsgtime=tonumber(os.time())+isbothushdatahushlength
end
else
IRCSend(torr.." "..channel.." :"..nick..": "..msg)
end
end
end
Chatted=require("chatted")
----------------------
----------------------
--Begin bot receiver--
----------------------
----------------------
do
local copas = require("copas")
local socket = require("socket")
do --Global
local skt=nil
local host=irc.host
local port=irc.port
local channel=irc.channel
local nickname=irc.nickname
local password=irc.password
local connected=false
local buffer=""
local err=""
skt = socket.tcp()
skt:settimeout(3) -- forgot to add optimization to prevent CPU load.
skt:connect(host, port)
function IRCSend(data)
skt:send(data.."\r\n")
print("[+++]Send Message ".. data)
io.flush()
end
while true do
local buffer, err = skt:receive("*l")
--print("[++]G Receive ",buffer,err)
if err=="closed" or botforcereboot==true then
error("im done..")
elseif err == nil or err == "timeout" then
if connected==false then
print("[++]Sent connection data.")
IRCSend("NICK "..nickname)
connected = true
end
end
if botforcerefresh==true then
botforcerefresh=false
Chatted=function() end;
Chatted=nil;
package.loaded['chatted'] = nil
Chatted=require("chatted")
print("Forced the refresh..")
end
if buffer ~= nil then
io.flush()
if string.sub(buffer,1,4) == "PING" then
print("[++]Ping Request")
IRCSend(string.gsub(buffer,"PING","PONG",1))
else
print("[++] '"..buffer.."'")
userhostname, cmd, param = string.match(buffer, "^:([^ ]+) ([^ ]+)(.*)$")
--print("[++]DataReceive: ".. buffer .." \n")
if cmd == "NOTICE" and param:sub(1,16)==" AUTH :*** No Id" then
IRCSend("USER testing 0 * Testing")
IRCSend("NAME "..nickname)
IRCSend("JOIN "..channel)
end
user, userhost = string.match(buffer,"^([^!]+)!(.*)$")
if user~=":jtv" and user~=nil then
--io.write("|irc.lua|>Subcontent: ".. buffer .." \n")
prefix, cmd, param = string.match(buffer, "^:([^ ]+) ([^ ]+)(.*)$")
if prefix~=nil and cmd~=nil and param~=nil then
param1, msg = string.match(param,"^([^:]+) :(.*)$")
if msg~=nil then
local channel=param1:sub(2)
user=user:sub(2)
do
local num=userhostname:match("^.*()@")
userhostname=userhostname:sub(num+1)
end
print("[++]G "..user..":"..msg)
Chatted(userhostname,user,msg,cmd,channel) --Host, Nick, Message, Type, Channel
end
end
end
end
end
end
end
end