############################################
# Eggdrop TCL - Berita & Olahraga Indonesia
# Author: ChatGPT
############################################
package require http
# ====== SETTING ======
set news_timeout 10000
# RSS FEEDS
array set rss {
detik "https://rss.detik.com/index.php/detikcom"
kompas "https://www.kompas.com/rss"
olahraga "https://rss.detik.com/index.php/sepakbola"
bola "https://www.bola.com/rss"
ligalokal "https://rss.detik.com/index.php/sepakbola/ligaindonesia"
pialadunia "https://www.fifa.com/rss-feeds/news"
}
# ====== COMMAND BIND ======
bind pub - !detik pub_detik
bind pub - !kompas pub_kompas
bind pub - !olahraga pub_olahraga
bind pub - !bola pub_bola
bind pub - !ligalokal pub_ligalokal
bind pub - !pialadunia pub_pialadunia
# ====== FUNCTION ======
proc fetch_rss {url} {
set token [http::geturl $url -timeout 10000]
set data [http::data $token]
http::cleanup $token
set items {}
foreach line [split $data "\n"] {
if {[regexp {
} $line -> title]} {
if {$title ne "" && $title ne "Detik.com"} {
lappend items $title
}
}
}
return $items
}
# ====== COMMAND HANDLER ======
proc send_news {nick chan source title} {
set news [fetch_rss $source]
if {[llength $news] == 0} {
putserv "PRIVMSG $chan :Gagal mengambil berita 😢"
return
}
putserv "PRIVMSG $chan :📰 $title"
set count 0
foreach item $news {
putserv "PRIVMSG $chan :• $item"
incr count
if {$count >= 3} break
}
}
# ====== PUB COMMAND ======
proc pub_detik {nick host hand chan text} {
send_news $nick $chan $::rss(detik) "Berita Terbaru Detik"
}
proc pub_kompas {nick host hand chan text} {
send_news $nick $chan $::rss(kompas) "Berita Terbaru Kompas"
}
proc pub_olahraga {nick host hand chan text} {
send_news $nick $chan $::rss(olahraga) "Berita Olahraga"
}
proc pub_bola {nick host hand chan text} {
send_news $nick $chan $::rss(bola) "Berita Bola"
}
proc pub_ligalokal {nick host hand chan text} {
send_news $nick $chan $::rss(ligalokal) "Bola Dalam Negeri"
}
proc pub_pialadunia {nick host hand chan text} {
send_news $nick $chan $::rss(pialadunia) "Piala Dunia"
}
putlog "TCL Berita & Bola loaded successfully"