Yeah that's what I'm doing at the moment, but it creates a ton of different files. Would be much cleaner (as you said) if a script like this could just read off a single text file. Also I imagine it could be adapted to many other things and have many other uses.tomekk wrote:you can make second file in the same directory or something, text file with rules 1 by 1
If you could do it so it reads a text file off the web that would work great.tomekk wrote:I can write TCL for you if want, but with txt file (its less work for me and for sure that will always work, 2nd thing, you can mod your html source without changing the TCL script code because its based on "clear" text file)
Code: Select all
# tomekk, http://forum.egghelp.org/viewtopic.php?t=16942
# commands channels
set file_web_channels {#channel #channel2}
# syntax: "channel_command_name|http://address/somefile"
set file_web_links {
"!rule|http://localhost/rules.txt"
"!test|http://localhost/test.txt"
}
#############################################################
bind pubm -|- * pub_proc
package require http
proc pub_proc { nick uhost hand chan arg } {
global file_web_links file_web_channels
if {[lsearch $file_web_channels $chan] == -1} {
return
}
set spt_args [split $arg]
set command_name [lindex $spt_args 0]
set command_data [lindex $spt_args 1]
if {![regexp {^([0-9]+)$} $command_data]} {
return
} {
set command_data [expr $command_data - 1]
if {$command_data <= -1} {
return
}
}
set the_url ""
foreach link_line $file_web_links {
if {$link_line != ""} {
set sep_rows [split $link_line "|"]
set ch_cmd_name [string trim [lindex $sep_rows 0]]
set ch_cmd_url [string trim [lindex $sep_rows 1]]
if {$command_name == $ch_cmd_name} {
set the_url $ch_cmd_url
}
}
}
if {$the_url != ""} {
if {![catch {set http_handle [http::geturl $the_url -timeout 10000]}]} {
set http_status [http::status $http_handle]
if {$http_status == "ok"} {
if {[http::ncode $http_handle] == 200} {
set http_data [http::data $http_handle]
set line_by_line [split $http_data "\n"]
if {$command_data <= [llength $line_by_line]} {
putquick "PRIVMSG $chan :[lindex $line_by_line $command_data]"
}
}
} elseif {$http_status == "timeout"} {
putquick "NOTICE $nick :error: connection timed out"
}
} {
putquick "NOTICE $nick :error: connection failed"
}
}
}
putlog "file-grabber.tcl ver 0.1 by tomekk loaded"
two diffrent files, with data line by line:20:31:19 <@tomekk> !rule 2
20:31:24 < botty> rules file line 2
20:31:29 <@tomekk> !test 3
20:31:29 < botty> test file line 3
[tomekk@zonk]:/home/www# cat rules.txt test.txt
rules file line 1
rules file line 2
rules file line 3
test file line 1
test file line 2
test file line 3
Code: Select all
set file_web_channels {#mabusbottest}
example, i used your host in my script ("!rule|http://www.dalnetdebates.com/rules.txt"):!rule <line number>
because, your 'rule.txt' file:09:22:59 <@tomekk> !rule 1
09:23:01 < botty> rules file line 1
09:23:03 <@tomekk> !rule 2
09:23:04 < botty> rules file line 2
09:23:06 <@tomekk> !rule 5
09:23:07 < botty> test file line 1
its working OK, remember, like u said, <command> <line number>rules file line 1 //line num 1
rules file line 2 //line num 2
rules file line 3 //line num 3
//line num 4
test file line 1 //line num 5
test file line 2 //line num 6
test file line 3 //line num 7
Code: Select all
# tomekk, http://forum.egghelp.org/viewtopic.php?t=16942
# commands channels
set file_web_channels {#channel #channel2}
# max "words" per line (it means: test test on. <- space separator, "test" "test" "on.", 3 "words" here)
set max_per_line 30
# syntax: "channel_command_name|http://address/somefile"
set file_web_links {
"!rule|http://localhost/rules.txt"
"!test|http://localhost/test.txt"
}
#############################################################
bind pubm -|- * pub_proc
package require http
proc pub_proc { nick uhost hand chan arg } {
global file_web_links file_web_channels max_per_line
if {[lsearch $file_web_channels $chan] == -1} {
return
}
set spt_args [split $arg]
set command_name [lindex $spt_args 0]
set command_data [lindex $spt_args 1]
if {![regexp {^([0-9]+)$} $command_data]} {
return
} {
set command_data [expr $command_data - 1]
if {$command_data <= -1} {
return
}
}
set the_url ""
foreach link_line $file_web_links {
if {$link_line != ""} {
set sep_rows [split $link_line "|"]
set ch_cmd_name [string trim [lindex $sep_rows 0]]
set ch_cmd_url [string trim [lindex $sep_rows 1]]
if {$command_name == $ch_cmd_name} {
set the_url $ch_cmd_url
}
}
}
if {$the_url != ""} {
if {![catch {set http_handle [http::geturl $the_url -timeout 10000]}]} {
set http_status [http::status $http_handle]
if {$http_status == "ok"} {
if {[http::ncode $http_handle] == 200} {
set http_data [http::data $http_handle]
set line_by_line [split $http_data "\n"]
if {$command_data <= [llength $line_by_line]} {
set line_list [split [lindex $line_by_line $command_data]]
set line_length [llength $line_list]
if {$line_length > $max_per_line} {
set parts [expr $line_length / $max_per_line]
if {[expr $parts * $max_per_line] < $line_length} {
incr parts 1
}
set start_idx 0
set end_idx [expr $max_per_line - 1]
for {set i 0} {$i < $parts} {incr i 1} {
putquick "PRIVMSG $chan :[join [lrange $line_list $start_idx $end_idx]]"
incr start_idx $max_per_line
incr end_idx $max_per_line
}
} {
putquick "PRIVMSG $chan :[lindex $line_by_line $command_data]"
}
}
}
} elseif {$http_status == "timeout"} {
putquick "NOTICE $nick :error: connection timed out"
}
} {
putquick "NOTICE $nick :error: connection failed"
}
}
}
putlog "file-grabber.tcl ver 0.1 by tomekk loaded"
10:39:21 <@tomekk> !rule 1
10:39:28 < botty> 1) Threats of any kind of violence towards any member of our channel is subject to immediate
and permanent removal from the channel. This includes any stalking behaviour that occurs
10:39:31 < botty> on our, or other channels our members happen to go on. This includes users following our
members into our channel from other channels to harrass them. Attempts to uncover personal
10:39:34 < botty> information about our users to use personal offline information about our users to in any way
embarrass or harm a user is strictly prohibited.
Code: Select all
# LINE_WRAP
# takes a long line in, and chops it before the specified length
# http://forum.egghelp.org/viewtopic.php?t=6690
#
proc line_wrap {str {splitChr { }}} {
set out [set cur {}]
set i 0
set len $::lineSplit
foreach word [split [set str][set str ""] $splitChr] {
if {[incr i [string length $word]] > $len} {
lappend out [join $cur $splitChr]
set cur [list $word]
set i [string length $word]
} else {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
}
Code: Select all
variable lineSplit 340
Code: Select all
if {$command_data <= [llength $line_by_line]} {
foreach splitline [line_wrap [lindex $line_by_line $command_data]] {
putserv "PRIVMSG $chan :$splitline"
}
}
Nah, it's just other way of doing the same action.speechles wrote:This looks very sketchy and amateur.
Code: Select all
# tomekk, http://forum.egghelp.org/viewtopic.php?t=16942
# commands channels
set file_web_channels {#channel #channel2}
# max chars per line (with full words, without spliting in the middle like: word wo\nrd word, will be: word word\nword, if possible)
variable lineSplit 340
# syntax: "channel_command_name|http://address/somefile"
set file_web_links {
"!rule|http://localhost/rules.txt"
"!test|http://localhost/test.txt"
}
#############################################################
bind pubm -|- * pub_proc
package require http
# LINE_WRAP
# takes a long line in, and chops it before the specified length
# http://forum.egghelp.org/viewtopic.php?t=6690
#
proc line_wrap {str {splitChr { }}} {
set out [set cur {}]
set i 0
set len $::lineSplit
foreach word [split [set str][set str ""] $splitChr] {
if {[incr i [string length $word]] > $len} {
lappend out [join $cur $splitChr]
set cur [list $word]
set i [string length $word]
} else {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
}
proc pub_proc { nick uhost hand chan arg } {
global file_web_links file_web_channels max_per_line
if {[lsearch $file_web_channels $chan] == -1} {
return
}
set spt_args [split $arg]
set command_name [lindex $spt_args 0]
set command_data [lindex $spt_args 1]
if {![regexp {^([0-9]+)$} $command_data]} {
return
} {
set command_data [expr $command_data - 1]
if {$command_data <= -1} {
return
}
}
set the_url ""
foreach link_line $file_web_links {
if {$link_line != ""} {
set sep_rows [split $link_line "|"]
set ch_cmd_name [string trim [lindex $sep_rows 0]]
set ch_cmd_url [string trim [lindex $sep_rows 1]]
if {$command_name == $ch_cmd_name} {
set the_url $ch_cmd_url
}
}
}
if {$the_url != ""} {
if {![catch {set http_handle [http::geturl $the_url -timeout 10000]}]} {
set http_status [http::status $http_handle]
if {$http_status == "ok"} {
if {[http::ncode $http_handle] == 200} {
set http_data [http::data $http_handle]
set line_by_line [split $http_data "\n"]
if {$command_data <= [llength $line_by_line]} {
foreach splitline [line_wrap [lindex $line_by_line $command_data]] {
putserv "PRIVMSG $chan :$splitline"
}
}
}
} elseif {$http_status == "timeout"} {
putquick "NOTICE $nick :error: connection timed out"
}
} {
putquick "NOTICE $nick :error: connection failed"
}
}
}
putlog "file-grabber.tcl ver 0.1 by tomekk loaded"