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 

Webchat.tcl

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


Joined: 30 Jul 2009
Posts: 4
Location: Sofia, Bulgaria

PostPosted: Mon Aug 03, 2009 11:58 pm    Post subject: Webchat.tcl Reply with quote

Hello. Can I do this TCL to show only the lastest 20 lines that are written in the channel?

Code:
set chat_setting(chan) "#Channel"

set chat_setting(file) "/home/ircd/www/radio/chat.html"

set chat_setting(temp) "/home/ircd/www/radio/chat.tmp"

if {![file exists $chat_setting(file)]} {
   set filehand [open $chat_setting(file) w]
   puts -nonewline $filehand ""
   close $filehand
}

bind pubm - * chat_update

proc chat_update {nick uhost hand chan text} {
   global chat_setting
   if {![string match "* [string tolower $chan ]*" "l [string tolower $chat_setting(chan)] l"]} {
      return 0
   }
   set time [clock format [clock seconds] -format "(%H:%M:%S\)"]
   set date [clock format [clock seconds] -format {%d %B %Y}]
   set text_nick "($nick)"
   set text_form "<b>($date) $time text_nick</b> $text<BR>"
   chat_file $text_form
   return 0
}

proc chat_file {text} {
   global chat_setting
   set filehand [open $chat_setting(file) r]
   set filehandtemp [open $chat_setting(temp) w]
   set linenum 0
   while {![eof $filehand]} {
      set line [gets $filehand]
      set lines [incr linenum]
      puts $filehandtemp "$line"
   }
   puts -nonewline $filehandtemp "$text"
   close $filehand
   close $filehandtemp
   file rename -force $chat_setting(temp) $chat_setting(file)
}

putlog "Инсталиран: WebChat.tcl"


Last edited by rabanne on Tue Aug 04, 2009 11:29 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Tue Aug 04, 2009 4:49 am    Post subject: Reply with quote

try:

Code:
set chat_setting(chan) "#kupa"

set chat_setting(file) "/home/www/chat.html"

set chat_setting(temp) "/home/www/chat.tmp"

if {![file exists $chat_setting(file)]} {
   set filehand [open $chat_setting(file) w]
   puts -nonewline $filehand ""
   close $filehand
}

bind pubm - * chat_update

proc chat_update {nick uhost hand chan text} {
   global chat_setting

   if {![string match "* [string tolower $chan ]*" "l [string tolower $chat_setting(chan)] l"]} {
      return 0
   }

   set time [clock format [clock seconds] -format "(%H:%M:%S\)"]
   set date [clock format [clock seconds] -format {%d %B %Y}]
   set text_nick "($nick)"
   set text_form "<b>($date) $time text_nick</b> $text<BR>"
   chat_file $text_form
   return 0
}

proc chat_file {text} {
   global chat_setting

   set filehand [open $chat_setting(file) r]
   set filehandtemp [open $chat_setting(temp) w]
#   set linenum 0
#   while {![eof $filehand]} {
#      set line [gets $filehand]
#      set lines [incr linenum]
#      puts $filehandtemp "$line"
#   }

   set last_lines [join [lrange [split [read $filehand] "\n"] end-18 end] "\n"]

   puts $filehandtemp $last_lines

   puts -nonewline $filehandtemp "$text"
   close $filehand
   close $filehandtemp
   file rename -force $chat_setting(temp) $chat_setting(file)
}

putlog "Инсталиран: WebChat.tcl"
Back to top
View user's profile Send private message Visit poster's website
rabanne
Voice


Joined: 30 Jul 2009
Posts: 4
Location: Sofia, Bulgaria

PostPosted: Tue Aug 04, 2009 11:30 am    Post subject: Reply with quote

Ten q ;>
Working Perfectly

...And if you want the last 30 lines should be

set last_lines [join [lrange [split [read $filehand] "\n"] end-28 end] "\n"] ?

for 40

set last_lines [join [lrange [split [read $filehand] "\n"] end-38 end] "\n"] .... etc


How can I make a site to see the numbers of rows? etc:
1. (date) (time) (nick) (text)
2. (date) (time) (nick) (text)
Back to top
View user's profile Send private message Visit poster's website
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Tue Aug 04, 2009 1:46 pm    Post subject: Reply with quote

try:
Code:
# channel
set irc_chan "#channel"

# html file
set channel_file "/home/www/chat.html"

# max lines number
set output_lines 20

##################################################33
bind pubm -|- "*" log_channel

if {![file exists $channel_file]} {
   set create_new [open $channel_file w]
   close $create_new
}

proc log_channel { nick uhost hand chan text } {
   global irc_chan channel_file output_lines

   if {$irc_chan != $chan} {
      return
   }

   set log_time [clock format [clock seconds] -format "%H:%M:%S"]
   set log_date [clock format [clock seconds] -format "%d %B %Y"]

   set log_line "<b>($log_date) ($log_time) ($nick) ($text)</b><br>"

   set read_current [open $channel_file r]
   set get_all [split [read $read_current] "\n"]
   close $read_current

   lappend get_all $log_line

   set get_all [lrange $get_all end-$output_lines end]

   set line_idx 1

   set rewrite [open $channel_file w]
   foreach each_line $get_all {
      if {$each_line != ""} {
         regsub {^[0-9]+\. } $each_line "" each_line
         puts $rewrite "$line_idx\. $each_line"
         incr line_idx 1
      }
   }
   close $rewrite
}

putlog "html-chan-log.tcl"
Back to top
View user's profile Send private message Visit poster's website
rabanne
Voice


Joined: 30 Jul 2009
Posts: 4
Location: Sofia, Bulgaria

PostPosted: Tue Aug 04, 2009 3:56 pm    Post subject: Reply with quote

You are number one ! Razz
Back to top
View user's profile Send private message Visit poster's website
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