var debug : boolean := false
var irc, ran : int
var tmp, data, svrname : string := ""
var fnum : int
open : fnum, "file.dat", put
irc := Net.OpenConnection ("irc.avalonworks.ca", 6667)
put : irc, "USER echeese echeese echeese :echeese"
randint (ran, 1000, 9999)
put : irc, "NICK bot" + intstr (ran)
proc setcolor (col : int)
if col = 0 then
color (0)
elsif col = 1 then
color (7)
elsif col = 2 then
color (1)
elsif col = 3 then
color (2)
elsif col = 4 then
color (12)
elsif col = 5 then
color (4)
elsif col = 6 then
color (5)
elsif col = 7 then
color (6)
elsif col = 8 then
color (14)
elsif col = 9 then
color (10)
elsif col = 11 then
color (11)
elsif col = 12 then
color (9)
elsif col = 13 then
color (13)
elsif col = 14 then
color (15)
elsif col = 15 then
color (8)
else
color (7)
end if
end setcolor
proc colorize (data : string)
var j : int := 1
loop
exit when j = length (data) + 1
if (ord (data (j)) = 3) then
if j < length (data) then
if (ord (data (j + 1)) > 47) and (ord (data (j + 1)) < 58) and (ord (data (j + 2)) > 47) and (ord (data (j + 2)) < 58) then
setcolor (strint (data (j + 1)) * 10 + (strint (data (j + 2))))
j += 3
elsif (ord (data (j + 1)) > 47) and (ord (data (j + 1)) < 58) then
setcolor (strint (data (j + 1)))
j += 2
else
color (7)
j += 1
end if
else
j += 1
end if
else
put data (j) ..
j += 1
end if
end loop
color (7)
end colorize
function getw (s : string, separator : char, n : int) : string
var wi := 0
var s2 := ""
for i : 1 .. length (s)
if wi >= n then
if s (i) = separator then
result s2
end if
s2 += s (i)
end if
if s (i) = separator then
wi += 1
end if
end for
if s2 not= "" then
result s2
else
result ""
end if
end getw
function getws (s : string, separator : char, n : int) : string
var wi := 0
var s2 := ""
for i : 1 .. length (s)
if wi >= n then
s2 += s (i)
end if
if s (i) = separator then
wi += 1
end if
end for
if s2 not= "" then
result s2
else
result ""
end if
end getws
proc parse (data : string)
if getw (data, " ", 0) = "PING" then
put : irc, "PONG ", getws (data, " ", 1)
elsif getw (data, " ", 1) = "MODE" then
color (2)
put "* ", getw (data, " ", 0) (2 .. *), " sets mode: ", getws (data, " ", 2)
color (7)
elsif getw (data, " ", 1) = "JOIN" then
color (2)
put "* ", getw (data, "!", 0) (2 .. *), " has joined ", getws (data, " ", 2) (2 .. *)
color (7)
elsif getw (data, " ", 1) = "NICK" then
color (2)
put "* ", getw (data, "!", 0) (2 .. *), " is now known as ", getws (data, " ", 2) (2 .. *)
color (7)
elsif getw (data, " ", 1) = "001" then
put getws (data, " ", 3) (2 .. *)
svrname := getw (data, " ", 0) (2 .. *)
elsif getw (data, " ", 1) = "002" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "003" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "251" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "252" then
put getw (data, " ", 3), " " ..
put "IRC Ops online"
elsif getw (data, " ", 1) = "254" then
put getw (data, " ", 3), " " ..
put "channels formed"
elsif getw (data, " ", 1) = "255" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "265" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "266" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "372" then
put getws (data, " ", 3) (2 .. *)
elsif getw (data, " ", 1) = "375" then
put "Message of the day"
elsif getw (data, " ", 1) = "376" then
put : irc, "JOIN #bots"
elsif getw (data, " ", 1) = "PRIVMSG" then
put "<", getw (data, "!", 0) (2 .. *), ":", getw (data, " ", 2), "> " ..
tmp := getws (data, " ", 3) (2 .. *)
colorize (tmp)
put ""
elsif getw (data, " ", 1) = "NOTICE" then
color (4)
put "-", getw (data, "!", 0) (2 .. *), "- " ..
tmp := getws (data, " ", 3) (2 .. *)
colorize (tmp)
put ""
else
if debug = true then
put data
end if
end if
end parse
put : irc, "JOIN #bots"
loop
if Net.CharAvailable (irc) then
loop
get : irc, tmp : 1
exit when ord (tmp) = 10
if length (data) = 255 then
exit
else
data += tmp
end if
end loop
parse (data)
data := ""
end if
end loop
|