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.

Storage & Display

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Storage & Display

Post by Football »

Hey,

I need a script that will store and display lines in a file by order and by a timer through private/public commands.
Would be nice if you could also configure the timer and view the whole file on request.

PLEASE PLEASE help.
Idling at #Football, Quakenet.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Re: Storage & Display

Post by willyw »

Football wrote:Hey,

I need a script that will store and display lines in a file by order and by a timer through private/public commands.
Would be nice if you could also configure the timer and view the whole file on request.

PLEASE PLEASE help.
Can you explain it a bit differently?
Not exactly sure of what it is that you want it to do.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Yes... especially the part about the timer. What exactly do you want it to be used for, etc? :)
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Ok I`ll explain it a bit differently

I should note first that I`ve looked through the archives and couldn't find what I was looking for.

I need a script that can be controlled via public commands - The script will allow you to add/delete/list & set timer for messages to be displayed in a certain channel and will display them by order.

The public commands would be:
!enable
!disable
!settimer
!addmsg
!delmsg
!listmsg


!enable - will enable the script in the current channel
!disable - will disable the script in the current channel
!stats - will notify you whether the script is enabled or disabled
then you can !addmsg message-here and the bot will add it to his list and number it
!delmsg <message-number> - will erase that specific message
!settimer <number of minutes> - Every X minutes the bot will display the messages by order; #1 and then X minutes later #2 and so on
!listmsg - will list all the messages that were added to the bot

Would be nice if all the bots replays would be notices.

-Bot- Message #1 Added: "Message Here"
-Bot- Message #3 Added: "Message 3 here"

-Bot- Messages list:
-Bot- #1..
-Bot- #2..

Is that a better explanation ?

Hope you'll help me out, I could really use that script, very handy. Thank you for your time and attention.
Idling at #Football, Quakenet.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Much better explanation. :) Okay, so basically... you want a sort of shortcut proc. i managed to get everything working except for the settimer proc. That one is deceptively hard, and I am afraid of testing it too much on my host, as while doing so earlier, I spiked the RAM really high and locked up my bot bad, lol. So.. I may have to leave that one to someone else, sorry. :( Anyway, here's what I have for you though: http://pastebin.com/9WN7RWvH
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Hey Luminous!

Thanks I would like to thank you for your patient, your time and attention, I bet you spent a while on this script and I appreciate it.

Hopefully someone will help out with the last part of the code, the timer, since its a pretty major option that I need in the script, but thank you so much for being so helpful ! :)
Idling at #Football, Quakenet.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

You're very welcome. :) I should have commented it for you so you can read through it better... Hopefully someone gets that settimer proc going, I'd be curious to see how that is done myself. Perhaps I'll end up working it out, we'll see...
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

I've been playing around with this since yesterday. :)

I see Luminous has posted already. Prior to that, we chatted some online, and shared some old and new ideas. I borrowed a bit of code from him, and some others too - and some new too, and put this thing together.

Note that since there was no mention of flags for limiting use of these public commands, as it is below, the commands are available to all.
You can easily edit the binds though, if you wish.

I've played with this a bit on a test bot. It worked. That doesn't mean that I thought of every possibility.
There are no guarantees. :)

Give it a try, and let us know how it goes.

I hope this helps.

Code: Select all

# August 3, 2010

# http://forum.egghelp.org/viewtopic.php?p=93728#93728


########################################################
#The public commands would be:
#!enable
#!disable
#!settimer
#!addmsg
#!delmsg
#!listmsg

#!timeron
#!timeroff
#!status
#!setline

#!enable - will enable the script in the current channel
#!disable - will disable the script in the current channel
#!status - will notify you whether the script is enabled or disabled
#!addmsg <message-here> and the bot will add it to his list
#!listmsg <number> - will list one message, from line #<number>
#!listmsg          - will list all the messages that were added to the bot
#!delmsg <message-number> - will erase that specific message
#!settimer <number of minutes> - Every X minutes the bot will display the messages by order; #1 and then X minutes later #2 and so on
#!settimer              will display the current setting.

#!timeroff Stops the timer for message display   (timer is ON, when bot starts )
#!timeron  Starts the timer for message display (without having to restart the bot)
#!setline <number>  Manually set the line number of the next displayed line
#!setline           will display current setting
####################################



##### Config
# Set the path and file name of the file that holds messages
set message_file "scripts/message_file.txt"


# Set the default starting timer minutes. 
# This is the time that will be used after a restart, until a !settimer command is used to change it.
set timer_minutes 2

