|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<!DOCTYPE MudletPackage> |
| 3 | +<MudletPackage version="1.001"> |
| 4 | + <TriggerPackage> |
| 5 | + <Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no"> |
| 6 | + <name>OnConnect</name> |
| 7 | + <script>vote.checkLastVoted()</script> |
| 8 | + <triggerType>0</triggerType> |
| 9 | + <conditonLineDelta>0</conditonLineDelta> |
| 10 | + <mStayOpen>0</mStayOpen> |
| 11 | + <mCommand></mCommand> |
| 12 | + <packageName></packageName> |
| 13 | + <mFgColor>#ff0000</mFgColor> |
| 14 | + <mBgColor>#ffff00</mBgColor> |
| 15 | + <mSoundFile></mSoundFile> |
| 16 | + <colorTriggerFgColor>#000000</colorTriggerFgColor> |
| 17 | + <colorTriggerBgColor>#000000</colorTriggerBgColor> |
| 18 | + <regexCodeList> |
| 19 | + <string>Welcome to the land of SlothMUD. May your visit here be... Interesting.</string> |
| 20 | + <string>Reconnecting.</string> |
| 21 | + </regexCodeList> |
| 22 | + <regexCodePropertyList> |
| 23 | + <integer>3</integer> |
| 24 | + <integer>3</integer> |
| 25 | + </regexCodePropertyList> |
| 26 | + </Trigger> |
| 27 | + </TriggerPackage> |
| 28 | + <TimerPackage /> |
| 29 | + <AliasPackage /> |
| 30 | + <ActionPackage /> |
| 31 | + <ScriptPackage> |
| 32 | + <Script isActive="yes" isFolder="no"> |
| 33 | + <name>vote</name> |
| 34 | + <packageName></packageName> |
| 35 | + <script>-- SlothMUD Vote Helper -------------------------------------------------------- |
| 36 | +-- Keeps track of when you last voted (at least if you launch from mudlet) |
| 37 | +-- and reminds you to vote if it's time to vote again @ sign-in |
| 38 | + |
| 39 | +vote = vote or {} -- a table to act as a bag to stuff things into. I guess. Lua... |
| 40 | + |
| 41 | +-- "Constants" |
| 42 | +vote.MODULE_NAME = "vote" |
| 43 | +vote.SAVE_FILENAME = "vote.last" |
| 44 | +vote.VOTING_SITES = { |
| 45 | + tms = { |
| 46 | + name = "Top Mud Sites", |
| 47 | + url = "http://www.topmudsites.com/vote-Splork.html", |
| 48 | + duration = 12*60*60, -- seconds required between vote attempts. ie 12 hours worth |
| 49 | + } |
| 50 | +} |
| 51 | +vote.DURATION_BUFFER = 3*60 -- seconds after duration expired before valid for prompting |
| 52 | + |
| 53 | + |
| 54 | +-- display debug/information messages to screen in consistent manner |
| 55 | +function vote.echo(message) |
| 56 | + cecho("<orange_red>[ vote ] - <steel_blue>"..message.."\n") |
| 57 | +end |
| 58 | + |
| 59 | +-- return where to save last voted record depending on whether installed as module or package |
| 60 | +function vote.getLastVotedPath() |
| 61 | + return (getModulePath(vote.MODULE_NAME) or getMudletHomeDir()):gsub("/vote[.]xml$","").."/"..vote.SAVE_FILENAME |
| 62 | +end |
| 63 | + |
| 64 | +-- check when last voted |
| 65 | +function vote.checkLastVoted() |
| 66 | + |
| 67 | + local voting_sites = vote.VOTING_SITES |
| 68 | + local file_path = vote.getLastVotedPath() |
| 69 | + if io.exists(file_path) then |
| 70 | + table.load(file_path, voting_sites) |
| 71 | + end |
| 72 | + |
| 73 | + for site_key,site in pairs(voting_sites) do |
| 74 | + local current_time = os.time() |
| 75 | + |
| 76 | + if site.last_voted == nil or site.last_voted + site.duration + vote.DURATION_BUFFER < current_time then |
| 77 | + local delta = "FOREVER" |
| 78 | + if site.last_voted then |
| 79 | + delta = math.floor((os.time() - site.last_voted) / 60 / 60) .. " hours" |
| 80 | + end |
| 81 | + -- this function is buggy and truncates leading spaces unlike cecho |
| 82 | + cechoLink([[<lime_green> |
| 83 | + |
| 84 | +| VV\ VV\ OOOOOO\ TTTTTTTT\ EEEEEEEE\ !!\ |
| 85 | +| VV | VV |OO __OO\ \__TT __|EE _____|!! | |
| 86 | +| VV | VV |OO / OO | TT | EE | !! | |
| 87 | +| \VV\ VV |OO | OO | TT | EEEEE\ !! | |
| 88 | +| \VV\VV / OO | OO | TT | EE __| \__| |
| 89 | +| \VVV / OO | OO | TT | EE | |
| 90 | +| \V / OOOOOO | TT | EEEEEEEE\ !!\ |
| 91 | +| \_/ \______/ \__| \________|\__| |
| 92 | +| |
| 93 | +| >>> <yellow>Click here to vote now<lime_green> <<< |
| 94 | +| |
| 95 | +| It has been more than <green> ]]..delta..[[ <lime_green> since you last voted at <green>]]..site.name..[[<lime_green>. |
| 96 | + ]],[[vote.launchWindow("]]..site_key..[[")]],"VOTE! VOTE!",true) |
| 97 | + end |
| 98 | + end |
| 99 | +end |
| 100 | + |
| 101 | +function vote.launchWindow(site_key) |
| 102 | + local voting_sites = vote.VOTING_SITES |
| 103 | + local file_path = vote.getLastVotedPath() |
| 104 | + if io.exists(file_path) then |
| 105 | + table.load(file_path, voting_sites) |
| 106 | + end |
| 107 | + openUrl(voting_sites[site_key].url) |
| 108 | + voting_sites[site_key].last_voted = os.time() |
| 109 | + table.save(file_path,voting_sites) |
| 110 | +end |
| 111 | + |
| 112 | +vote.echo("Will use:"..vote.getLastVotedPath())</script> |
| 113 | + <eventHandlerList /> |
| 114 | + </Script> |
| 115 | + </ScriptPackage> |
| 116 | + <KeyPackage /> |
| 117 | + <HelpPackage> |
| 118 | + <helpURL></helpURL> |
| 119 | + </HelpPackage> |
| 120 | +</MudletPackage> |
0 commit comments