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.

Where have I gone wrong? (pubm)

Help for those learning Tcl or writing their own scripts.
Post Reply
D
D3FiANC3
Voice
Posts: 2
Joined: Sun Feb 01, 2009 7:52 am

Where have I gone wrong? (pubm)

Post by D3FiANC3 »

Putting aside the fact that I am a huge Tcl nooblet, where have I gone wrong here? It never binds. :oops:

Code: Select all

package require http
bind pubm - "#mychan *released*ago*" blowme

proc blowme {nick host handle channel text} {
 regsub -all {([\002\017\026\037]|[\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})} $text "" text
 regsub -all " " $text "+" text
 regsub -all "(" $text "%28" text
 regsub -all ")" $text "%29" text
if {$nick == "MrBot"} { 
  set url "http://www.myurl.com/gotime.php"
  set agent "Mozilla"
  set query "$url?prerls=$text"
  set page [http::config -useragent $agent]
  set page [http::geturl $query]
  set preinfo [http::data $page]
  upvar #0 $page state
  set max 0
 }
}
<MrBot> (BETA) Beta.v0.27 was released 20h 3m 22s ago
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I think if you explain what you are trying to do, it might help us to assist.

From what I can gather, if MrBot (not clear whether that is the botnick on which this script is loaded) says in #mychan something that matches *released*ago* then you attempt to strip text codes with a regsub (I can't see that working) then replace ) ( and " " with %29, %28 and + respectively to form a valid URL from the text. Then append the resultant text to http://www.myurl.com/gotime.php?prerls=

First off, use the Eggdrop Tcl command stripcodes to strip text formatting codes as follows :-

set text [stripcodes bcruag $text]

The channel text which you want the script to respond to is typically :-

<MrBot> (BETA) Beta.v0.27 was released 20h 3m 22s ago

I deduced from this that the URL would be :-

http://www.myurl.com/gotime.php?prerls= ... 3m+22s+ago

I pasted that into a browser and got nothing useful that might tell me what you are trying to do.

Quite aside from the success or otherwise of the coding inside the PUBM proc, if you wish to test if 'things' are happening you could temporarily add output statements at appropriate points. For example, if you want to see if the bind is triggering simply add this as the first line of code inside the proc (and watch the partyline for output) :-

putlog "bind triggered"

You can use this technique to find where your code fails, if there is not otherwise any Tcl error to be seen in the partyline.

A typical http useragent (from an MS Windows machine) would be :-

"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Your problem is likely case. You've bound to lowercase words and if any uppercase letters happen to be part of that it will not trigger. Try using something similar to how I've done it below. Let the procedure do the figuring with a series of string equal/matches. I've also correctly added the formatQuery for your text instead of your regsubbing () into html values. User agent shouldnt matter at all as this is your site, you can omit it if you want.

Code: Select all

package require http
bind pubm - "*" blowme

proc blowme {nick host handle channel text} {
  if {[string equal -nocase "mrbot" $nick] && \
    [string equal -nocase "#mychan" $chan] && \
    [string match -nocase "*released*ago*" $text]} {
    set url "http://www.myurl.com/gotime.php"
    set agent "Mozilla"
    set page [http::config -useragent $agent]
    set page [http::geturl $url -query [http::formatQuery prerls [stripcode brcuag $text]]]
    # if your using the above query to build a php database, you can remove the rest
    # below this, you don't need the page html or upvar...
    # dunno what max is.. might need that
    set preinfo [http::data $page]
    upvar #0 $page state
    set max 0
  }
}
Keep in mind, the entire contents of $text will be sent to your php. This is likely not what you want or perhaps is what you want. If it isn't what you want you will need to perform a regexp to extract the data you do want passed to your php.
arfer wrote:I deduced from this that the URL would be :-

http://www.myurl.com/gotime.php?prerls= ... 3m+22s+ago