##### End Config



########### script begins here


bind pub - "!addmsg" addmsg
bind pub - "!listmsg" listmsg
bind pub - "!delmsg" delmsg
bind pub - "!settimer" settimer
bind pub - "!enable" enable
bind pub - "!disable" disable
bind pub - "!status" status
bind pub - "!timeroff" timer_off
bind pub - "!timeron" timer_on
bind pub - "!setline" setline

setudef flag announcer
set line_counter 0



## If message file does not exist, create it as empty file
if {![file exist $message_file]} {
	close [open $message_file w]
	}



## Check to see if script is loaded already, and if not, then start timer.
## The idea is to NOT start additional timers, after a rehash 
if {![info exists timer_announcer_loaded]} {
	set timer_announcer_loaded 1
    	timer $timer_minutes run_announce
   } 




## Sends one message to channel, every XX minutes, incrementing through stored messages.
proc run_announce {} {
global message_file timer_minutes line_counter
	
foreach chan [channels] {

   if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {


	set phile [open $message_file "r"]
	set data [read -nonewline $phile] 
	close $phile
	
	#Check to see if the line number we are looking for, is greater than the actual number of lines in the message file
	#and if so, instead have it go to the last line
	if {[llength [split $data \n]]<=$line_counter} {
		set line_counter [expr [llength [split $data \n]] - 1]
		}

      #Display the line
	if {"[lindex [split $data \n] $line_counter]"!=""} {
			putserv "privmsg $chan : [join [lindex [split $data \n] $line_counter]] "
	   }
	 }
    }
incr line_counter
if {[llength [split $data \n]]<=$line_counter} {
	set line_counter 0
   }

# re-starts the timer, to run this proc again
timer $timer_minutes run_announce

}




## Allows line counter to be manually set
proc setline {nick uhost handle chan text} {
global line_counter

if {[string is integer -strict [join [lindex [split $text] 0]]]} {
	set line_counter [expr [lindex [split $text] 0] -1]
	putserv "notice $nick :Next line displayed will be line [expr $line_counter +1]"
	} else {
	putserv "notice $nick :Next line displayed will be line [expr $line_counter +1]"
  }
}



##Allows timer delay to be changed via a pub command

proc settimer {nick uhost handle chan text} {
global timer_minutes

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {

	if {"[lindex [split $text] 0]"==""} {
		putserv "notice $nick :Timer is set to $timer_minutes minutes"
		} elseif {"[lindex [split $text] 0]"<="0"} {
			putserv "notice $nick :No change. Timer must be set to a positive integer" 
		} else {
		set timer_minutes "[lindex [split $text] 0]"
		putserv "notice $nick :Timer will be set to $timer_minutes minutes"
		}
  }
}





##Allows timer to be turned off via a pub command

proc timer_off {nick uhost handle chan text} {

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {


	foreach thetimer [timers] {
		 if {[string match -nocase "run_announce*" [lindex $thetimer 1]]} {
	  # got a match
	  killtimer [lindex $thetimer 2]

	  putserv "notice $nick :Timed Announcer is off"
	
	  # killed the timerID which is the 3rd element of $thetimer.
	  break
	  # stopped since no need for further checks.
      	}
     }

# credit: http://forum.egghelp.org/viewtopic.php?p=53896#53896

  }
}






## Allows timer to be turned on via a pub command

proc timer_on {nick uhost handle chan text} {

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {

	if {"[timerexists run_announce]"==""} {
		run_announce
		putserv "notice $nick :Timed Announcer is on"
	}
   }
}






## Used by other procedure, to find out if a timer already exists
proc timerexists {command} {
  foreach i [timers] {
    if {![string compare $command [lindex $i 1]]} then {
      return [lindex $i 2]
	}
  }
  return
#credit:  from alltools.tcl
}







## Allows messages to be added via a pub command

proc addmsg {nick uhost handle chan text} {
global message_file

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {

	if {"$text"==""} {
		putserv "notice $nick :Syntax: !addmsg <message here..... >"
		return 0
	  }

	set phile [open $message_file "r"]
	set first_line [gets $phile]
	close $phile
	if {"$first_line"==""} {
		set phile [open $message_file "w"] 
		puts $phile "[lrange [split $text] 0 end]"
	     close $phile
		} else {
		set phile [open $message_file "a"] 
		puts $phile "[lrange [split $text] 0 end]"
     		close $phile
	   }
	
	putserv "notice $nick :Added:   \"[join [lrange [split $text] 0 end]]\" "
  }
}






