egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Where have I gone wrong? (pubm)

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
D3FiANC3
Voice


Joined: 01 Feb 2009
Posts: 2

PostPosted: Sun Feb 01, 2009 8:37 am    Post subject: Where have I gone wrong? (pubm) Reply with quote

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

Code:

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
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Feb 01, 2009 11:27 am    Post subject: Reply with quote

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=%28BETA%29+Beta.v0.27+was+released+20h+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)"
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Feb 01, 2009 11:54 am    Post subject: Reply with quote

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:
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=%28BETA%29+Beta.v0.27+was+released+20h+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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Feb 01, 2009 12:43 pm    Post subject: Reply with quote

LOL!! OK, don't rub that one in. I never even saw that coming
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Feb 01, 2009 1:26 pm    Post subject: Reply with quote

@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:
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Feb 01, 2009 1:42 pm    Post subject: Reply with quote

nml375 wrote:
Code:
  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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Feb 01, 2009 2:04 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
D3FiANC3
Voice


Joined: 01 Feb 2009
Posts: 2

PostPosted: Sun Feb 01, 2009 2:59 pm    Post subject: Reply with quote

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:

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. Smile 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).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber