| View previous topic :: View next topic |
| Author |
Message |
StormG Voice
Joined: 05 Jan 2013 Posts: 9
|
Posted: Thu Feb 21, 2013 3:04 am Post subject: Words peak |
|
|
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. |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Thu Feb 21, 2013 7:31 am Post subject: |
|
|
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: |
# ---------------------------------------
# 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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Feb 21, 2013 10:51 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Thu Feb 21, 2013 1:39 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Feb 22, 2013 2:14 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Fri Feb 22, 2013 7:32 am Post subject: |
|
|
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: |
<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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Feb 23, 2013 4:45 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Sat Feb 23, 2013 5:56 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
StormG Voice
Joined: 05 Jan 2013 Posts: 9
|
Posted: Sat Feb 23, 2013 1:18 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Sat Feb 23, 2013 1:27 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Feb 23, 2013 1:33 pm Post subject: |
|
|
Nah, thanks I'm fine thank you. Anyway, I'm busy with something else.  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
|