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.

News.tcl Adding/Deleting/Reading news items from/into a file

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
D
DiEPLZ
Voice
Posts: 7
Joined: Thu Dec 24, 2009 11:21 am

News.tcl Adding/Deleting/Reading news items from/into a file

Post by DiEPLZ »

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? ... 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
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
D
DiEPLZ
Voice
Posts: 7
Joined: Thu Dec 24, 2009 11:21 am

Post by DiEPLZ »

The thing is i'm not root on the shell and root dont wanna install any sql stuff :-(
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

Code: Select all

# 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
D
DiEPLZ
Voice
Posts: 7
Joined: Thu Dec 24, 2009 11:21 am

Post by DiEPLZ »

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!
o
outthere
Voice
Posts: 33
Joined: Sat Nov 26, 2005 7:25 pm

thanks

Post by outthere »

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?
Post Reply