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.

buffer/keep-in-memory

Help for those learning Tcl or writing their own scripts.
Post Reply
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

buffer/keep-in-memory

Post by raider2k »

I would like to work on a system that is gathering news from two different news channels on an irc network and then announce the news to one of my own news channels. after thinking about a solution for some time it came to mind that duplicate announcing to my channel could happen, but should not.

is there a way to put the last 20 news into some kind of memory that is being kept in a global list which can be compared with new incoming news? in example a list containing the news source, the news title and the date. would mean, if new news found in list, dont announce it to my channel, if news not found, announce it.

was thinking about arrays already but - either its me or theres really no way to do it - I was not able to find anything to limit the lists maximum size (eg: maximum 20 news to be kept where the oldest news entry gets deleted - automatically or manually, doesnt matter so far).

and also was i thinking of working with files - to be honest, if theres a choice I wouldnt want to use files because it seems to unhandy to me.

looking forward to constructive help :)
and much thanks in advance
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The first question would be the persistence of the stored information; should it be valid for the session the eggdrop is running, or should it persist in between crashes/restarts/reboots?

The simplest approach in my mind, would be to use tcl-lists;
Use lappend to add a new item to the list, lsearch to test whether the list contains an item, and lrange or lreplace to remove old items. This, however, will only persist while your eggdrop is running and not restarted. For longer persistence you'll need some kind of database storage (files or other).
NML_375
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

looks like I was thinking around the corner ...
sounds like a 2go option :D

by the way: theres no command to easily delete a line instead of replacing it? thats what I was always wondering about, because replacing isnt the same as deleting .. or am I thinking in circles again?

edit:
persistent as long as the eggdrop is running I think should be enough as it i quite stable
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

If you think of deleting as replacing one list item with nothing at all, then lreplace can delete an item.
NML_375
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

looks like im really thinking the wrong way. the vision in my head looks like this:

first news - news source
second news - news source
third news - news source
fourth news - news source
last news - news source

but from what I have seen now on the tcl docs page reminds me again of the tcl way of lists that looks like this:

{{first news - news source} {second news - news source} {third news - news source} { fourth news - news source} {last news - news source}}

as far as I am right
so you are saying that lreplace kind of deletes a line when it becomes ""? correct me if I am wrong please :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

No, I am talking 'bout tcl-lists... as I've been from the very start. lreplace will replace the specified list items (not rows) with whatever values you provide (if any).

Code: Select all

set mylist [list "item 1" "item 2" "item 3"]
#mylist: {item 1} {item 2} {item 3}
lappend mylist "item 4"
#mylist: {item 1} {item 2} {item 3} {item 4}
set mylist [lreplace mylist 2 2]
#mylist: {item 1} {item 2} {item 4}
set mylist [lreplace mylist 2 2 "item 3"]
#mylist: {item 1} {item 2} {item 3}
set mylist [lreplace mylist 2 2 "item 3" "item 4"]
#mylist: {item 1} {item 2} {item 3} {item 4}
set mylist [lrange $mylist 1 end]
#mylist: {item 2} {item 3} {item 4}
if {[lsearch $mylist "item 3"]} {
  puts stdout "true"
}
Basically, when you get a new news-item, check whether it's already present in the list; if not, add it to the list and announce it, then use lrange or lreplace to remove old entries (you can use the llength command to test the size of the list).
NML_375
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

ok
let me try that when I have some more time and Im at home again, will keep you updated. thanks again for your quick reply :)
Post Reply