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.

5 Lines MSG

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
R
Regex
Voice
Posts: 19
Joined: Sat Mar 19, 2011 1:23 pm

5 Lines MSG

Post by Regex »

Hi Dear Coders..

I need your help..

How can we do 5 lines tcl..

when person says 5 lines in my channels, my eggdrop bot will send a message to person.

Example:

<Jackie> Hi
<Jackie> How are u ?
<Jackie> I'm so good.
<Jackie> Imm..
<Jackie> Where are u from ?
<Eggdrop> Jackie Thank You!!! You're chatting so good. ;)
<Jackie> Imm
<Jackie> My Pleasure
<Jackie> Im so happy now
<Jackie> :)
<Jackie> ..
<Eggdrop> Jackie Thank You!! You're chatting so good. ;)
N
Nimos
Halfop
Posts: 80
Joined: Sun Apr 20, 2008 9:58 am

Post by Nimos »

Code: Select all

###
#	5lines.tcl
##
#
# OUTDATED VERSION, USE THE SCRIPT BELOW!
#
##
# 	Settings
#
# The channels the script should be active in, seperated by spaces
# (leave empty for all channels)
set fivelines(channels) ""
#
# How many lines to write, to get an answer
set fivelines(count) 5
#
#
# A list with things the bot can answer
#
# (possible "variables" are %c (channel) %n (nick) %b (botnick))
#
set fivelines(answers) {
	"%n Thank You!!! You're chatting so good. ;)"
	"Hello %n, could you stop spamming now? :>"
	"Hurr durr, I am %b the mighty ruler of %c"
}
##
#
#	End of settings
#
###


bind pubm - * pubm_fivelines_counter

set fivelines(channels) [split $fivelines(channels)]
set fivelines(counter) 0

foreach chan $fivelines(channels) {
	set fivelines(counter|$chan) 0
	set fivelines(nick|$chan) ""
}
putlog [join [array get fivelines] \n]
	
proc pubm_fivelines_counter {nick host hand chan text} {
global fivelines


	if {[lsearch $fivelines(channels) $chan] != -1} {
		
		if {$fivelines(nick|$chan) == $nick} {
			incr fivelines(counter|$chan)
			
			if {$fivelines(counter|$chan) >= $fivelines(count)} {
				set answer [lindex $fivelines(answers) [expr round(rand() * ([llength $fivelines(answers)] - 1))]]
				regsub -all "%c" $answer $chan answer
				regsub -all "%n" $answer $nick answer
				regsub -all "%b" $answer $::botnick answer
				
				putserv "PRIVMSG $chan :$answer"
				
				set fivelines(counter|$chan) 0
			}
		} else {
			set fivelines(counter|$chan) 1
			set fivelines(nick|$chan) $nick
		}
	}
}
Last edited by Nimos on Sun Apr 24, 2011 6:18 am, edited 1 time in total.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Nimos wrote:*snipped long code*
Nimos, when new users join the channel, after any rehash/restart/etc .. (ones that were not previously in that channel before the rehash) rejoins your channel that script will cause errors for those nicknames.

Code: Select all

foreach chan $fivelines(channels) {
	set fivelines(counter|$chan) 0
	set fivelines(nick|$chan) ""
}
You use this code to intialize a huge array in global space for some reason. Rather than, using [info exists] command and using this to tell an initialized (aka, empty) array.

You then make this call to your procedure:

Code: Select all

		if {$fivelines(nick|$chan) == $nick} {
This will cause an error for any nickname that wasn't present when you previously initialized the array. It should be based around [info exists] imo. Using a series of sets does not work dynamically how you have done it. Just words of advice. ;)

As people chat, you add them to the array, only then do they eat memory. Until then we use [info exist] to tell if each nick is, or is not, already added to our array. If it's not then "set fivelines($nick|$chan) 1". If it is, then [incr] it ever after based on that until we hit the magic number 5.

Also...

Code: Select all

[expr round(rand() * ([llength $fivelines(answers)] - 1))]]
Might want to brace that [expr {}] to speed it up 1000% and to keep any issues with $fivelines variable from containing any exploits or substitution errors... and just do...

Code: Select all

[rand [llength $fivelines(answers)]]
which is same thing as your long code above in proper form without that nasty expr and needless round required because of that -1 you do to llength. Otherwise your code would never use the last element in the $fiveline(answers) list, which it will do rarely, not evenly like your rand suggest it would. In your list of three you can test this yourself, and do 3 queries. Multiple times. So 3 queries 20x. So 60x total. In those, the most ever the last element can appear as the result of those 60. Is 10 times. One sixth. 1/6. Half of what true random would be for 3 items, and making 60 queries. It should be 1/3rd, or 20/60th's. This is because of reasons having to do with your code versus mine and as I said only affects the last element in the list. My code above works correctly showing each of the 3 items 20 times if 60 requests were made and the list was only 3 lines long.
N
Nimos
Halfop
Posts: 80
Joined: Sun Apr 20, 2008 9:58 am

Post by Nimos »

Thanks for your comment, speechless.

You pointed out some flaws in my script, but it isn't as bad as you understood it.

My script only answers, if someone writes 5 lines in a row, without being interrupted by another person (I think thats what OP wanted.).
Notice, that my array is fivelines(nick|$chan), not fivelines($nick|$chan), so it wont create an entry for every user in the channel, nor would it require every user of the channel to be in it. (So it wont error on rehash/etc)

Still my array wasn't optimal, and I used an info exists line in exchange.


And thanks for the rand function! I didn't know it before.


New script:

Code: Select all

###
#	5lines.tcl
##
# 	Settings
#
# The channels the script should be active in, seperated by spaces
# (leave empty for all channels)
set fivelines(channels) ""
#
# How many lines to write, to get an answer
set fivelines(count) 5
#
#
# A list with things the bot can answer
#
# (possible "variables" are %c (channel) %n (nick) %b (botnick))
#
set fivelines(answers) {
	"%n Thank You!!! You're chatting so good. ;)"
	"Hello %n, could you stop spamming now? :>"
	"Hurr durr, I am %b the mighty ruler of %c"
}
##
#
#	End of settings
#
###


bind pubm - * pubm_fivelines_counter

set fivelines(channels) [split $fivelines(channels)]

	
proc pubm_fivelines_counter {nick host hand chan text} {
global fivelines


	if {[lsearch $fivelines(channels) $chan] != -1} {
		
		if {[info exists fivelines(nick|$chan)]} {
		
			if {$fivelines(nick|$chan) == $nick} {
				incr fivelines(counter|$chan)
				
				if {$fivelines(counter|$chan) >= $fivelines(count)} {
					set answer [lindex $fivelines(answers) [rand [llength $fivelines(answers)]]]
					regsub -all "%c" $answer $chan answer
					regsub -all "%n" $answer $nick answer
					regsub -all "%b" $answer $::botnick answer
					
					putserv "PRIVMSG $chan :$answer"
					
					set fivelines(counter|$chan) 0
				}
				
			} else {
				set fivelines(counter|$chan) 1
				set fivelines(nick|$chan) $nick
			}
		} else {
			set fivelines(counter|$chan) 1
			set fiveliens(nick|$chan) $nick
		}
	}[
}
edit: added missing last close brace
Post Reply