r00t-err0r

Eggdrop YouTube by munZe (TCL8.5)

Apr 27th, 2013
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.92 KB | None | 0 0
  1. ######################################
  2. # Youtube TCL v1.1 by munZe         ##
  3. # Requed TCL 8.5 or remove $uploaded #
  4. ######################################
  5.  
  6. bind pubm - *youtu.be/* YouTube
  7.  
  8. bind pubm - *youtube.com/watch*v=* YouTube
  9.  
  10. proc YouTube {nick host hand chan text} {
  11.  
  12. if {[checkUserAbuse $nick $chan] == "1"} {
  13.  
  14. set ytid [regexp -all -inline -nocase {([A-Za-z0-9_-]{11})} $text]; set ytid [lindex $ytid 0]
  15. set url "http://gdata.youtube.com/feeds/api/videos/$ytid?v=2&alt=jsonc&prettyprint=true"
  16. set token [ ::http::geturl $url ]; set page [ ::http::data $token ]
  17. ::http::cleanup $token
  18. set duration [regexp -all -inline {"duration": (.*?),} $page]; set duration [lindex $duration 1]; set duration [clock format $duration -gmt 1 -format %H:%M:%S]
  19. set title [regexp -all -inline {"title": "(.*?)",} $page]; set title [lindex $title 1]
  20. set likes [regexp -all -inline {"likeCount": "(.*?)",} $page]; set likes [lindex $likes 1]
  21. set views [regexp -all -inline {"viewCount": (.*?),} $page]; set views [lindex $views 1]
  22. set uploader [regexp -all -inline {"uploader": "(.*?)",} $page]; set uploader [lindex $uploader 1]
  23. set uploaded [regexp -all -inline {"uploaded": "(.*?)",} $page]; set uploaded [lindex $uploaded 1]; set uploaded [clock scan $uploaded -format {%Y-%m-%dT%H:%M:%S.000Z}]; set uploaded [clock format $uploaded -format {%d.%m.%Y}]
  24. putserv "PRIVMSG $chan :Youtube - Title: \002$title\002 - Duration: \002$duration\002 - Likes: \002$likes\002 - Views: \002$views\002 - Uploaded by: \002$uploader\002 - Uploaded: \002$uploaded\002"
  25.  
  26. }
  27.  
  28. }
  29.  
  30. ######################
  31. #   Flood protect    #
  32. ######################
  33.  
  34. set floodTime 10
  35. set floodmsg 3
  36. set banDuration 10
  37.  
  38. proc initCmdUser {host time} {
  39.    global usersbanovani
  40.    set usersbanovani($host) [list 0 [list $time]]
  41.    return
  42. }
  43.  
  44. proc checkUserAbuse {nick chan} {
  45.    set host [getchanhost $nick $chan]
  46.    global usersbanovani banDuration floodTime floodmsg
  47.    set time [unixtime]
  48.    if {![array exists usersbanovani]} {
  49.       initCmdUser $host $time
  50.       return 1
  51.    }
  52.    set seenNick 0
  53.    foreach user [array names usersbanovani] {
  54.       if {$user == $host} {set seenNick 1; break}
  55.    }
  56.    if {$seenNick == 0} {
  57.       initCmdUser $host $time
  58.       return 1
  59.    }
  60.    if {[lindex $usersbanovani($host) 0] != 0} {
  61.       if {[lindex $usersbanovani($host) 0] <= $time} {
  62.      array set usersbanovani [list $host [list 0 [list $time]]]
  63.          return 1
  64.       }
  65.       return 0
  66.    }
  67. set messages {}
  68.    foreach m [lindex $usersbanovani($host) 1] {
  69.       if {[expr $time-$m] <= $floodTime} {
  70.      lappend messages $m
  71.       }
  72.    }
  73.    lappend messages $time
  74.    array set usersbanovani [list $host [list 0 $messages]]
  75.    if {[llength $messages] > $floodmsg} {
  76.     set host [getchanhost $nick]
  77.  
  78.       array set usersbanovani [list $host [list [expr $time+($banDuration*60)] {}]]
  79.       return 0
  80.    }
  81.    return 1
  82. }
  83. ######################
  84.  
  85. putlog "Loaded YouTube TCL v1.1 by munZe"
Advertisement
Add Comment
Please, Sign In to add comment