## Will display all messages, in response to a pub command

proc listmsg {nick uhost handle chan text} {
global message_file line_counter

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {

	#Display one message via notice, only if a number is given with !listmsg - if no number given, then list all messages
	if {[string is integer -strict [join [lindex [split $text] 0]]]} {
		set phile [open $message_file "r"]
		set data [read -nonewline $phile] 
		close $phile

		if {[llength [split $data \n]]>=[lindex [split $text] 0]} {
			putserv "notice $nick :[join [lindex [split $data \n] [expr [lindex [split $text] 0]-1]]]"
			} else {
			putserv "notice $nick :No such line"
		}

	return 0
	  }	


	set phile [open $message_file "r"]
	set first_line [gets $phile]
	close $phile
	if {"$first_line"==""} {
		putserv "notice $nick : I got nothing"
		return 0
		}

	set lnum 0
	set phile [open $message_file "r"]
	while {[gets $phile line] >= 0} {
		putserv "notice $nick :[incr lnum]: [join $line]"
		}
	close $phile
	#credit: Luminous


	if {[string is integer -strict [join [lindex [split $text] 0]]]} {
		set phile [open $message_file "r"]
		set data [read -nonewline $phile] 
		close $phile
		putserv "privmsg $chan : [join [lindex [split $data \n] $line_counter]] "
	  }	
  }

}





## Allows a message to be deleted (by message number, see !listmsg) via a pub command

proc delmsg {nick uhost handle chan text} {
global message_file

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {


	if {"$text"==""} {
		putserv "notice $nick :Syntax: !delmsg <number>"
		putserv "notice $nick :Use !listmsg     to get line numbers"
		return 0
		}

	
	set del_line_num [expr [lindex [split $text] 0] - 1 ]
	if {$del_line_num < 0} {
		putserv "notice $nick :No can do.  Must be 1 or greater."
		return 0
		}
	 

	set phile [open $message_file r]
		set data [read -nonewline $phile] 
	close $phile

	set lines [split $data "\n"] 



     if {[llength $lines] <= $del_line_num} {
		putserv "notice $nick :No such line number"
		return 0
	   }
	putserv "notice $nick :Deleting:  [join [lindex $lines $del_line_num]]"
	putserv "notice $nick :      (use  !listmsg   again now, as you may have changed the line numbers!)"
	set lines [lreplace $lines $del_line_num $del_line_num]

	set phile [open $message_file "w"]
		puts $phile [join $lines "\n"]
	close $phile

  }
}




## Will enable timed messages announcements in the channel where the pub command is sent

proc enable {nick uhost handle chan text} {

channel set $chan +announcer

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
	putserv "notice $nick :Timed Announcer enabled on $chan"
	}
}





## Will disable timed message announcements in the channel where the pub command is sent

proc disable {nick uhost handle chan text} {

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {

	channel set $chan -announcer

     }

if {([lsearch -exact [channel info $chan] {-announcer}] != -1)} {
	putserv "notice $nick :Timed Announcer disabled on $chan"
	}
}






## Send the status (enabled or disabled) to the channel where the pub command is given

proc status {nick uhost handle chan text} {

set time_left 0
foreach thetimer [timers] {
		 if {[string match -nocase "run_announce*" [lindex $thetimer 1]]} {
		 set time_left [lindex $thetimer 0]
		   }
      }

if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
	
	putserv "notice $nick :Announcer is enabled in $chan."  
	if {$time_left} {putserv "notice $nick :Timer is running with $time_left minutes or less to go"}
	if !{$time_left} {putserv "notice $nick :Timer is not running"}
	} else {
	putserv "notice $nick :Timed Announcer is disabled in $chan"
	if {$time_left} {putserv "notice $nick :Timer is running with $time_left or less to go"}
	if !{$time_left} {putserv "notice $nick :Timer is not running"}
	}
}



putlog "Loaded Timed Announcer   :)     See: http://forum.egghelp.org/viewtopic.php?p=93728#93728 "



## Much credit goes to posters on the forum at   http://forum.egghelp.org/   
## Bits and pieces, and ideas used above - were borrowed from there.
## To anyone not specifically mentioned, I apologize.

## Any errors, broken code, poor code, or other strange things,  are not theirs.  They are mine.


