| View previous topic :: View next topic |
| Author |
Message |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Sun Feb 03, 2008 3:49 pm Post subject: Probably simple.. But. I cant do it.. |
|
|
I am new to tcl, but need to write a simple script.. Basically, I am running a irc server for a webhost company.. We do our support there, and have a bot setup to handle some things. I need a script that when someone messages it in private, or notice a command like GETINFO <NICKNAME> it will go to a web site, i.e. http://www.mysite.com/getuserinfo.php?login=NICKNAME and get the output, (i've already got this part covered) the page returns information in the form of:
hostingtype,serverid,username,domain,hostpackage,suspended
Basically, I need it to either return that to the requesting user in a message or notice and either parse it like
Hosting type: hostingtype
Server ID: serverid
Username: username
Account Domain: domain
Hosting Package: hostingpackage
Account Suspended: accountsuspended
Or, if thats too complicated, just return the whole string to the user and i'll tell them how to read it. I've tried several things, but can't get it. |
|
| Back to top |
|
 |
Maiki Voice
Joined: 20 May 2007 Posts: 28
|
Posted: Sun Feb 03, 2008 4:03 pm Post subject: |
|
|
| If you would give me the website.. Or the page of the soucrce, i will make it for you. |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Mon Feb 04, 2008 7:49 pm Post subject: |
|
|
Sorry i've taken so long.. they are going to change it up alittle, we haven't got the site done yet, but now it's going to be like the bot goes to http://www.somesite.com/somepage.php?login=LOGIN where the person messages or notices the bot with GETINFO <nick>, i'd like to restrict this to ops on a channel, but thats not really required. basically, the site is going to output like this now: (no html tags)
cPanel Login: <login>
Domain Name: <domain>
Hosting type <type>
Account type: <type>
Suspended: Yes/No
Server ID: <id>
Could you possibly get a simple script that just reads the lines of the page, and sends them back to the person who requested it in either privmsg or notice?
Thanks for your help. |
|
| Back to top |
|
 |
