<speechles> !bible mark 4:1-9
<sp33chy> Mark 4:1-9 (Today's New International Version)
<sp33chy> Mark 4. The Parable of the Sower.
<sp33chy> 1) Again Jesus began to teach by the lake. The crowd that gathered around him was so large that he got into a boat and sat in it out on the lake, while all the people were along the shore at the water's edge.
<sp33chy> 2) He taught them many things by parables, and in his teaching said:
<sp33chy> 3) "Listen! A farmer went out to sow his seed.
<sp33chy> 4) As he was scattering the seed, some fell along the path, and the birds came and ate it up.
<sp33chy> 5) Some fell on rocky places, where it did not have much soil. It sprang up quickly, because the soil was shallow.
<sp33chy> 6) But when the sun came up, the plants were scorched, and they withered because they had no root.
<sp33chy> 7) Other seed fell among thorns, which grew up and choked the plants, so that they did not bear grain.
<sp33chy> 8) Still other seed fell on good soil. It came up, grew and produced a crop, some multiplying thirty, some sixty, some a hundred times."
<sp33chy> 9) Then Jesus said, "Whoever has ears to hear, let them hear."
<speechles> !bible genesis 4:12
<sp33chy> Genesis 4:12 (Today's New International Version)
<sp33chy> 12) When you work the ground, it will no longer yield its crops for you. You will be a restless wanderer on the earth."
Code: Select all
# BibleGateway Example using EggHttp via speechless
# freeware - feel free to use any part of this script for any purpose.
# To enable this script requires one of 2 methods below:
# 1) some chans: on dcc partyline, type: .chanset #yourchan +bible
# 2) all bot chans: on dcc partyline, type .chanset * +bible
# NOTE: Code is purposely over commented to explain each section.
# Config
set pubtrigger "!bible"
set pubspeed 5
# End of config
# script begins with egghttp check
if {![info exists egghttp(version)]} {
putlog "egghttp.tcl was NOT successfully loaded."
putlog "biblegateway.tcl has not been loaded as a result."
} else {
proc biblegateway {sock} {
global url
global chan2
set headers [egghttp:headers $sock]
set body [egghttp:data $sock]
# remove all newlines, carriage returns, tabs, and vertical tabs
regsub -all {(?:\n|\r|\t|\v)} $body "" body
# grab the title and if success, change into space
# if fails, set title accordingly
if {[regexp {<h3>(.+?)</h3>} $body - title]} {
# change into space
regsub -all { } $title " " title
} else {
# if no title is found we must set one
set title "No Title"
}
# grab the subtitle and other relevant subtitles
# gather them into a single line.
if {[regexp {<p><h.*?>(.+?)<span id} $body - moretitle]} {
# these end each subtitle, changing them to . allows
# them to fit on one line, in a sort-of sentence.
regsub -all {</h.>} $moretitle ". " moretitle
# replace non-breaking space tags with true spaces.
regsub -all { } $moretitle " " moretitle
# remove all remaining html tags.
regsub -all {<.*?>} $moretitle "" moretitle
} else {
# some valid pages have no subtitles
# so if none is found, we will just set it blank.
set moretitle ""
}
# message title and subtitles.
putserv "privmsg $chan2 :$title"
putserv "privmsg $chan2 :$moretitle"
# reset pubspeed counter
set count 0
# while we have text, let's recurse the loop
while {[regexp -- {<span id.*?">(.+?)<span} $body - line]} {
# increment pubspeed counter
incr count
# remove from the $body the regexp leader
# so that the same exact segment can never
# match twice.
regsub -- {<span id.*?">} $body "" body
# each verse number is encased within span tags
# changing the end tag to a parenthesis cleans up text
regsub -all {</span>} $line "\)" line
# this combination should be dealt with first
regsub -all {\[<.*?>\]} $line "" line
# now remove the rest of the html tags
regsub -all {<.*?>} $line "" line
# this non-breaking space is for web display
# irrelevant on irc, let's remove it
regsub -all { } $line "" line
# pubspeed check, if exceeded puthelp
if {$count > $::pubspeed} {
puthelp "privmsg $chan2 :$line"
} else {
putserv "privmsg $chan2 :$line"
}
}
}
# bind pub
bind pub -|- $::pubtrigger our:pubtrigger
# channel flag
setudef flag bible
proc our:pubtrigger {nick uhand hand chan text} {
global url
global chan2
set chan2 $chan
# if bible isn't set for the channel, return and do nothing
if {[lsearch -exact [channel info $chan] +bible] == -1} {return}
# set the url using urlencode function based on $text
set url "http://www.biblegateway.com/passage/?search=[our:urlencode $text]&version=72"
# call bible
set sock [egghttp:geturl $url biblegateway]
}
# convert text into html approved % codes.
proc our:urlencode {text} {
set aurl ""
foreach byte [split [encoding convertto utf-8 $text] ""] {
scan $byte %c i
if {$i < 65 || $i > 122} {
append aurl [format %%%02X $i]
} else {
append aurl $byte
}
}
return [string map {%3A : %2D - %2E . %30 0 %31 1 %32 2 %33 3 %34 4 %35 5 %36 6 %37 7 %38 8 %39 9 \[ %5B \\ %5C \] %5D \^ %5E \_ %5F \` %60} $aurl]
}
putlog "biblegateway.tcl has been successfully loaded."
}
Tested & works, doing the lords work.. haw.. pubspeed is the amount of lines which will be putserved, the rest will be puthelped. If you find the bot getting excess flooded off IRC, lower it. If you find the bot is too slow to display everything, raise it.
You will now need to develop some kind of flood protection as well as some kind of error detection mechanism, other than that here you go, enjoy..
Note: inline regexp with a foreach would've been nice to use, but it isn't possible with how the page is built. The while loop is the way to do it in this case.