.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Hey willyw! Thank you for the kind help! I`ve been looking for a while for this script and I had to use many low-class scripts that don't fulfill all my needs, but thanks to you and Luminous I can now end my long journey.
Thank you very much.

I have a few suggestions though.

A. The script doesn't support multiple channels...
B. Would be nice if I could use the commands both on public or in private

an example for private commands:

!enable #Football
!addmsg #Football This is an auto msg
!listmsg #Football

And so on..

C. Would be nice if you add a bind that will allow only +o to use the commands.

Hope this isn't too rude... thank you both!
Idling at #Football, Quakenet.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Football wrote:Hey willyw! Thank you for the kind help!
You are welcome.
I have a few suggestions though.

A. The script doesn't support multiple channels...
It doesn't?
Have you tried it on more than one?
I tested on only two....

Use the commands you requested : !enable and !disable
B. Would be nice if I could use the commands both on public or in private
I saw:
Football wrote: ...I need a script that can be controlled via public commands...
and went with that.

I will have to look at it again, and see how much might be involved, to get it to work with either. ... no promises though. :)
an example for private commands:

!enable #Football
!addmsg #Football This is an auto msg
!listmsg #Football

And so on..


C. Would be nice if you add a bind that will allow only +o to use the commands.
I'd said that you could easily edit the binds. Perhaps that didn't register on you. :)

Find the lines like:

Code: Select all

bind pub - "!addmsg" addmsg 
and change that dash to o:

Code: Select all

bind pub o "!addmsg" addmsg
and rehash
now, only those with the Operator flag, in the bot, can use that command.

I think that is what you are asking for, anyway. :)
Here: http://suninet.the-demon.de/041.htm
is some nice reference material, on how to use the flags with bind.
Hope this isn't too rude... thank you both!
nah...
but I am unclear on something: Have you loaded it up, and tried it?
All the commands?
I ask, because there are couple commands in there that you did not request, and couple that you did, but with modifications.
Just wanted to be sure you'd found that stuff, too.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

It doesn't?
Have you tried it on more than one?
I tested on only two....

Use the commands you requested : !enable and !disable
What I mean is, that since it uses only one file, it will use the same messages set for channel A for channel B aswell and not seperate messages.
I saw:
Football wrote:

...I need a script that can be controlled via public commands...


and went with that.

I will have to look at it again, and see how much might be involved, to get it to work with either. ... no promises though.
Yeah, you're totally right and thats my fault, this is only a suggestion to improve it, thought it could get a bit floody & the whole room will have to put up with the configuration, when it doesn't really need to see whats going on.. would be great if you could add it though!
I'd said that you could easily edit the binds. Perhaps that didn't register on you.
One of the reasons I`m so thankful for your help is because A. I know it takes a fair amount of time & B. Because I can't script at all, thats why I`m trying to reach for the most help I can from you..
but I am unclear on something: Have you loaded it up, and tried it?
All the commands?
I ask, because there are couple commands in there that you did not request, and couple that you did, but with modifications.
Just wanted to be sure you'd found that stuff, too.
Yeah I did, everything works great, I`ve checked it out and its beyond my requests, only that addition of op binds & private binds aswell could make it just too sweet!
Idling at #Football, Quakenet.
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Think I found an error...
From message #1 it jumped to #3, same from #3 to #5

[22:16:11] <@Ailen> !listmsg
[22:16:13] -Football- 1: #Football addon Released [July 20th]! Includes all Football bot commands & some other cool features! download it now! http://tinyurl.com/3yatcvs
[22:16:15] -Football- 3: Friday [Friendlies] 20:45 Aston Villa vs. Valencia, Bolton vs. Osasuna, Wrexham vs. Stoke [CONCACAF Champions League] 02:00 Joe Public vs. Brujas, 04:00 Xelaju vs. Fass [SuperLiga] 02:00 Houston vs. Monarcas [Copa Sudamericana] 00:30 Goias vs. Gremio [Copa Libertadores] 02:50 Sao Paulo vs. Internacional [MLS] 02:00 Philadelphia vs. Columbus [ERE] 20:45 Roda vs. Twente
[22:16:20] -Football- 5: Saturday [German SuperCup] 17:45 Bayern vs. Schalke [MEX] 03:10 Tecos vs. Puebla [POR League Cup] 18:00 Gil Vicente vs. Moreirense [MLS] 22:00 Toronto vs. Chivas [ERE] 18:45 Nijmegen vs. Venlo, 19:45 De Graafschap vs. Excelsior, Heracles vs. Willem II [Ligue 1] 20:00 Auxerre vs. Lorient, Lens vs. Nancy, Lyon vs. Monaco, Marseille vs. Caen, Nice vs. Valenciennes, PSG vs. St. Etienne, Rennes vs. Lille, Sochaux vs. Arles, Toulouse vs. Brest
[22:16:23] -Football- 7: Sunday [FA Community Shield] 16:00 Chelsea vs. Man Utd [Ligue 1] 21:00 Montpellier vs. Bordeaux
[22:16:25] -Football- 8: Monday [ARG] 01:20 Godoy Cruz vs. Boca Juniors [MLS] 01:00 Dallas vs. Philadelphia, 03:00 Chicago vs. New York, 05:00 Seattle vs. Houston
[22:16:27] -Football- 9: Tuesday [EURO U21 Qualifiers] 20:30 Ireland U21 vs. Estonia U21 [Friendly] 19:00 Augsburg vs. Stuttgart [Friendly International] 19:00 Cyprus U21 vs. Israel U21
[22:16:29] -Football- 10: Wednesday [Africa Cup of Nations - Qualifying] 15:00 Chad vs. Tunisia, Malawi vs. Botswana [Euro Qualifiers] 19:00 Estonia vs. Faroe Islands [Euro U21 Qualifiers] 17:30 Croatia vs. Norway, 18:15 France vs. Belgium, Iceland vs. Germany [Friendlies] 02:00 USA vs. Brazil, 20:15 Czech Republic vs. Latvia, 20:30 Slovakia vs. Croatia, 22:00
Idling at #Football, Quakenet.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Football wrote:
It doesn't?
Have you tried it on more than one?
I tested on only two....

Use the commands you requested : !enable and !disable
What I mean is, that since it uses only one file, it will use the same messages set for channel A for channel B aswell and not seperate messages.
Oh.
Right.
In your detailed description of what you wanted/needed, I didn't see anything about different messges, on a per channel basis.

That could get involved.
Perhaps Luminous, or somebody else here, would like to give it a shot.
I don't mind if they use all or part of what I've done here.

I've done it in the past, with a few of my scripts, that I just use myself.... made them into multi-chan capable. Sometimes it is not a big deal, sometimes it is.
When I get time, I'll look at this again... but if it is a really time consuming thing, I might not be able to do it.
....

Because I can't script at all,
hehe... well... put your toe in the water!
Jump in!
heheeh

This is easy, and I've no doubt you can do it. :)
Besides, the original is right here, so if you phat phinger it, and make a mess, you can always just start over, with a fresh copy from here.
Here's what you do:
Open the file, with whatever you used to make it - an editor of some sort, I suppose. If your copy is on a Windows computer, then Wordpad works fine.
Look for these lines:

Code: Select all

bind pub - "!addmsg" addmsg
bind pub - "!listmsg" listmsg
bind pub - "!delmsg" delmsg
bind pub - "!settimer" settimer
bind pub - "!enable" enable
bind pub - "!disable" disable
bind pub - "!status" status
bind pub - "!timeroff" timer_off
bind pub - "!timeron" timer_on
bind pub - "!setline" setline
and change them to:

Code: Select all

bind pub o "!addmsg" addmsg
bind pub o  "!listmsg" listmsg
bind pub o "!delmsg" delmsg
bind pub o "!settimer" settimer
bind pub o "!enable" enable
bind pub o "!disable" disable
bind pub o "!status" status
bind pub o "!timeroff" timer_off
bind pub o "!timeron" timer_on
bind pub o "!setline" setline
all that is, ... is changing the dashes, to the letter o
:)

Be sure to save it.
Load it in your bot. A restart will do it.
Then, be sure to test.
What you should notice is that only those with the o flag (Operators), in your bots internal user list, can now get those commands to react.
Those without the o flag should get no reaction at all from the bot now, if they send one of those commands.

Let us know how it turns out.
:)

but I am unclear on something: Have you loaded it up, and tried it?
All the commands?
I ask, because there are couple commands in there that you did not request, and couple that you did, but with modifications.
Just wanted to be sure you'd found that stuff, too.
Yeah I did, everything works great, ...
Great! :)
F
Football
Master
Posts: 205
Joined: Fri Dec 26, 2008 3:08 pm
Location: Quakenet, #Football

Post by Football »

Thanks willyw, but I actually added the 'o' part before you wrote how to do it :)

If you could help me out with the more complicated two parts I mentioned that would be great, but I`m very greatful as it is.
Idling at #Football, Quakenet.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Football wrote:Think I found an error...
From message #1 it jumped to #3, same from #3 to #5
Open the file, and have a look at what is in it.
What is on those lines? line 2, line 4 ... perhaps that will be a clue.

(I may be away for a few hours, ... I'll check back later)
Post Reply