egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to put console/terminal text into channel

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
ZEXEL
Halfop


Joined: 27 Jun 2006
Posts: 45

PostPosted: Tue Nov 11, 2008 4:35 am    Post subject: How to put console/terminal text into channel Reply with quote

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... Surprised
_________________
.:[ Knowledge Is The Power ]:.


Last edited by ZEXEL on Wed Nov 12, 2008 12:27 am; edited 4 times in total
Back to top
View user's profile Send private message Visit poster's website
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Tue Nov 11, 2008 4:36 pm    Post subject: Reply with quote

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

RE: http://forum.egghelp.org/viewtopic.php?t=9945
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
ZEXEL
Halfop


Joined: 27 Jun 2006
Posts: 45

PostPosted: Wed Nov 12, 2008 12:24 am    Post subject: Reply with quote

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

more help please... Crying or Very sad
_________________
.:[ Knowledge Is The Power ]:.
Back to top
View user's profile Send private message Visit poster's website
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed Nov 12, 2008 7:48 am    Post subject: Reply with quote

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... Crying or Very sad

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Nov 12, 2008 3:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Nov 12, 2008 5:04 pm    Post subject: Reply with quote

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 Wink
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Nov 12, 2008 6:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
ZEXEL
Halfop


Joined: 27 Jun 2006
Posts: 45

PostPosted: Wed Nov 12, 2008 10:06 pm    Post subject: little error Reply with quote

@TCL_no_TK, @speechles thx for suggestion Rolling Eyes
@nml375, thx for the script Very Happy
@user, nice tips and tricks Wink

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
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Nov 13, 2008 2:16 pm    Post subject: Reply with quote

Nah, just means I made a bummer mixing up variables... fixed now.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
ZEXEL
Halfop


Joined: 27 Jun 2006
Posts: 45

PostPosted: Fri Nov 14, 2008 2:28 am    Post subject: Reply with quote

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... Embarassed
_________________
.:[ Knowledge Is The Power ]:.
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Nov 14, 2008 12:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber