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.

Words peak

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
S
StormG
Voice
Posts: 9
Joined: Sat Jan 05, 2013 4:32 pm

Words peak

Post by StormG »

Is there a way to count words said in channel? I mean something like:
<nick> !peakwords
<bot> There are *200 words as far as i know, the most recent ones would be: <word1> , <word2> , <word3> posted in #channel.

And if it can be done, it's there a way to enable the script via an activation flag, so the script should work only on channels where is enabled?

NOTE: *200 is just an example, the bot should tell the words he remembers them from the first activation point, except when he quitted, or not present on the channel.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Here is a little code for what you asked, it`s not really sophisticated I know it could be more advanced with more protections and commands but I`m guessing maybe a future version.. :)

Code: Select all

# ---------------------------------------
# Word Count by dirty Inc.
# 
# Contact:
# WwW.BotZone.TK
# irc.undernet.org @ #BotZone
#
# HOW TO USE!!!!
# Set the channel to +wordcount
# Commands:
# !wordcount
# ---------------------------------------

# Set here how many "last words" to display
set dty_wc(lastwords) "5"

# DO NOT EDIT PASS THIS LINE (AT YOUR OWN RISK)
set dty_wc(version) "v1"

setudef flag wordcount
setudef str wordcount-text
setudef int wordcount-nr

bind pubm -|- * wc:pub:words
proc wc:pub:words {nick uhost handle channel text} {
	global dty_wc
	
	if {![channel get $channel wordcount]} { return }
	if {[isbotnick $nick]} { return }
	if {[string tolower [lindex $text 0]] == "!wordcount"} { return }
	
	set wctext [channel get $channel wordcount-text]
	set wcnr [channel get $channel wordcount-nr]
	if {$wcnr == ""} {
		set wcnr 0
	}
	set newtext ""
	foreach word [join [lrange [split $text] 0 end]] {
		if {[llength [split $word ""]] > 1} {
			incr wcnr
			lappend newtext $word
		}
	}
	set newtext "[lreverse $newtext] $wctext"
	channel set $channel wordcount-text [lrange $newtext 0 [expr {$dty_wc(lastwords) - 1}]]
	channel set $channel wordcount-nr $wcnr
	putlog "WC [channel get $channel wordcount-nr]: [channel get $channel wordcount-text]"
} 

bind pub - !wordcount wc:cmd:wordcount
proc wc:cmd:wordcount {nick uhost handle channel text} {
	global dty_wc
	
	if {![channel get $channel wordcount]} { return }
	
	putserv "PRIVMSG $channel :Total Words said in $channel [channel get $channel wordcount-nr]"
	putserv "PRIVMSG $channel :Last $dty_wc(lastwords) words: [channel get $channel wordcount-text]"
}

putlog "Word Count $dty_wc(version) by dirty Inc. Loaded."
come to the dark side.. I have cookies!
WwW.BotZone.TK
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The way you designed this, if he's on a private shell hosting company will will get his account suspended/disabled, mainly due to the fact that if the channel is heavy populated, at some point it would reach a high amount of words and would most likely end up on wasting memory. :)

A better approach would be to filter out crap like meaningless words, store words for in memory then write them down in a flat text file every 10 minutes or something, and only when an user issues the !wordcount command it should only then fetch stuff from that file and give results.

I for one would use sqlite instead of a flat file, cos has commands designed for managing a database.
Once the game is over, the king and the pawn go back in the same box.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

What do you mean "high amount of words" ? the bot only stores the last 5 words the rest are not. the only high cpu is that the egg will run that proc on each text line of a user on the channel and sure we can write everything in a file and count words and display last 5 but it would still open, write all text and save the file on each text.. why would we do that? i think it will use even more resources that way because it has to manipulate an external file instead of doing everything internal like i`ve designed it.

I see you are one of dose people that are used to write external files for scripts and i have nothing against it.. but i don`t think it`s the best efficient way sorry. If you still think i`m wrong then how about a demonstration.. put this tcl in an eggdrop.. create one to do the same that uses an external file and show me the resource usage.. then i`ll be convinced.
come to the dark side.. I have cookies!
WwW.BotZone.TK
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If you read again what the OP asked for you will see that he will need ALL words counted cos then how would it know what words are top 5 if it will store only the last 5? :)

Let's say currently the last 5 are: word1, word2, and so on. Now, word6 has just 10 mentions, while let's say word5 has 11. If word6 is mentioned 2 times, how would the bot know how many words word6 previously had if you don't store it anywhere?

I've said keep stuff in memory BUT after let's say 10 minutes flush it down in to a sqlite database as is a better option than a flat file, where you would have to design all the functions sqlite already has: search, add, update, count and so on.
Once the game is over, the king and the pawn go back in the same box.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Yes that would of been a lot more to store but he didn`t say to do that .. if that`s what he meant then a log file is needed to do that but i made a script that dose what he wrote.

Code: Select all

<nick> !peakwords 
<bot> There are *200 words as far as i know, the most [b]recent ones[/b] would be: <word1> , <word2> , <word3> posted in #channel.
He said RECENT ONES not MOST USED so you probably want to read his post again.
come to the dark side.. I have cookies!
WwW.BotZone.TK
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Yes, you are somehow 50% right as he wanted last 3 words, it still needs a full log of all mentioned words. :)
Once the game is over, the king and the pawn go back in the same box.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Why would he need a full log if what he only want is the last X words?
come to the dark side.. I have cookies!
WwW.BotZone.TK
S
StormG
Voice
Posts: 9
Joined: Sat Jan 05, 2013 4:32 pm

Post by StormG »

Hello, and thank you dirty, for your quick reply, and caesar with the above mentions; i read the forward replies to this thread, so to be more precise, i had in mind something like: if in the channel where the flag is enabled, the bot will start to count every word said, and after the command will output the current info for the max words counted in channel, and also output the most last three wods said in it.

Hopefully this will clear what i had in mind.
d
dirty
Halfop
Posts: 40
Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:

Post by dirty »

Haha.. ok well that`s another thing StormG .. as i`ve said to caesar on your first post you said "most recent ones" not "most used" so i made what you asked. I`ll let caesar edit my script and make it so it will show most used words :)
come to the dark side.. I have cookies!
WwW.BotZone.TK
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Nah, thanks I'm fine thank you. Anyway, I'm busy with something else. :P
Once the game is over, the king and the pawn go back in the same box.
Post Reply