I have a made a script that gets information from my website and puts it in an IRC channel when someone says something (like !edrank or !nextmatch).
However, it only works for one channel or a pair of channels - I want to make the script multi-channel so that it grabs different information from the website according to what channel the user requested it from.
So for example, the !nextmatch in #channel.a would be different from the !nextmatch in #channel.b. However I dont know how to do this and have tried to read about namespaces but have become more confused. Ideally I want the script to be dynamic so that I would only need to set a couple new variables mentioning the channel and url to the webpage that the info need to be grabbed from for that channel.
Here is the script that works atm, but when I load a replica of this script with changed variables, the one that has been loaded last overwrites the previous script so only one script works.
Code: Select all
##
## Lost Sanity Clan bot script by xiphrex
##
set main "#lostsanity"
set pchan "#ls-war"
set vent "212.42.13.171"
set ventport "9807"
set ventpass "password"
set ladderid "35"
set clanid "18931"
set division "CSS: Premier"
bind pub -|- !nextmatch proc:nextmatch
bind pub -|- !displaymatch proc:displaymatch
bind pub -|- !lastresult proc:lastresult
bind pub -|- !vent proc:vent
bind pub -|- !edrank proc:edrank
package require http
proc proc:nextmatch {nick host handle chan content} {
global pchan main
if {$chan == $main || $chan == $pchan} {
set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]
regsub -all "\n" $matches "" matches
regexp "<NAME>(.*)</NAME>" $matches match name
regexp "<DESC>(.*)</DESC>" $matches match desc
regexp "<SERVER>(.*)</SERVER>" $matches match server
regexp "<TIME>(.*)</TIME>" $matches match time
regexp "<TYPE>(.*)</TYPE>" $matches match type
regexp "<URL>(.*)</URL>" $matches match url
regexp "<STATUS>(.*)</STATUS>" $matches match status
putserv "NOTICE $nick :\002\00315,1 Nextmatch:\002\0030,1 $name \002"
putserv "NOTICE $nick :\002\00315,1 Time/Date:\002\0030,1 $time \002"
putserv "NOTICE $nick :\002\00315,1 Server:\002\0030,1 $server \002"
putserv "NOTICE $nick :\002\00315,1 Type:\002\0030,1 $type \002"
putserv "NOTICE $nick :\002\00315,1 Details:\002\0030,1 $desc \002"
putserv "NOTICE $nick :\002\00315,1 URL:\002\0030,1 $url \002"
putserv "NOTICE $nick :\002\00315,1 Status:\002\0030,1 $status \002"
}
}
proc proc:displaymatch {nick host handle chan content} {
global pchan main
if {![isop $nick $chan]} {
puthelp "NOTICE $nick : You are not allowed to view this content!"
} else {
if {$chan == $main || $chan == $pchan} {
set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]
regsub -all "\n" $matches "" matches
regexp "<NAME>(.*)</NAME>" $matches match name
regexp "<DESC>(.*)</DESC>" $matches match desc
regexp "<SERVER>(.*)</SERVER>" $matches match server
regexp "<TIME>(.*)</TIME>" $matches match time
regexp "<TYPE>(.*)</TYPE>" $matches match type
regexp "<URL>(.*)</URL>" $matches match url
regexp "<STATUS>(.*)</STATUS>" $matches match status
putserv "PRIVMSG $pchan :\002\00315,1 Nextmatch:\002\0030,1 $name \002"
putserv "PRIVMSG $pchan :\002\00315,1 Time/Date:\002\0030,1 $time \002"
putserv "PRIVMSG $pchan :\002\00315,1 Server:\002\0030,1 $server \002"
putserv "PRIVMSG $pchan :\002\00315,1 Type:\002\0030,1 $type \002"
putserv "PRIVMSG $pchan :\002\00315,1 Details:\002\0030,1 $desc \002"
putserv "PRIVMSG $pchan :\002\00315,1 URL:\002\0030,1 $url \002"
putserv "PRIVMSG $pchan :\002\00315,1 Status:\002\0030,1 $status \002"
}
}
}
proc proc:lastresult {nick host handle chan content} {
global pchan main
if {$chan == $main || $chan == $pchan} {
set matches [http::data [http::geturl "http://clan-a.iqcss.co.uk/r_last_match.php"]]
regsub -all "\n" $matches "" matches
regexp "<DESC>(.*)</DESC>" $matches match desc
regexp "<RESULT>(.*)</RESULT>" $matches match result
regexp "<TIME>(.*)</TIME>" $matches match time
regexp "<TYPE>(.*)</TYPE>" $matches match type
regexp "<TEAM>(.*)</TEAM>" $matches match team
regexp "<MAP>(.*)</MAP>" $matches match map
putserv "PRIVMSG $chan :\002\00315,1 Last Match:\002\0030,1 $desc \002"
putserv "PRIVMSG $chan :\002\00315,1 Result:\002\0030,1 $result \002"
putserv "PRIVMSG $chan :\002\00315,1 Time/Date:\002\0030,1 $time \002"
putserv "PRIVMSG $chan :\002\00315,1 Type:\002\0030,1 $type \002"
putserv "PRIVMSG $chan :\002\00315,1 Team:\002\0030,1 $team \002"
putserv "PRIVMSG $chan :\002\00315,1 Map:\002\0030,1 $map \002"
}
}
proc proc:vent {nick host handle chan content} {
global vent ventport ventpass main pchan
if {![isop $nick $chan]} {
puthelp "NOTICE $nick : You are not allowed to view this content!"
} else {
if {$chan == $main} {
putserv "NOTICE $nick :\00315,1 Do !vent in #ls-war \002"
} else {
if {$chan == $pchan} {
putserv "PRIVMSG $pchan :\002\00315,1 Vent IP:\002\0030,1 $vent \002\00315,1 Port:\002\0030,1 $ventport \002\00315,1 Password:\002\0030,1 $ventpass \002"
}
}
}
}
proc proc:edrank {nick host handle chan content} {
global ladderid clanid division main pchan
set content [http::data [http::geturl "http://www.enemydown.co.uk/ed_clanrank.php?ladder=$ladderid&clan=$clanid"]]
if {[regexp "<b>(.*)</b>" $content match rank] } {
regsub -all {<.+?>} $match {} match
if {$chan == $main || $chan == $pchan} {
puthelp "PRIVMSG $chan :\002\00315,1 Enemy Down \0037,1::\002\00315,1 $division Ladder \002\0037,1::\002\00315,1 Rank:\002\0030,1 $match \002"
}
}
}
putlog "lostsanity.tcl v1.5 has been successfully loaded. EDrank by Stoo"