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 

buffer/keep-in-memory

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed Aug 12, 2009 10:13 am    Post subject: buffer/keep-in-memory Reply with quote

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 Smile
and much thanks in advance
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Aug 12, 2009 10:29 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed Aug 12, 2009 11:07 am    Post subject: Reply with quote

looks like I was thinking around the corner ...
sounds like a 2go option Very Happy

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


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Aug 12, 2009 11:17 am    Post subject: Reply with quote

If you think of deleting as replacing one list item with nothing at all, then lreplace can delete an item.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed Aug 12, 2009 11:50 am    Post subject: Reply with quote

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


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Aug 12, 2009 12:04 pm    Post subject: Reply with quote

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:
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed Aug 12, 2009 2:19 pm    Post subject: Reply with quote

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 Smile
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 -> Scripting Help 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