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.

good voting script?

Old posts that have not been replied to for several years.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

good voting script?

Post by arcane »

hi

looking for a good voting-script. should have the following functions:

- setting the timespan in minutes and hours
- dynamic answers (e.g. !vote 12m We'd like to do bla. What do you think
about? : yes, no, perhaps,
don't know -> users can vote for yes, no, perhaps and don't know)
- vote for anyone or ops only
- more than one voting session at the same time

any idea?
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

I'm thinking about writing a script like that! What kind of security would be good? Bot users only, or by ip address? Or only +v's in the channel? etc
d
dvV
Voice
Posts: 30
Joined: Wed Jan 29, 2003 4:08 pm

Post by dvV »

would be very cool to have it set up to only allow one vote per host yadda yadda. after you got it working the more options (for stricter/looser) votes would be cool. we have actually been using on on #eggdrop@dalnet for a a few months. no one really got into it though for maybe the fact that it lacked options, security, and of course the fact that how many channel ops do you know are around at the same time of day every day. something that had a list of active ops to notify that a vote is in session when they came away from idle or even annoyed the voter every hr and such to ensure a fair vote would be cool. all kinds of stuff that could be done with this idea.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

hm... seems there isn't such a script already. guess i'll have to write it...
do you think, this would be possible for my first script? :D (just coding c++ and javascript...). or i'll wait til stdragon finished his script :D
i've got the channel voter script by loki`from the scripts-section. it isn't that bad, but it lacks some functions.
security: hm.. guess i won't have to think about that. the chan isn't very big oder popular... but ip oder hostmask would be best i think
dvV wrote:would be very cool to have it set up to only allow one vote per host
that's one of the features of the channel voter script. it also reminds user who haven't voted yed and are allowed to vote. as i said, not bad, but only one vote at the same time and only the answers "yes" or "no"...
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

just started writing my own voting-script but i think i'll have to bother
you with some questions...

first:
the input should be like this

!vote <time> <question> <answers>

e.g.

!vote 10m "Do you write programs? and if yes, how long per week?" "1 hour: 2
hours : 3 hours:4 hours, more than 5 hours:i don't write at all:well, don't
care"

i thougt, it would be best, to put the topic (or question) and the answers
into "" and to separate the different answers with ":". do you think this is
practical?
how should the proc look like?

proc any_vote {nick mask hand chan args}

?

and i'd get time, topic and answers by split $args?

by just typing "!vote" without any arguments, the bot should give
information about current / last vote. how should i solve this?

if {$args == ""}

would this work?

ok, and second:
let's say, the answers are separated by ":" each and i've got them in ONE
variable. how would i get the different answer-possibilities? the problem
is, that they could be separated by " :", " : ", ": " or just ":". first
split $args :, but then? is there any funktion like "trim left/trim right"
in c++? or should i first replace all " :", ": ", " : " by ":"? but how
would this look like?

hope, these aren't too stupid questions ;) and if anything isn't clear, just
ask. guess my english isn't the best :) i've got marijn's tclguide but i
guess i'll need much more examples to understand tcl :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

FOr spliting and trimming.

Use split on ":", then use "string trim"

You could use "string trimleft", or "string trimright". But this kills two birds with one stone.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

ok thanks, but i've some problems handling the arguments...

Code: Select all

proc any_vote {nick mask hand chan args} {
global botnick
	if {$args == ""} {
		puthelp "PRIVMSG $chan No params."
	} else {
		set time [lindex [split $args] 0]
		set topic [lindex [split $args] 1]
		set answers [lrange [split $args] 2 end]
		puthelp "PRIVMSG $chan time: $time, topic: $topic, answers: $answers"
	}
}
can't get this to work :(

input should be:

!vote 10m "this is the topic" "these:are:the:different:answers"

guess i'm too stupid for tcl... :roll:
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

No. It's not that your too stupid, you don't just don't grasp allt he concepts, or how to convert things properly.

There are many issues witht he way you wish to handle your script. Some of them trivial, and others requiring more effort.

First, you can't use $args you way you have. In Tcl, the $args (the name args, not anything else) variable has a special meaning.

Normaly, if you create a rpocedure, you have to pass exactly the right amount of arguments. No more, no less. There are two exeptions to this.

1: You can pass less arguments (but not more), if you setup default values for some of the arguments.

IE.

Code: Select all

proc test {a b {c ""} {d ""}} {
return $a
}
The above, you can pass 2, 3 or 4 arguments. Nor more, no less. If you use less than 4, then default values are used.

2: You can 0 or more (upto unlimted) arguments, when using the $args variable. This allows you do all the setup of variables, wihtin the script itself.

IE

Code: Select all

proc test {a b c d} {
} 

is the same as

proc test {args} {
  set a [lindex $args 0]
  set b [lindex $args 1]
  set c [lindex $args 2]
  set d [lindex $args 3]
}
In your script, you can simply change $args (and other parts of variable naming) to arg, and nothing should be wrong.

The harder task, is with splitting the collected information about the vote, into it's component pieces.

Using split on a string like the incoming text from IRC, will split it into seperate words. There is no default way, to split the text from
newvote 10m "What is your favourate colour" "blue:red:orange"
so that the time, quoestion and answeres are seperate. Simply enclosing them in quotes, isn't enough for Tcl to split it correctly.

It is upto the programmer to go through the text, and split it up acordingly.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

thanks
i've got a newer version now. works better :D i knew that "args" isn't a variable like all the others (says the tutorial too), but i didn't know how to handle it right (now i know - took a closer look at the tutorial :D) it's just that i'm new to tcl and it's a bit different than c++. think i'll get it :D

and with "args" and "arg": you mean, "arg" would allow the same input? thought it wouldn't work, because there's more than 1 argument... well, i'll see :D
It is upto the programmer to go through the text, and split it up acordingly.
that's my next problem :D will have to search functions for that. would it work, that i set 3 strings and just add all words until the next " comes? well, stupid question, i'll simply try :D
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

seems to work! :D

Code: Select all

proc vote {nick mask hand chan arg} {
global botnick 
 if {$arg == ""} {
   puthelp "PRIVMSG $chan :No arguments."
  return 0
 } else {
  set time [lindex $arg 0]
  set topic [lindex $arg 1]
  set answers [lindex $arg 2]
  puthelp "PRIVMSG $chan :time: $time, topic: $topic, answers: $answers"
 }
}
e.g. input: !vote 10m "is this a vote?" "yes:no:maybe"

time is "10m", topic is "is this a vote?", answers is "yes:no:maybe".
perhaps i'm not that stupid at all :D
*misses.his.debug.mode*
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

one more question:
i've got a list $answers with all possible answers. now i'd need a second list of the same size for counting how often an answer is given. how can i set such a list? (all items should be "0")
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

You need to split each of the possible answers up, and create some form of array, using either hash tables (Tcl calls them arrays), or Tcl lists (Which are keyless arrays).

Along with this array data, should be a values.
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

ok, don't understand anything of what you said :-? no easier way? ;) guess i'll have to take another close look at my tuturial... or could you give me an example?
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

did you mean this? if not, what do you think of the idea?

Code: Select all

set count "0"

for {set number "1"} {$number < [llength $answers]} {incr number} {
    append $count " 0"
}
set $count [split $count]
edit: should be set number "1" :D
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

what did you mean ppslim?
Locked