| View previous topic :: View next topic |
| Author |
Message |
DiEPLZ Voice
Joined: 24 Dec 2009 Posts: 7
|
Posted: Tue May 11, 2010 6:09 am Post subject: News.tcl Adding/Deleting/Reading news items from/into a file |
|
|
Hi all,
last time I requested a script here, arfer made me a fine script wich look up stuff on pricewatch (http://www.tweakers.net/pricewatch) see the script @ http://forum.egghelp.org/viewtopic.php?t=17457&highlight=pricewatch
Arfer still many thanks for this! i'm using it allot.
Anyway i'm looking for a pretty simple news script, wich I couldnt find in the archive or on google
This is what the script must be able todo:
!addnews <news> - wich result in adding the <news> in a simple .txt file in /scripts/news.txt (every news item on a new line)
!delnews <1,2,3 - all> - wich result in deleting line 1,2,3 or all (would be neat if you could delete line 1, 4 and 13, without deleting the rest)
!news - wich result the eggdrop to announce last 3 or 5 (perhaps editable) news lines
a nice feature would be if the eggdrop announce something like:
!news
<@bot> 1: this script is awesome
<@bot> 2: Another fine script is made
!delnews 2
<@bot> Item 2 has been deleted
!delnews all
<@bot> All news items has been deleted
!addnews this site is the best
<@bot> The news item has been
I've tried user_news, wich is asking for nickserv identification, wich isnt an option
I've tried news_1.01, wich didnt created news ;(
I've tried holm_news wich couldnt get others, except for shell user, to add hosts thru irc
So if someone has a script like this allready; pls gimme a link
otherwise I would be very honoured if someone is able to make such a script for me
Many thanks in advance |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue May 11, 2010 6:54 am Post subject: |
|
|
I would rather use sqlite3 to store stuff in than reinvent the wheel and store them in a text file.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
DiEPLZ Voice
Joined: 24 Dec 2009 Posts: 7
|
Posted: Tue May 11, 2010 7:15 am Post subject: |
|
|
The thing is i'm not root on the shell and root dont wanna install any sql stuff  |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Tue May 11, 2010 3:44 pm Post subject: |
|
|
| Code: | # Author: tomekk
# e-mail: tomekk/@/oswiecim/./eu/./org
# home page: http://tomekk.oswiecim.eu.org/
#
# Version 0.1
#
# This file is Copyrighted under the GNU Public License.
# http://www.gnu.org/copyleft/gpl.html
# if you want to use commands from this script on your chan, type in eggdrop console (via telnet or DCC chat)
# .chanset #channel_name +snews
# and later .save
# how many last news to show
set newsnr 3
# file with news
set newsdb "news.db"
#########################################################
bind pub -|- !news show_news
bind pub -|- !addnews add_news
bind pub -|- !delnews del_news
setudef flag snews
if {[file exists $newsdb] == 0} {
set new_db [open $newsdb w]
puts $new_db "news 1\nnews 2\nnews 3"
close $new_db
}
proc get_news { } {
global newsdb
set get_data [open $newsdb r]
set all_news [split [read $get_data] "\n"]
close $get_data
return $all_news
}
proc show_news { nick uhost hand chan arg } {
global newsnr
if {![channel get $chan snews]} {
return
}
set cmd [lindex [split $arg] 0]
set news_list [get_news]
set news_len [expr [llength $news_list] - 1]
if {$cmd == ""} {
if {$news_len > 0} {
set news_counter 1
for {set i $news_len} {$i > [expr $news_len - $newsnr]} {set i [expr $i - 1]} {
if {$i > 0} {
putquick "PRIVMSG $chan :$news_counter: [lindex $news_list [expr $i - 1]]"
incr news_counter 1
}
}
} {
putquick "PRIVMSG $chan :News file is empty."
}
} elseif {$cmd == "count"} {
putquick "PRIVMSG $chan :Total news in file: $news_len"
}
}
proc add_news { nick uhost hand chan arg } {
global newsdb
if {![channel get $chan snews]} {
return
}
if {[string trim $arg] != ""} {
set write_to_file [open $newsdb a]
puts $write_to_file $arg
close $write_to_file
putquick "PRIVMSG $chan :The news item has been added."
}
}
proc del_news { nick uhost hand chan arg } {
global newsdb
if {![channel get $chan snews]} {
return
}
set arg [string trim $arg]
if {$arg == "all"} {
set clean_db [open $newsdb w]
close $clean_db
putquick "PRIVMSG $chan :All news items have been deleted."
} {
set in_args [split $arg]
set numbers [list]
foreach in_arg $in_args {
if {[regexp {^([0-9]+)$} $in_arg]} {
if {$in_arg > 0} {
set del_nr [expr $in_arg - 1]
lappend numbers $del_nr
}
}
}
if {[llength $numbers] > 0} {
set the_news [get_news]
set the_number [llength $the_news]
if {$the_number > 0 } {
set rewrite_db [open $newsdb w]
for {set i 0} {$i < $the_number} {incr i 1} {
if {[lsearch $numbers $i] == -1} {
set the_line [lindex $the_news $i]
if {$the_line != ""} {
puts $rewrite_db $the_line
}
} {
putquick "PRIVMSG $chan :Item [expr $i + 1] has been deleted"
}
}
close $rewrite_db
}
}
}
}
putlog "simple-news.tcl ver 0.1 by tomekk loaded"
|
i've made tiny fix to my other script
!news - shows news
!news count - counts the news
!addnews <news> - adds the news
!delnews X X X X - removes the news (easier without , ;p)
!delnews all - removes all news
try it |
|
| Back to top |
|
 |
DiEPLZ Voice
Joined: 24 Dec 2009 Posts: 7
|
Posted: Wed May 12, 2010 1:41 am Post subject: |
|
|
Script is doing its work!
I was almost submitting something totally different here, though
Cause I had some error while chansetting my chan for +snews, although I killed the eggdrop and reloaded it afterwards and it is now working like a charm!
Many thanks! Really much appreciated! |
|
| Back to top |
|
 |
outthere Voice
Joined: 26 Nov 2005 Posts: 33
|
Posted: Wed May 04, 2011 7:59 pm Post subject: thanks |
|
|
I have been looking for something like this. Thanks. I notice though when you !delnews 6 out of 10 for example it counts backward so it in fact deletes the 4th one.
Is it just me? |
|
| Back to top |
|
 |
|