Poller

An object for taking polls. Allows for multiple choice answers.

Category: Other
Compatibility: CobraMUSH, PennMUSH, TinyBit, TinyMUX.

Instructions

Copy and paste the below code into a compatible MUSH or MUX.

MUSHCode for Poller

@create POLLER
@link POLLER==me
@DESCRIBE POLLER=[center(Polling,78,=)]%rThe following are the currently active polling topics. Type [ansi(hy,POLL HELP)] to see how you can participate. Ahhhh, democracy. Topics you haven't voted on yet will be highlighted in [ansi(bhr,red)].%r%r[iter(edit(lattr(me/POLLQ_*),POLLQ_,),[if(hasattr(me,POLLA_##_%#),##:,ansi(bhr,##:))][first(get(me/POLLQ_##),%r)],,%r)]%r[center(Code by Territan@OlympusIslandMUSH,78,=)]%R%RNote: This is a nice poll for when you want to poll staff or players on anything.
@set POLLER/DESCRIBE=no_command visual prefixmatch
&$POLL POLLER=$POLL: @pemit %#=[center(Polling,=)]%rThe following are the currently active polling topics. Type [ansi(hy,POLL HELP)] to see how you can participate. Ahhhh, democracy. Topics you haven't voted on yet will be highlighted in [ansi(bhr,red)].%r%r[iter(edit(lattr(me/POLLQ_*),POLLQ_,),[if(hasattr(me,POLLA_##_%#),##:,ansi(bhr,##:))][first(get(me/POLLQ_##),%r)],,%r)]%r
&POLL_ADD_STAR_STAR POLLER=$POLL ADD *=*: @switch [hasattr(me,POLLQ_[ucstr(%0)])]=1,{@pemit %#=POLL: Sorry, but there's already an active poll with that abbreviation.},0,{&POLLQ_%0 me=[first(%1,|)]|[ucstr(last(%1,|))]; @pemit %#=POLL: New poll "[ucstr(%0)]" has been set.}
&POLL_DELETE_STAR POLLER=$POLL DELETE *: @switch [setq(0,ucstr(%0))][hasattr(me,POLLQ_%q0)]=0,{@pemit %#=POLL: Sorry, but I can't find a poll labeled "%q0".},1,{&POLLQ_%q0 me; @wipe me/POLLA_%q0_*; @pemit %#=POLL: Poll "%q0" has been purged from the system. I hope you didn't need the results from it any more...}
&$POLL_HELP POLLER=$POLL HELP: @pemit %#=[center(Poll Help,78,-)]%rPOLL is a handy little way to ask questions and get answers. Use it frequently and copiously.%r[ansi(hy,POLL)] by itself will show what active polls there are on the machine at any given time. Each topic has a code in front of it, in green, which you should note for the next item:%r[ansi(hy,POLL LOOK <ABBREV>)] will let you see a specific poll topic, all the choices associated with it, and how voting's been running so far. Finally...%r[ansi(hy,POLL VOTE <ABBREV>=<ANSWER>)] will register your answer on the poll to be counted.%rThe admins have their own functions to add and remove polls, but not necessarily to see who voted how on which topic. After all, that might interfere with fair and honest polling.%r
&$POLL_HELP2 POLLER=$POLL HELP2: @pemit %#=[center(Staff Help for Poll,78,-)]%r[ansi(hy,POLL LIST)] will list all active polls. Simple.%r[ansi(hy,POLL VIEW <ABBREV>)] will show the poll in detail, and how voting has gone. Again, simple.%r[ansi(hy,POLL DELETE <ABBREV>)] will completely remove the poll from the list. Simple again.%r[ansi(hy,POLL ADD <ABBREV>=<TEXT>|<CHOICES>)] is where things get hairy. <TEXT> is the text of the poll, with %%r (carriage return) separating the question from the answers for formatting niceness. Use %%r between possible answers as you like. The v-bar is a separator which gets embedded in the question again for formatting reasons, and what follows the v-bar is a space-delimited list of possible answers (i.e. a b c d e f etc.) so the players can't get clever and put in multiword answers. The formatting of the results list allows for possible answers of up to three letters, if you really need them.%r
&$POLL_LOOK_STAR POLLER=$POLL LOOK *:@switch [setq(0,ucstr(%0))][hasattr(me,POLLQ_%q0)]=0,{@pemit %#=POLL: There is no currently active poll labeled "%q0"},1,{@pemit %#=[center(<< Poll Topic "%q0">>,78)]%r[first(get(me/POLLQ_%q0),|)]%r%r[setq(1,edit(lattr(me/POLLA_%q0_*),POLLA_%q0_,))][setq(2,setunion(iter(%q1,get(me/POLLA_%q0_##)),))][if(eq(%q1,0),Nobody has responded yet.,Out of [words(%q1)] respondant[if(eq(words(%q1),1),,s)]...%r[iter(%q2,[setq(3,words(grep(me,POLLA_%q0_*,##)))][rjust(##:,4)][rjust(%q3,2)][ansi(b[mid(rbgymcrbgymcrbgymcrbgymc,member(%q2,##),1)],repeat(>,div(mul(%q3,60),words(%q1))))][repeat(-,sub(60,div(mul(%q3,60),words(%q1))))],,%r)])]%r}
&$POLL_VOTE_STAR_STAR POLLER=$POLL VOTE *=*:@switch [setq(0,ucstr(%0))][setq(1,ucstr(%1))][hasattr(me,POLLQ_%q0)][t(member(last(get(me/POLLQ_%q0),|),%q1))][hasattr(me,POLLA_%q0_%#)]=0*,{@pemit %#=POLL: Sorry, but there is no active question "%q0".},10*,{@pemit %#=POLL: Sorry, but "%q1" is not one of the valid choices for poll "%q0"-- please use [itemize(last(get(me/POLLQ_%q0),|),%b,or,\,)].},110,{&POLLA_%q0_%# me=%q1; @pemit %#=POLL: Noted, you are answering question %q0 with "%q1".},111,{&POLLA_%q0_%# me=%q1; @pemit %#=POLL: Noted, you are changing your answer on question %q0 to "%q1"},{@pemit %#=POLL: Nothing matched the way you expected it to. The logic you got in here is SO boned...}