I pasted that into a browser and got nothing useful that might tell me what you are trying to do.
Heh, myurl is likely a placeholder because that php places entries into a database. If poster had provided the correct url to add entries to his database this wouldn't exactly be the smartest thing to do. Since no useful data comes of this is why I advise the poster to drop the http::data statement and the upvar right after that, it's not needed.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

LOL!! OK, don't rub that one in. I never even saw that coming
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@speechles, masks of bindings do not care for case.
However, the manual check of the nickname is indeed case sensitive.

As for sanitizing the url for http:get, just use the ::http::formatQuery.

Code: Select all

package require http
bind pubm - "#mychan *released*ago*" blowme

proc blowme {nick host handle channel text} {
#drop all those hidious regsub's, just do as arfer suggested and scrub off colors/controlcodes
# regsub -all {([\002\017\026\037]|[\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})} $text "" text
# regsub -all " " $text "+" text
# regsub -all "(" $text "%28" text
# regsub -all ")" $text "%29" text
 set text [stripcodes $text bcruag]

#Lets do a proper test of the nickname, and throw in -nocase as illustrated by speechles.
 if {[string equal -nocase $nick "MrBot"} {

#Use the http-library to build your url, works alot better...
  set url "http://www.myurl.com/gotime.php?[::http::formatQuery prerls $text]"

  set agent "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
  set page [::http::config -useragent $agent]
  set page [::http::geturl $url]
  set preinfo [::http::data $page]

#I'm not quite sure what you intended here.. Care to try and explain?
  upvar #0 $page state
  set max 0

#Now, preinfo contains the webpage, but what to do now? Print it somewhere?
 }
} 
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

nml375 wrote:

Code: Select all

  set url "http://www.myurl.com/gotime.php?[::http::formatQuery prerls $text]"

  set agent "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
  set page [::http::config -useragent $agent]
  set page [::http::geturl $url]
  set preinfo [::http::data $page]
Wasn't aware that bindings were case insensitive, always assumed it was WYSIWYG.. thanks for clarifying that bit..

But, do you notice the lack of -timeout or -callback within the http::geturl. This is how most warez pre scripts operate. They do not need any html, they just need to send the query to the php engine which will append the release to the database.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

For some very odd reason, I tend to not keep track of the warez-scene :p
In any case, not having a -command (which I assume you were thinking of with -callback) argument means it is running in synchronous mode. That is, the ::http::geturl command will block until the whole webpage is loaded, or an error/abort condition occurs. The content of the retrieved data is then directly returned, rather than returning a http transaction token.

Whenever using the http package with eggdrops, use asynchronous mode, regardless of the script's use.
(No, I did not correct this in my earlier post, I was a lazy boy)
NML_375
D
D3FiANC3
Voice
Posts: 2
Joined: Sun Feb 01, 2009 7:52 am

Post by D3FiANC3 »

Thanks for all the replies. I also appreciate the explanations to go with the code - always better to learn so next time I can do for myself. I have fixed my errors and thrown the log line in to test it out.

The reason why my script sends the data to a php page is as you guessed, to add it to the DB. As for why it is sent unprocessed ... well that is simply because my PHP knowledge is advanced whereas my Tcl knowledge (as you can see) is amateurish.

Edit:

OK, here is the amended script.

Code: Select all

package require http
bind pubm - "#mychan *released*ago*" blowme

proc blowme {nick host handle channel text} {
 putlog "bind triggered"	
 set text [stripcodes bcruag $text]
if {[string equal -nocase "MrBot" $nick]} { 
  set url "http://www.myurl.com/gotime.php?[::http::formatQuery prerls $text]"
  set agent "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
  set page [::http::config -useragent $agent]
  set page [::http::geturl $url]
 }
}
All is well now. It seemed to be the $nick match. Even though I used the same case, the match failed. A case-insensitive match did it. Thanks again for the help and for the education. :) The script not only works but I feel better knowing I got rid of some of that junk also (which I knew was sloppy/wrong but I knew no other way).
Post Reply