| View previous topic :: View next topic |
| Author |
Message |
ZEXEL Halfop

Joined: 27 Jun 2006 Posts: 45
|
Posted: Tue Nov 11, 2008 4:35 am Post subject: How to put console/terminal text into channel |
|
|
I've some mini hash calculator for texts but it's run only under console/terminal. How can I put the result of that's into the channel.
in console/terminal, I type:
| Code: | [kingkong@pine eggdrop]$ ./htext The quick brown fox jumps over the lazy dog
~Mini Hash by ranDoM v1.3~
>> Input Texs: The quick brown fox jumps over the lazy dog
>> Adler32: DA0FDC5B
>> SHA1: 2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12
>> CRC32: 61EE9D45
>> MD5: 9E107D9D372BB6826BD81D3542A419D6
>> GOST: 77B7FA410C9AC58A25F49BCA7D0468C9296529315EACA76BD1A10F376D1F4294
>> RIPE128: 3FA9B57F053C053FBE2735B2380DB596
--- done ---
[kingkong@pine eggdrop]$ |
example (i want):
| Code: | | <@Yuppy>!hash The quick brown fox jumps over the lazy dog |
and output:
| Code: | <+bothash>Input: The quick brown fox jumps over the lazy dog
<+bothash>SHA1: 2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12 | MD5: 9E107D9D372BB6826BD81D3542A419D6 | CRC32: 61EE9D45 | Adler32: DA0FDC5B |
Hopefully you all can help me and write the tcl for it, and thank you...  _________________ .:[ Knowledge Is The Power ]:.
Last edited by ZEXEL on Wed Nov 12, 2008 12:27 am; edited 4 times in total |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
|
| Back to top |
|
 |
ZEXEL Halfop

Joined: 27 Jun 2006 Posts: 45
|
Posted: Wed Nov 12, 2008 12:24 am Post subject: |
|
|
@TCL_no_TK
I've used it, but unformatted and multiple texts will show in the channel if I use that.
more help please...  _________________ .:[ Knowledge Is The Power ]:. |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed Nov 12, 2008 7:48 am Post subject: |
|
|
| ZEXEL wrote: | @TCL_no_TK
I've used it, but unformatted and multiple texts will show in the channel if I use that.
more help please...  |
Use eval as suggested. Stuff the results into a variable. Then use regexp, regsub or scan to "parse" the things you want out of it. This is exactly the same as parsing html pages only a bit easier because the output is predictable and doesn't change. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Nov 12, 2008 3:59 pm Post subject: |
|
|
I'd do something like below:
Code is untested, let me know if there's any errors..
| Code: | bind pub - !hash do_hash
proc do_hash {nick host handle channel text} {
set f_id [open "|./htext $text"]
fconfigure $f_id -blocking 0
fileevent $f_id readable [list ParseHtext $f_id $channel]
set ::t_list($f_id) [list]
set ::t_input($f_id) $text
}
proc ParseHtext {socket channel} {
if {[gets $socket line] < 0} {
if {[eof $socket]} {
close $socket
puthelp "PRIVMSG $channel :Input: $::t_input($socket)"
puthelp "PRIVMSG $channel :[join $::t_list($socket) " | "]"
unset ::t_list($socket)
unset ::t_input($socket)
return
}
} else {
if {[regexp -- {>> ([[:alnum:]]+): ([[:xdigit:]]+)} $line text key value] == 1} {
lappend ::t_list($socket) "$key: $value"
}
}
} |
Edit: Bummer using wrong variable, fixed now..
Edit: Another variable bummer, fixed now... _________________ NML_375, idling at #eggdrop@IrcNET
Last edited by nml375 on Fri Nov 14, 2008 12:22 pm; edited 2 times in total |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Wed Nov 12, 2008 5:04 pm Post subject: |
|
|
| nml375 wrote: | | Code: | | set f_id [open "|./htext $text"] |
|
It might be a good idea to limit access to this command (require some flag) or filter/escape the contents of $text  _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Nov 12, 2008 6:26 pm Post subject: |
|
|
Point taken. Would be worth mentioning that would apply any use of external command invocation (such as with exec). Same concern should be taken when using eval mentioned earlier aswell.
Unfortunately, the old trick of using lists is only reliable within a tcl-environment, and is of limited use with exec and/or open.
As for filtering/escaping contents, the pipe and redirection tokens documented in the manpage for exec would be the major concern to escape. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
ZEXEL Halfop

Joined: 27 Jun 2006 Posts: 45
|
Posted: Wed Nov 12, 2008 10:06 pm Post subject: little error |
|
|
@TCL_no_TK, @speechles thx for suggestion
@nml375, thx for the script
@user, nice tips and tricks
I got error in console/terminal when trying to get result from the channel:
| Code: | can't read "t_input(#finger)": no such variable
while executing
"puthelp "PRIVMSG $channel :Input: $t_input($channel)""
(procedure "ParseHtext" line 5)
invoked from within
"ParseHtext file8 #finger" |
Is that mean I must add variabel channel at $t_input($channel) ?
thx you very much for your help... _________________ .:[ Knowledge Is The Power ]:. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Nov 13, 2008 2:16 pm Post subject: |
|
|
Nah, just means I made a bummer mixing up variables... fixed now. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
ZEXEL Halfop

Joined: 27 Jun 2006 Posts: 45
|
Posted: Fri Nov 14, 2008 2:28 am Post subject: |
|
|
| nml375 wrote: | | Nah, just means I made a bummer mixing up variables... fixed now. |
it's look stop processing at:
| Code: | can't read "t_input(file8)": no such variable
while executing
"puthelp "PRIVMSG $channel :Input: $t_input($socket)""
(procedure "ParseHtext" line 5)
invoked from within
"ParseHtext file8 #finger" |
and the I fix it with:
| Code: | | "puthelp "PRIVMSG $channel :Input: $::t_input($socket)"" |
it's works but show only 1st line:
| Code: | <@yuppy> !hash The quick brown fox jumps over the lazy dog
<+bothash> Input: The quick brown fox jumps over the lazy dog |
need more help please...  _________________ .:[ Knowledge Is The Power ]:. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Nov 14, 2008 12:24 pm Post subject: |
|
|
Another bummer with variables.. double-checking the code right now just to make sure I havn't made yet another bummer :p _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|