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 

youtube tcl with protection

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Cr0ntab
Voice


Joined: 26 Mar 2010
Posts: 22

PostPosted: Sat Mar 19, 2011 3:45 am    Post subject: youtube tcl with protection Reply with quote

Hello. i would like a tcl that shows the artist and title of a youtube link when it is posted to a channel but with 2 main protections:
1. flood protection with limiting 1 link per 4-5sec
2. a protection that if the title has one of the words i set in the tcl the title is NOT shown in the channel and the user gets a notice that the title of the Youtube videoo has a forbidden word in it

Thank you
Back to top
View user's profile Send private message
arfer
Master


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

PostPosted: Mon Mar 21, 2011 10:21 am    Post subject: Reply with quote

Give this a try.

Code:

# youtitle.tcl
# to function in #channelname requires in the partyline .chanset #channelname +youtitle
# requires that coloured text can be displayed in #channelname (eg. not +c on DALnet)

###################################################################################################
########## configuration ##########################################################################

# set here the minimum time in seconds that must elapse before another channel input is parsed
set vYoutitleThrottleTime 5

# set here a list of words considered forbidden in YouTube video titles
set vYoutitleForbidden {
    dead
    sex
}

########## end of configuration ###################################################################
###################################################################################################

set vYoutitleVersion 11.03.20.17.47

package require http

setudef flag youtitle

set vYoutitleThrottled 0

bind PUBM - * pYoutitleTrigger

proc pYoutitleTrigger {nick uhost hand chan text} {
    global vYoutitleThrottled vYoutitleThrottleTime
    if {[channel get $chan youtitle]} {
        if {!$vYoutitleThrottled} {
            set vYoutitleThrottled 1
            utimer $vYoutitleThrottleTime pYoutitleRelease
            if {[regexp -nocase -- {youtube\.com/watch\?v\=([^\s]{11})} $text -> link]} {
                pYoutitleParse $nick $chan $link
            }
        }
    }
    return 0
}

proc pYoutitleParse {nick chan link} {
    global vYoutitleForbidden
    set url http://www.youtube.com/watch?v=$link
    set agent [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"]
    if {![catch {set token [::http::geturl $url -timeout 10000]}]} {
        switch -- [::http::status $token] {
            ok {
                switch -- [::http::ncode $token] {
                    200 {
                        set data [::http::data $token]
                        regexp -nocase -- {<span id=\"eow-title\"[^>]+>([^<]+)</span>} $data -> title
                        if {[info exists title]} {
                            set title [regsub -all -- {[\t\n]} $title ""]
                            set title [regsub -all -- {\:} $title " - "]
                            set title [string trim [regsub -all -- {[\s]{2,}} $title " "]]
                            set title [string map -nocase {\&\#39; \x27 &amp; \x26 &quot; \x22} $title]
                            foreach word $vYoutitleForbidden {
                                if {[regexp -nocase -- [subst -nobackslashes {(\A|\s)${word}(\s|\Z)}] $title]} {
                                    putserv "NOTICE $nick :forbidden word(s) detected in the title of your YouTube link"
                                    return 0
                                }
                            }
                            set page You\00300,04Tube\003
                            putserv "PRIVMSG $chan :$page $title"
                        } else {}
                    }
                    default {}
                }
            }
            default {}
        }
        ::http::cleanup $token
    }
    return 0
}

proc pYoutitleRelease {} {
    global vYoutitleThrottled
    set vYoutitleThrottled 0
    return 0
}

putlog "youtitle.tcl version $vYoutitleVersion loaded"

# eof


** edited 21/03/11 14:14pm to translate html ampersands **
_________________
I must have had nothing to do
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 -> Script Requests 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