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.

How to put console/terminal text into channel

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
ZEXEL
Halfop
Posts: 45
Joined: Tue Jun 27, 2006 10:47 pm
Contact:

How to put console/terminal text into channel

Post by ZEXEL »

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: Select all

[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: Select all

<@Yuppy>!hash The quick brown fox jumps over the lazy dog
and output:

Code: Select all

<+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... :o
Last edited by ZEXEL on Wed Nov 12, 2008 12:27 am, edited 4 times in total.
.:[ Knowledge Is The Power ]:.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

Could try

Code: Select all

eval exec
If you look in the TCL FAQ section, you'll find an example proc of !exec code, hope it helps. :)

RE: http://forum.egghelp.org/viewtopic.php?t=9945
User avatar
ZEXEL
Halfop
Posts: 45
Joined: Tue Jun 27, 2006 10:47 pm
Contact:

Post by ZEXEL »

@TCL_no_TK
I've used it, but unformatted and multiple texts will show in the channel if I use that.

more help please... :cry:
.:[ Knowledge Is The Power ]:.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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... :cry:
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.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I'd do something like below:
Code is untested, let me know if there's any errors..

Code: Select all

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...
Last edited by nml375 on Fri Nov 14, 2008 12:22 pm, edited 2 times in total.
NML_375
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

nml375 wrote:

Code: Select all

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 :wink:
Have you ever read "The Manual"?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
User avatar
ZEXEL
Halfop
Posts: 45
Joined: Tue Jun 27, 2006 10:47 pm
Contact:

little error

Post by ZEXEL »

@TCL_no_TK, @speechles thx for suggestion :roll:
@nml375, thx for the script :D
@user, nice tips and tricks :wink:

I got error in console/terminal when trying to get result from the channel:

Code: Select all

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 ]:.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Nah, just means I made a bummer mixing up variables... fixed now.
NML_375
User avatar
ZEXEL
Halfop
Posts: 45
Joined: Tue Jun 27, 2006 10:47 pm
Contact:

Post by ZEXEL »

nml375 wrote:Nah, just means I made a bummer mixing up variables... fixed now.
it's look stop processing at:

Code: Select all

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: Select all

"puthelp "PRIVMSG $channel :Input: $::t_input($socket)""
it's works but show only 1st line:

Code: Select all

<@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... :oops:
.:[ Knowledge Is The Power ]:.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Another bummer with variables.. double-checking the code right now just to make sure I havn't made yet another bummer :p
NML_375
Post Reply