$include $lib/alynna : alt?[ d:target1 d:target2 -- b:result ] target1 @ target2 @ dbcmp if 0 exit then target1 @ "/@pc/aka/" target2 @ reflist_find if 1 exit then 0 ; PUBLIC alt? $def AYB "/_polls/" $def AVATAR "$AVATAR" match $def WALL AVATAR { rot trig "_defchan" getpropstr " " rot }cat force $def PRINT dup tostr tellme $def }tell }cat "Poll" pretty tellme $def }print }cat tellme lvar param lvar item lvar itemdesc lvar poller lvar polltype lvar responses lvar btime lvar etime lvar trigname ( Define this if you will place this program into MUFCron ) $def MUFCRON "Yea" $ifdef MUFCRON $include $muf/cron $endif : yn if "Yes" else " No" then ; : xname ( d -- s ) dup #-2 dbcmp if pop "*Nobody*" else name then ; : delitem ( i/s -- ) var target toint tostr target ! trig { AYB target @ }cat remove_prop { "Item " target @ " taken off the polling board." }cat WALL ; : resolveitem ( i/s -- i ) var target var item var propcheck tostr target ! ( Check for numeric match ) target @ toint 0 > if trig AYB target @ "/item" strcat strcat getprop tostr "" stringcmp if trig AYB target @ "/item" strcat strcat getpropstr if target @ toint exit ( Number points at a valid poll ) else 0 exit then then then ( Check for item name match, return item number ) trig AYB array_get_propdirs foreach item ! pop trig AYB item @ "/item" strcat strcat getpropstr propcheck ! propcheck @ "" stringcmp propcheck @ target @ stringpfx and if item @ toint exit then repeat ( Or else return 0 ) 0 ; : refreshpoll ( i/s -- ) var btimex var itemx var value var temp resolveitem tostr btimex ! trig { AYB btimex @ "/byResponse/" }cat array_get_propvals foreach value ! itemx ! trig { AYB btimex @ "/byResponse/" itemx @ }cat 0 setprop repeat trig { AYB btimex @ "/byPerson/" }cat array_get_propvals foreach value ! itemx ! trig { AYB btimex @ "/byResponse/" value @ }cat over over getprop 1 + setprop repeat ; : loaditem ( i/s -- ) var btimex resolveitem tostr btimex ! trig { AYB btimex @ "/item" }cat getprop item ! trig { AYB btimex @ "/itemdesc" }cat getprop itemdesc ! trig { AYB btimex @ "/poller" }cat getprop poller ! trig { AYB btimex @ "/polltype" }cat getprop polltype ! trig { AYB btimex @ "/btime" }cat getprop btime ! trig { AYB btimex @ "/etime" }cat getprop etime ! trig { AYB btimex @ "/byPerson/" }cat array_get_propvals array_count responses ! btimex @ refreshpoll ; : saveitem ( i -- ) var btimex toint tostr btimex ! trig { AYB btimex @ "/item" }cat item @ setprop trig { AYB btimex @ "/itemdesc" }cat itemdesc @ setprop trig { AYB btimex @ "/poller" }cat poller @ setprop trig { AYB btimex @ "/polltype" }cat polltype @ setprop trig { AYB btimex @ "/btime" }cat btime @ setprop trig { AYB btimex @ "/etime" }cat etime @ setprop btimex @ refreshpoll ; : arcitem[ trigger -- ] trigger @ { AYB btime @ }cat trigger @ { "/arc/" btime @ }cat 1 copyprops pop trigger @ { AYB btime @ }cat remove_prop ; : displayitem ( -- ) var tmp var itemx var value var btimex btime @ btimex ! (1) { "Poll #" btimex @ " - " item @ }cat header tellme (2) { "Poll number: [^CYAN^" btime @ "^NORMAL^] Poller: [^CYAN^" poller @ xname tostr 12 lj "^NORMAL^]" }print (3) { "Poll start: [^CYAN^" "%x %X" btime @ timefmt "^NORMAL^]" }print (4) { "Time left: [^CYAN^" btime @ etime @ + systime - timex "^NORMAL^]" }print (5) "Description" header tellme (6) itemdesc @ wrap78 atellme (7) "Results" header tellme polltype @ if { "Yes|" trig { AYB btimex @ "/byResponse/Y" }cat getprop dup toint tmp ! tostr 3 rj " " tmp @ responses @ 1.0 * / 100.0 * error? if pop 0.0 then 1 fchop 5 rj "% |" tmp @ responses @ statbar "|" }print { " No|" trig { AYB btimex @ "/byResponse/N" }cat getprop dup toint tmp ! tostr 3 rj " " tmp @ responses @ 1.0 * / 100.0 * error? if pop 0.0 then 1 fchop 5 rj "% |" tmp @ responses @ statbar "|" }print else trig { AYB btimex @ "/byResponse/" }cat array_get_propvals foreach value ! itemx ! { itemx @ tostr 3 rj "|" value @ toint dup tmp ! tostr 3 rj " " tmp @ responses @ 1.0 * / 100.0 * error? if pop 0.0 then 1 fchop 5 rj "% |" tmp @ responses @ statbar "|" }print repeat then { "To register your vote: +poll/vote " item @ "=" }cat footer tellme ; : newpoll "Please enter the name for this poll:" "Poll" pretty tellme read item ! "Please enter the question you want to ask, for examples: " "Poll" pretty tellme "Do you like apple pie (Y/N)" "Poll" pretty tellme "What kind of pie do you like? (1)Apple (2)Cherry (3)Lemon meringue" "Poll" pretty tellme read itemdesc ! "What kind of answers should I take for this poll? (0)Numeric[default] (1)Yes/No only" "Poll" pretty tellme read toint polltype ! polltype @ 0 < polltype @ 1 > or if 0 polltype ! then "And how many hours would you like the auction to last? (0 for the default, 72 hours)" "Poll" pretty tellme read dup toint not if tofloat else toint tofloat then etime ! etime @ 0.0 <= if 72.0 etime ! then etime @ 3600.0 * toint etime ! systime btime ! me @ poller ! displayitem "Does this look good to you? (Y/N)" "Poll" pretty tellme read "y" stringpfx not if "Aborted." "Poll" pretty tellme exit then btime @ saveitem { "Item (" btime @ ") placed onto the poll board by " poller @ xname ", called '" item @ ". +" trig truename "/view " item @ " to look at and vote in this poll." }cat WALL ; : answeritem var itemx var answer var btimex var target force_level if "Someone has attempted to force you to vote. Vote cancelled." "Poll" pretty tellme prog "?" flag? if AVATAR { "wc #Someone has attempted to force " me @ " to vote. (Check the logfile)" }cat force then exit then ( Security patch! ) param @ "=" explode 2 = not if "Syntax, +*/vote =" "Poll" pretty tellme exit then tostr itemx ! answer ! itemx @ resolveitem dup 0 > if itemx ! else pop { "Couldn't match your item '" itemx @ "'." }cat "Poll" pretty tellme exit then itemx @ loaditem btime @ etime @ + systime - 1 < if "This poll is over, no more answers permitted." "Poll" pretty tellme exit then btime @ btimex ! ( alt test ) trig { AYB btimex @ "/ByPerson/" }cat array_get_propvals foreach pop atoi dbref target ! me @ target @ alt? me @ target @ dbcmp not and if "One of your alts already voted." "Vote" pretty tellme prog "?" flag? if AVATAR { "wc #" me @ " has attempted to vote when their alt already voted. THEY ARE TEH SUX" }cat force then exit then repeat ( Log result ) polltype @ if answer @ tostr capitalize 1 strcut pop answer ! answer @ "Y" stringpfx answer @ "N" stringpfx or if trig { AYB btimex @ "/ByPerson/" me @ int }cat answer @ setprop { "You have answered '" answer @ "' to this poll." }cat "Poll" pretty tellme else { "Umm, you must answer 'Yes' or 'No' to this poll." }cat "Poll" pretty tellme then else answer @ toint answer ! answer @ 0 > if trig { AYB btimex @ "/ByPerson/" me @ int }cat answer @ setprop { "You have answered [" answer @ "] to this poll." }cat "Poll" pretty tellme else { "Umm, you must give a valid numeric response." }cat "Poll" pretty tellme then then itemx @ saveitem ; : listitems "^BCYAN^Number____ Name____________________ Res Poller______ TimeLeft^NORMAL^" tellme trig AYB array_get_propdirs foreach item ! pop item @ toint loaditem { btime @ tostr 10 lj " " item @ tostr 24 lj " " responses @ tostr 3 rj " " poller @ xname tostr 12 lj " " { "{stimestr:" btime @ etime @ + systime - "}" }cat mpime " " }cat tellme repeat ; : listitemsarc var btimex var itemx var value var temp "^BCYAN^Number____ Name____________________ Res Poller______ ^NORMAL^" tellme trig "/arc/" array_get_propdirs foreach item ! pop item @ btimex ! trig { "/arc/" btimex @ "/item" }cat getprop item ! trig { "/arc/" btimex @ "/itemdesc" }cat getprop itemdesc ! trig { "/arc/" btimex @ "/poller" }cat getprop poller ! trig { "/arc/" btimex @ "/btime" }cat getprop btime ! trig { "/arc/" btimex @ "/etime" }cat getprop etime ! trig { "/arc/" btimex @ "/byPerson/" }cat array_get_propvals array_count responses ! { btime @ tostr 10 lj " " item @ tostr 24 lj " " responses @ tostr 3 rj " " poller @ xname tostr 12 lj " " }cat tellme repeat ; : showitem param @ resolveitem dup 0 > if dup loaditem displayitem else { "Couldn't match your item '" param @ "'." }cat "Poll" pretty tellme then ; : showitemarc var btimex var itemx var value var tmp param @ btimex ! trig { "/arc/" btimex @ "/item" }cat getpropstr item ! trig { "/arc/" btimex @ "/itemdesc" }cat getpropstr itemdesc ! trig { "/arc/" btimex @ "/btime" }cat getpropval btime ! trig { "/arc/" btimex @ "/etime" }cat getpropval etime ! trig { "/arc/" btimex @ "/polltype" }cat getprop polltype ! trig { "/arc/" btimex @ "/poller" }cat getprop poller ! trig { "/arc/" btimex @ "/byPerson/" }cat array_get_propvals array_count responses ! trig { "/arc/" btimex @ "/byResponse/" }cat array_get_propvals foreach value ! itemx ! trig { "/arc/" btimex @ "/byResponse/" itemx @ }cat 0 setprop repeat trig { "/arc/" btimex @ "/byPerson/" }cat array_get_propvals foreach value ! itemx ! trig { "/arc/" btimex @ "/byResponse/" value @ }cat over over getprop 1 + setprop repeat (1) { "Poll " btimex @ " - " item @ }cat header tellme item @ not if "-" item ! then (2) { "Poll number: [^CYAN^" btime @ "^NORMAL^] Poller: [^CYAN^" poller @ xname tostr 12 lj "^NORMAL^]" }print (3) { "Poll start: [^CYAN^" "%x %X" btime @ timefmt "^NORMAL^]" }print (4) "Description" header tellme (5) itemdesc @ wrap78 atellme (6) "Results" header tellme (7) polltype @ if { "Yes|" trig { "/arc/" btimex @ "/byResponse/Y" }cat getprop dup toint tmp ! tostr 3 rj " " tmp @ responses @ 1.0 * / 100.0 * error? if pop 0.0 then 1 fchop 5 rj "% |" tmp @ responses @ statbar "|" }print { " No|" trig { "/arc/" btimex @ "/byResponse/N" }cat getprop dup toint tmp ! tostr 3 rj " " tmp @ responses @ 1.0 * / 100.0 * error? if pop 0.0 then 1 fchop 5 rj "% |" tmp @ responses @ statbar "|" }print else trig { "/arc/" btimex @ "/byResponse/" }cat array_get_propvals foreach value ! itemx ! { itemx @ tostr 3 rj "|" value @ toint dup tmp ! tostr 3 rj " " tmp @ responses @ 1.0 * / 100.0 * error? if pop 0.0 then 1 fchop 5 rj "% |" tmp @ responses @ statbar "|" }print repeat then "Voting is closed for this item" footer tellme ; : sanfix var itemx var answer var btimex var target1 var target2 var pollarray me @ "W" flag? not if "You're not staff, go away." "Vote/Sanfix" pretty tellme exit then param @ "=" explode 1 = not if "Syntax, +poll/sanfix " "Poll" pretty tellme exit then tostr itemx ! itemx @ resolveitem dup 0 > if itemx ! else pop { "Couldn't match your item '" itemx @ "'." }cat "Poll" pretty tellme exit then itemx @ loaditem btime @ btimex ! ( alt test and sanity check ) trig { AYB btimex @ "/ByPerson/" }cat array_get_propvals foreach pop atoi dbref target1 ! trig { AYB btimex @ "/ByPerson/" }cat array_get_propvals foreach pop atoi dbref target2 ! target2 @ target1 @ alt? if trig { AYB btimex @ "/ByPerson/" target1 @ int }cat getprop if { "Removing alt vote '" target2 @ "' by '" target1 @ "'." }cat "Vote" pretty tellhere trig { AYB btimex @ "/ByPerson/" target2 @ toint }cat 0 setprop then then repeat repeat btimex @ refreshpoll ; : pollheart background $ifndef MUFCRON AVATAR "!wc #Poll heart activated." force begin $endif #-1 "*" "E" find_array "_defchan" "*" array_filter_prop foreach swap pop dup var! trigger AYB array_get_propdirs foreach var! item pop item @ toint loaditem systime btime @ etime @ + >= if AVATAR { trigger "_defchan" getpropstr " Poll '" item @ "' has ended." }cat force trigger @ arcitem then repeat repeat $ifndef MUFCRON 60 sleep repeat $endif ; : pollhelp "Polling system v1 by Alynna" tellme { " " trig truename " -- This help" }cat tellme " /list List all polls" tellme " /view Read a poll" tellme " /vote Submit a vote/answer on a poll" tellme " /add Add a new poll" tellme " /del Remove a poll " tellme " /sanfix Sanity fix a poll " tellme " /closed Show all closed polls" tellme " /cview View a closed poll" tellme ; : main param ! trig truename trigname ! $ifdef MUFCRON param @ mufcron? if pollheart exit then $else command @ "Queued event." stringcmp not if pollheart exit then $endif command @ "*/view" smatch if showitem exit then command @ "*/vote" smatch if answeritem exit then command @ "*/sanfix" smatch if sanfix exit then command @ "*/add" smatch if newpoll exit then command @ "*/del" smatch if param @ delitem exit then command @ "*/closed" smatch if listitemsarc exit then command @ "*/cview" smatch if showitemarc exit then command @ "*/help" smatch if pollhelp exit then listitems { "Type '+" trigname @ "/help' for help." }cat "Poll" pretty tellme { "Type '+" trigname @ "/view ' to view a poll." }cat "Poll" pretty tellme ;