This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Dynamic Script help

Old posts that have not been replied to for several years.
Locked
x
xiphrex
Voice
Posts: 5
Joined: Fri Apr 29, 2005 8:42 pm

Dynamic Script help

Post by xiphrex »

Hello,

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"
I would like to know how to go about making this script dynamic. All help is appreciated, thank you.
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Code: Select all

foreach chan [channels] {
    if{ $chan = "dynamic1"} { ... do some stuff ... }
    if{ $chan = "dynamic2"} { ... do some different stuff ... }
}
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
x
xiphrex
Voice
Posts: 5
Joined: Fri Apr 29, 2005 8:42 pm

Post by xiphrex »

Hi thanks for the reply.

I tried what you said but it doesnt matter what channel I do the command in, it will just do what it says in the last { }.

Here is the modified code:

Code: Select all

set main "#lostsanity"
set pmain "#ls-war"
set eva "#xippy"
set peva "#xippy"

bind pub -|- !nextmatch proc:nextmatch

package require http 
proc proc:nextmatch {nick host handle chan content} {
global pmain main eva peva
foreach chan [channels] {
	if {$chan == $main || $chan == $pmain} {set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]}
	if {$chan == $eva || $chan == $peva} {set matches [http::data [http::geturl "http://xidesign.net/evanextmatch.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"

}
It will just display the information from "http://xidesign.net/evanextmatch.php" even though according to that foreach loop it should get the information from "http://xidesign.net/nextmatch.php" in the channels $main and $pmain.

Any ideas?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

try removing the foreach loop, from what i understand about your purpose its redudant and only overwrites $chan and $matches
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
x
xiphrex
Voice
Posts: 5
Joined: Fri Apr 29, 2005 8:42 pm

Post by xiphrex »

If I remove the foreach loop, Im left with the same code I started off with. I think the foreach idea should work but for some reason its ignoring my if {} inside it and just carrying out the last {} whatever the channel.

Is there a way to make it detect the channel the command is being issues in, and when it does it sets the match variable according to that channel and then exits the loop and runs the rest of the procedure?
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

ok lets try it this way.

Code: Select all

set main "#lostsanity"
set pmain "#ls-war"
set eva "#xippy"
set peva "#xippy"

bind pub -|- !nextmatch proc:nextmatch

package require http
proc proc:nextmatch {nick host handle chan content} {
global pmain main eva peva

    set origin $chan

    switch -- $origin {
        "$pmain" {
            set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]
        }
        "$main" {
            set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]
        }
        "$eva" {
            set matches [http::data [http::geturl "http://xidesign.net/evanextmatch.php"]]
        }
        "$peva" {
            set matches [http::data [http::geturl "http://xidesign.net/evanextmatch.php"]]
        }
        default {
            putserv "NOTICE $nick :Unrecognised channel Please see my admin"
        }
    }

    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"

}
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
x
xiphrex
Voice
Posts: 5
Joined: Fri Apr 29, 2005 8:42 pm

Post by xiphrex »

Nice one man!

It doesnt work as you have shown since it doesnt evaluate the variables before running, even when in quotes. So I just changed the variable to an actual channel like #lostsanity without the quotes and it works perfect.

Good job, thanks to all who helped!
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

ahh doh was off the top of my head and wasn't tested but glad you fixed it :)
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

User once helped me with that problem, its rather simple, the vars wont be evaluated within th {} baces, so remove them:

Code: Select all

    switch -- $origin \
        $pmain {
            set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]
        } \
        $main {
            set matches [http::data [http::geturl "http://xidesign.net/nextmatch.php"]]
        } \
        $eva {
            set matches [http::data [http::geturl "http://xidesign.net/evanextmatch.php"]]
        } \
        $peva {
            set matches [http::data [http::geturl "http://xidesign.net/evanextmatch.php"]]
        } \
        default {
            putserv "NOTICE $nick :Unrecognised channel Please see my admin"
        }
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked