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.
Support & discussion of released scripts, and announcements of new releases.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Fri Mar 13, 2020 4:18 pm
i was wondering how to integrate a throttle check in this youtube title grabber of m00nies
ive seen examples for regular scripts but never in a namespace eval
Code: Select all
#########################################################################################
# Name m00nie::youtube
# Description Uses youtube v3 API to search and return videos
#
# Version 1.8 - Chanset +youtube now controls search access!
# 1.7 - Modify SSL params (fixes issues on some systems)
# 1.6 - Small correction to "stream" categorisation.....
# 1.5 - Added UTF-8 support thanks to CatboxParadox (Requires eggdrop
# to be compiled with UTF-8 support)
# 1.4 - Correct time format and live streams gaming etc
# 1.3 - Updated output to be RFC compliant for some IRCDs
# 1.2 - Added auto info grabber for spammed links
# 1.1 - Fixing regex!
# 1.0 - Initial release
# Website https://www.m00nie.com
# Notes Grab your own key @ https://developers.google.com/youtube/v3/
#########################################################################################
namespace eval m00nie {
namespace eval youtube {
package require http
package require json
package require tls
tls::init -tls1 true -ssl2 false -ssl3 false
http::register https 443 tls::socket
bind pub - !yt m00nie::youtube::search
bind pubm - * m00nie::youtube::autoinfo
variable version "1.8"
setudef flag youtube
variable key "GET-YOUR-OWN"
variable regex {(?:http(?:s|).{3}|)(?:www.|)(?:youtube.com\/watch\?.*v=|youtu.be\/)([\w-]{11})}
::http::config -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
proc autoinfo {nick uhost hand chan text} {
if {[channel get $chan youtube] && [regexp -nocase -- $m00nie::youtube::regex $text url id]} {
putlog "m00nie::youtube::autoinfo is running"
putlog "m00nie::youtube::autoinfo url is: $url and id is: $id"
set url "https://www.googleapis.com/youtube/v3/videos?id=$id&key=$m00nie::youtube::key&part=snippet,statistics,contentDetails&fields=items(snippet(title,channelTitle,publishedAt),statistics(viewCount),contentDetails(duration))"
set ids [getinfo $url]
set title [encoding convertfrom [lindex $ids 0 1 3]]
set pubiso [lindex $ids 0 1 1]
regsub {\.000Z} $pubiso "" pubiso
set pubtime [clock format [clock scan $pubiso]]
set user [encoding convertfrom [lindex $ids 0 1 5]]
# Yes all quite horrible...
set isotime [lindex $ids 0 3 1]
regsub -all {PT|S} $isotime "" isotime
regsub -all {H|M} $isotime ":" isotime
if { [string index $isotime end-1] == ":" } {
set sec [string index $isotime end]
set trim [string range $isotime 0 end-1]
set isotime ${trim}0$sec
} elseif { [string index $isotime 0] == "0" } {
set isotime "stream"
} elseif { [string index $isotime end-2] != ":" } {
set isotime "${isotime}s"
}
set views [lindex $ids 0 5 1]
puthelp "PRIVMSG $chan :\002\00301,00You\00300,04Tube\003\002 \002$title\002 by $user (duration: $isotime) on $pubtime, $views views"
}
}
proc getinfo { url } {
for { set i 1 } { $i <= 5 } { incr i } {
set rawpage [::http::data [::http::geturl "$url" -timeout 5000]]
if {[string length rawpage] > 0} { break }
}
putlog "m00nie::youtube::getinfo Rawpage length is: [string length $rawpage]"
if {[string length $rawpage] == 0} { error "youtube returned ZERO no data :( or we couldnt connect properly" }
set ids [dict get [json::json2dict $rawpage] items]
putlog "m00nie::youtube::getinfo IDS are $ids"
return $ids
}
proc search {nick uhost hand chan text} {
if {![channel get $chan youtube] } {
return
}
putlog "m00nie::youtube::search is running"
regsub -all {\s+} $text "%20" text
set url "https://www.googleapis.com/youtube/v3/search?part=snippet&fields=items(id(videoId),snippet(title))&key=$m00nie::youtube::key&q=$text"
set ids [getinfo $url]
set output "\002\00301,00You\00300,04Tube\003\002 "
for {set i 0} {$i < 5} {incr i} {
set id [lindex $ids $i 1 1]
set desc [encoding convertfrom [lindex $ids $i 3 1]]
set desc [string map -nocase [list "&" "&" "'" "'" """ "\""] $desc ]
set yout "https://youtu.be/$id"
append output "\002" $desc "\002 - " $yout " | "
}
set output [string range $output 0 end-2]
puthelp "PRIVMSG $chan :$output"
}
}
}
putlog "m00nie::youtube $m00nie::youtube::version loaded"
i usually use this took from member user on the forum
Code: Select all
proc throttled2 {id time} {
global throttled
if {[info exists throttled($id)]} {
return 1
} {
set throttled($id) [utimer $time [list unset throttled($id)]]
return 0
}
}
and check with if
Code: Select all
if {![throttled2 $chan:$chan 10]} { return 0 }
i altered it a bit
im not sure if this is the best and most reliable way of checking throttle channel wide and not per user
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Sat Mar 14, 2020 4:10 am
$chan instead of $chan:$chan in your if line will be more than enough and should work as you wanted.
Once the game is over, the king and the pawn go back in the same box.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sat Mar 14, 2020 8:42 am
Tnx for your reply caesar ive tried integrating it but couldn't get it to work it always returned errors i couldn't figure how to solve if i have time i will reproduce and post the errors here
Tnx.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sat Mar 14, 2020 9:24 am
this is how i have it atm
Code: Select all
#########################################################################################
# Name m00nie::youtube
# Description Uses youtube v3 API to search and return videos
#
# Version 1.8 - Chanset +youtube now controls search access!
# 1.7 - Modify SSL params (fixes issues on some systems)
# 1.6 - Small correction to "stream" categorisation.....
# 1.5 - Added UTF-8 support thanks to CatboxParadox (Requires eggdrop
# to be compiled with UTF-8 support)
# 1.4 - Correct time format and live streams gaming etc
# 1.3 - Updated output to be RFC compliant for some IRCDs
# 1.2 - Added auto info grabber for spammed links
# 1.1 - Fixing regex!
# 1.0 - Initial release
# Website https://www.m00nie.com
# Notes Grab your own key @ https://developers.google.com/youtube/v3/
#########################################################################################
namespace eval m00nie {
namespace eval youtube {
package require http
package require json
package require tls
tls::init -tls1 true -ssl2 false -ssl3 false
http::register https 443 tls::socket
bind pub - !yt m00nie::youtube::search
bind pubm - * m00nie::youtube::autoinfo
variable version "1.8"
setudef flag youtube
variable key "XXXXXXXXXXX"
variable regex {(?:http(?:s|).{3}|)(?:www.|)(?:youtube.com\/watch\?.*v=|youtu.be\/)([\w-]{11})}
::http::config -useragent "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
proc autoinfo {nick uhost hand chan text} {
if {![m00nie::throttled2 $chan 10]} { return 0 }
if {[regexp -nocase -- $m00nie::youtube::regex $text url id]} {
putlog "m00nie::youtube::autoinfo is running"
putlog "m00nie::youtube::autoinfo url is: $url and id is: $id"
set url "https://www.googleapis.com/youtube/v3/videos?id=$id&key=$m00nie::youtube::key&part=snippet,statistics,contentDetails&fields=items(snippet(title,channelTitle,publishedAt),statistics(viewCount),contentDetails(duration))"
set ids [getinfo $url]
set title [encoding convertfrom [lindex $ids 0 1 3]]
set pubiso [lindex $ids 0 1 1]
regsub {\.000Z} $pubiso "" pubiso
set pubtime [clock format [clock scan $pubiso]]
set user [encoding convertfrom [lindex $ids 0 1 5]]
# Yes all quite horrible...
set isotime [lindex $ids 0 3 1]
regsub -all {PT|S} $isotime "" isotime
regsub -all {H|M} $isotime ":" isotime
if { [string index $isotime end-1] == ":" } {
set sec [string index $isotime end]
set trim [string range $isotime 0 end-1]
set isotime ${trim}0$sec
} elseif { [string index $isotime 0] == "0" } {
set isotime "stream"
} elseif { [string index $isotime end-2] != ":" } {
set isotime "${isotime}s"
}
set views [lindex $ids 0 5 1]
#puthelp "PRIVMSG $chan :\002\00301,00You\00300,04Tube\003\002 \002$title\002 by $user (duration: $isotime) on $pubtime, $views views"
puthelp "PRIVMSG $chan :\00301,00You\00300,04Tube\003\017 $title by $user (duration: $isotime) on $pubtime, $views views"
}
}
proc throttled2 {id time} {
global throttled
if {[info exists throttled($id)]} {
return 1
} {
set throttled($id) [utimer $time [list unset throttled($id)]]
return 0
}
}
proc getinfo { url } {
for { set i 1 } { $i <= 1 } { incr i } {
set rawpage [::http::data [::http::geturl "$url" -timeout 5000]]
if {[string length rawpage] > 0} { break }
}
# putlog "m00nie::youtube::getinfo Rawpage length is: [string length $rawpage]"
if {[string length $rawpage] == 0} { error "youtube returned ZERO no data :( or we couldnt connect properly" }
set ids [dict get [json::json2dict $rawpage] items]
# putlog "m00nie::youtube::getinfo IDS are $ids"
return $ids
}
proc search {nick uhost hand chan text} {
putlog "m00nie::youtube::search is running"
regsub -all {\s+} $text "%20" text
set url "https://www.googleapis.com/youtube/v3/search?part=snippet&fields=items(id(videoId),snippet(title))&key=$m00nie::youtube::key&q=$text"
set ids [getinfo $url]
set output "\002\00301,08You\00308,05Tube\003\002\017 "
for {set i 0} {$i < 1} {incr i} {
set id [lindex $ids $i 1 1]
set desc [encoding convertfrom [lindex $ids $i 3 1 ]]
set desc [string map -nocase [list "&" "&" "'" "'" """ "\""] $desc ]
set yout "https://youtu.be/$id"
append output "" "" $desc " - " $yout " | "
#append output "\002" "\0035" $desc "\002 - " \0035 $yout " | "
}
set output [string range $output 0 end-2]
puthelp "NOTICE $nick :$output"
#puthelp "PRIVMSG $chan :$output"
}
}
}
putlog "m00nie::youtube $m00nie::youtube::version loaded"
only this time it doesnt throttle and no errors
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Sat Mar 14, 2020 4:33 pm
If you look at the initial post at user's example
here you will notice that you got that:
Code: Select all
if {![m00nie::throttled2 $chan 10]} { return 0 }
wrong.
Once the game is over, the king and the pawn go back in the same box.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sat Mar 14, 2020 7:46 pm
isnt that how u suppose to integrate that into namespace eval as im not really familiar with that
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Sun Mar 15, 2020 4:32 am
I meant if the throttled process returns 1 then you should 'pause' not the other way around.
Once the game is over, the king and the pawn go back in the same box.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sun Mar 15, 2020 8:41 am
i tried with return 1 and it didnt seem to throttle
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Sun Mar 15, 2020 3:57 pm
I meant you should drop the ! (exclamation mark) in the if line.
Once the game is over, the king and the pawn go back in the same box.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Sun Mar 15, 2020 5:00 pm
excellent that did it tnx caesar
m4s
Halfop
Posts: 97 Joined: Mon Jan 30, 2017 3:24 pm
Post
by m4s » Tue Mar 17, 2020 1:52 am
Hi simo!
Can you pls share the final script here?
Thank you!
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Tue Mar 17, 2020 2:08 am
Just remove the ! (exclamation mark) from this line:
Code: Select all
if {![m00nie::throttled2 $chan 10]} { return 0 }
cos that's what I told him to do.
Once the game is over, the king and the pawn go back in the same box.
simo
Revered One
Posts: 1108 Joined: Sun Mar 22, 2015 2:41 pm
Post
by simo » Tue Mar 17, 2020 1:43 pm
changing this:
Code: Select all
if {![m00nie::throttled2 $chan 10]} { return 0 }
into this:
Code: Select all
if {[m00nie::youtube::throttled2 $chan 10]} { return 0 }
and you should be good to go
Note: keep in mind this checks channel wide to throttle (not per user)
if u want to check per user u might want to do like this
Code: Select all
if {[m00nie::youtube::throttled2 $uhost:$chan 10]} { return 0 }
tnx again caesar.
m4s
Halfop
Posts: 97 Joined: Mon Jan 30, 2017 3:24 pm
Post
by m4s » Wed Mar 18, 2020 2:10 pm
Thanks caesar, simo.
This throttling means the users has 10 seconds to send youtube links to the channel?
m00nie
Voice
Posts: 14 Joined: Sat Mar 28, 2020 2:02 pm
Post
by m00nie » Sat Mar 28, 2020 2:05 pm
Hi all
I saw this and updated the script to include it as a configurable option for a per user and per channel limit. Newest version has the variables at the top
Hope it helps a little
Cheers
m00nie