Maiki Voice
Joined: 20 May 2007 Posts: 28
|
Posted: Tue Feb 05, 2008 6:19 am Post subject: |
|
|
| Code: |
if {[catch {package require http} error]} { putlog "Failed loading error= $error" }
bind pub - getinfo info
proc info {nick uhost hand chan arg} {
if {![isop $nick $chan]} { putmsg $chan "No acces to use this script"; return }
if {$arg == ""} { putmsg $chan "Wrong syntax. \"GETINFO nick\""; return }
set url "http://www.somesite.com/somepage.php?login=$arg"
set tok [http::geturl $url]
set data [http::data $tok]
http::cleanup $tok
regexp -- {cPanel Login:(.+?)} $data -> login
regexp -- {Domain Name:(.+?)} $data -> domain
regexp -- {Hosting type:(.+?)} $data -> type
regexp -- {Account type:(.+?)} $data -> account
regexp -- {Suspended:(.+?)} $data -> suspended
regexp -- {Server ID:(.+?)} $data -> id
if {![info exists ::login]} { putmsg $chan "No info available"; return }
putmsg $nick "$login,$domain,$type,$account,$suspended,$id"
}
|
Last edited by Maiki on Wed Feb 06, 2008 6:29 am; edited 1 time in total |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Tue Feb 05, 2008 4:26 pm Post subject: |
|
|
| Very nice, thank you alot! |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Tue Feb 05, 2008 8:00 pm Post subject: |
|
|
caused an error:
[18:57] <x10Helper> [18:58] Tcl error [info]: bad option "rpope904": must be args, body, cmdcount, commands, complete, default, exists, functions, globals, hostname, level, library, loaded, locals, nameofexecutable, patchlevel, procs, script, sharedlibextension, tclversion, or vars
any ideas? thanks again. |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Tue Feb 05, 2008 11:18 pm Post subject: |
|
|
| Code: | bind pub - getinfo info
...snipped irrelevant parts...
proc getinfo {nick uhost hand chan arg} { |
see the problem? change the part below and it will properly bind getinfo to the proc getinfo | Code: | | bind pub - getinfo getinfo |
|
|
| Back to top |
|
 |
Maiki Voice
Joined: 20 May 2007 Posts: 28
|
Posted: Wed Feb 06, 2008 6:29 am Post subject: |
|
|
| speechles wrote: | | Code: | bind pub - getinfo info
...snipped irrelevant parts...
proc getinfo {nick uhost hand chan arg} { |
see the problem? change the part below and it will properly bind getinfo to the proc getinfo | Code: | | bind pub - getinfo getinfo |
|
Oopsie, i noticed it to late i guess :p |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Feb 06, 2008 1:36 pm Post subject: |
|
|
| Code: | if {[catch {package require http} error]} { putlog "HTTP package required '$error'" }
bind pub - getinfo getinfo
# GET Info
# Grabs your server data, etc, etc
#
proc getinfo {nick uhost hand chan text} {
if {[isop $nick $chan]} {
if {$text == ""} {
putserv "privmsg $nick :Wrong syntax. \"GETINFO <nick>\""
} else {
set tok [http::geturl "http://www.somesite.com/somepage.php?login=[urlencode $text]"]
set html [http::data $tok]
http::cleanup $tok
regexp -nocase -- {cPanel Login:(.+?) Domain Name:(.+?) Hosting type:(.+?) Account type:(.+?) Suspended:(.+?) Server ID:(.+?)} $data -> login domain type account suspended id
if {![info exists $login]} {
putserv "privmsg $nick :No info available for $text."
) else {
putserv "privmsg $nick :[join [list $login $domain $type $account $suspended $id] ", "]"
}
}
}
}
# URL Encode
# Encodes anything not a-zA-Z0-9 into %00 strings...Pimp-Style
#
proc urlencode {text} {
set url ""
foreach byte [split [encoding convertto utf-8 $text] ""] {
scan $byte %c i
if {$i < 65 || $i > 122} {
append url [format %%%02X $i]
} else {
append url $byte
}
}
return [string map {%3A : %2D - %2E . %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 \[ %5B \\ %5C \] %5D \^ %5E \_ %5F \` %60} $url]
}
##defeat-word-wrap#################################################################################################################################################################### |
Try this, since all your stuff is on one line Maiki's regexp's will be very greedy and not do what you want. I've also used putserv for messaging, eliminated all those returns, and stopped it from giving a "you have no access" response if a non-op tries to trigger the script, no response is better. Also included is a pimp-style url encoder.. keke
@metroid, how does it look now?
edit: corrected missing " which lead to the tcl interpreter giving the missing closing brace error, is now corrected.
Last edited by speechles on Wed Feb 06, 2008 5:26 pm; edited 11 times in total |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Wed Feb 06, 2008 1:54 pm Post subject: |
|
|
| You should modify info because it'll overwrite the default TCL proc like that. |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Wed Feb 06, 2008 4:12 pm Post subject: |
|
|
Yeah, the second one did cause an error..
[14:25] <x10Helper> [14:26] Tcl error in file './eggdrop.conf':
[14:25] <x10Helper> [14:26] missing close-brace
[14:25] <x10Helper> while executing
[14:25] <x10Helper> "proc getinfo2 {nick uhost hand chan text} {
[14:25] <x10Helper> if {[isop $nick $chan]} {
[14:25] <x10Helper> if {$text == ""} {
[14:25] <x10Helper> putserv "privmsg $nick :Wrong syntax. \"GETINFO <..."
[14:25] <x10Helper> (file "scripts/uinfo2.tcl" line 9)
[14:25] <x10Helper> invoked from within
[14:25] <x10Helper> "source scripts/uinfo2.tcl"
[14:25] <x10Helper> (file "./eggdrop.conf" line 1342)
[14:25] <x10Helper> [14:26] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
DCC session closed
On the first one, I changed the output on the site to one line because I had it printing a <pre> tag first, \n wont work with php echo, and I wasn't sure how the bot would handle a <br> tag on each line.. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Feb 06, 2008 5:20 pm Post subject: |
|
|
| Try the edited version above and it'll work, promise. |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Wed Feb 06, 2008 5:39 pm Post subject: |
|
|
| thats the one I tried, gonna give it another shot. |
|
| Back to top |
|
 |
rpope904 Voice
Joined: 02 Feb 2008 Posts: 16
|
Posted: Wed Feb 06, 2008 5:43 pm Post subject: |
|
|
copied and pasted again, exactly as you had it, did a .rehash:
[16:42] <x10Helper> [16:43] Tcl error in file './eggdrop.conf':
[16:42] <x10Helper> [16:43] missing close-brace
[16:42] <x10Helper> while executing
[16:42] <x10Helper> "proc getinfo {nick uhost hand chan text} {
[16:42] <x10Helper> if {[isop $nick $chan]} {
[16:42] <x10Helper> if {$text == ""} {
[16:42] <x10Helper> putserv "privmsg $nick :Wrong syntax. \"GETINFO <n..."
[16:42] <x10Helper> (file "scripts/uinfo2.tcl" line 8)
[16:42] <x10Helper> invoked from within
[16:42] <x10Helper> "source scripts/uinfo2.tcl"
[16:42] <x10Helper> (file "./eggdrop.conf" line 1342)
[16:42] <x10Helper> [16:43] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
DCC session closed |
|
| Back to top |
|
 |
|