From 0c549bf3dec9eb00726018694d83365a3467ae7a Mon Sep 17 00:00:00 2001 From: Brandon Cornejo Date: Sun, 3 Feb 2019 19:11:22 -0600 Subject: [PATCH] Quota timer, in prompt, reset on new login --- config.tin | 3 +- src/gmcp.tin | 3 ++ src/prompt.tin | 11 +++- src/quota.tin | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 src/quota.tin diff --git a/config.tin b/config.tin index 920c8f9..770cb91 100644 --- a/config.tin +++ b/config.tin @@ -21,6 +21,7 @@ #READ {src/xpmonitor.tin}; #READ {src/tpamonitor.tin}; #READ {src/spottimers.tin}; +#READ {src/quota.tin}; #READ {src/combat.tin}; #READ {src/deadletter.tin}; @@ -28,7 +29,7 @@ #READ {src/magic.tin}; #READ {src/missions.tin}; -#READ{src/group.tin}; +#READ {src/group.tin}; #SESSION {discworld} {discworld.starturtle.net} {4242}; diff --git a/src/gmcp.tin b/src/gmcp.tin index 522851c..fbbc319 100644 --- a/src/gmcp.tin +++ b/src/gmcp.tin @@ -47,6 +47,9 @@ { #IF {"$debug" == "1"} { #SHOWME %1 }; #VAR GMCP[charinfo] {%0}; + + #nop New login, invalidate stale info; + #unvar {quota}; } #EVENT {IAC SB GMCP room.info IAC SE} diff --git a/src/prompt.tin b/src/prompt.tin index fa8615e..709c5c1 100644 --- a/src/prompt.tin +++ b/src/prompt.tin @@ -17,15 +17,22 @@ #ALIAS {update_prompt} { + #nop XP monitor details; xp_monitor; #format {prompt_xp} {%Gxp in %s (%Gk/h)} {$session_xp} {$uptime[display]} {$xprate}; + #nop TPA monitor details; #var {prompt_tpa} {}; - #if {$tpa_status == 1} { #format {prompt_tpa} {%cTPA%c} {@tpa_col{$tpa_color}} {<098>}; }; - #format {prompt_line} {%+5s %+40s} {$prompt_tpa} {$prompt_xp}; + #nop Quota monitor details; + #var {prompt_quota} {}; + #if {"a} { + #format {prompt_quota} {Quota: %s} {@quota_time_left{}}; + }; + + #format {prompt_line} {%+5s %+40s %+15s} {$prompt_tpa} {$prompt_xp} {$prompt_quota}; #showme {$prompt_line} {-1}; } diff --git a/src/quota.tin b/src/quota.tin new file mode 100644 index 0000000..62a282b --- /dev/null +++ b/src/quota.tin @@ -0,0 +1,142 @@ +#CLASS {QUOTA} {KILL}; +#CLASS {QUOTA} {OPEN}; + +#unvar quota; + +#nop ==[ Parse 'read quota brief' output ]==; +#action {^ Receipts received: A\$%1.$} +{ + #var quota[reciepts] %1; +} +#action {^ Receipts received: %1p.$} +{ + #math quota[reciepts] {%1 * 0.01}; +} + +#action {^ Min quota: A\$%1.$} +{ + #var quota[min] %1; +} + +#action {^ Max quota: A\$%1.$} +{ + #var quota[max] %1; +} + +#action {^ Amount owed: A\$%1.$} +{ + #var quota[owed] %1; +} +#action {^ Amount owed: %1p.$} +{ + #math quota[owed] {%1 * 0.01}; +} + +#action {^ Amount paid: A\$%1.$} +{ + #var quota[paid] %1; +} +#action {^ Amount paid: %1p.$} +{ + #math quota[paid] {%1 * 0.01}; +} +#action {^ Time left: %1.$} { + #regex {%1} {%d hour{s?}} { + #var {quota[time][hour]} {&1}; + } { #var {quota[time][hour]} {0} }; + #regex {%1} {%d minute{s?}} { + #var {quota[time][min]} {&1}; + } { #var {quota[time][min]} {0} }; + #regex {%1} {%d second{s?}} { + #var {quota[time][sec]} {&1}; + } { #var {quota[time][sec]} {0} }; + + #var {quota[who]} {$GMCP[charinfo][capname]}; + #var {quota[alert]} {on}; +} + + +#tick {quota_time} +{ + #nop If we have no quota info, do nothing; + #if {!&{quota[time]}} { + #return; + }; + + #nop Subtract a second, calculate new times; + #math {quota[time][sec]} {$quota[time][sec] - 1}; + #if {$quota[time][sec] < 0} { + #math {quota[time][min]} {$quota[time][min] - 1}; + #math {quota[time][sec]} {$quota[time][sec] + 60}; + + #nop Update prompt; + update_prompt; + }; + #if {$quota[time][min] < 0} { + #math {quota[time][hour]} {$quota[time][hour] - 1}; + #math {quota[time][min]} {$quota[time][min] + 60}; + }; + #if {$quota[time][hour] < 0} { + #math {quota[time][hour]} {$quota[time][hour] + 12}; + #var {quota[reciepts]} {0}; + + #nop Quota period is over, announce it.; + #format {quota_display_line} {%c[Quota] %c*%c %s's quota has %creset%c.} {bold blue} {bold yellow} {bold blue} {$quota[who]} {bold red} {bold blue}; + #showme {$quota_display_line}; + }; + + #nop Alert when quota is ending; + #if {"$quota[alert]" == "on"} { + #nop Message an hour before; + #if {$quota[time][hour] == 0 && $quota[time][min] == 59 && $quota[time][sec] == 59} { + #format {quota_display_line} {%c[Quota] %c*%c %s's quota flips over in %cone hour%c.} {bold blue} {bold yellow} {bold blue} {$quota[who]} {bold red} {bold blue}; + #echo {$quota_display_line \a}; + }; + + #nop Message 30 minutes before; + #if {$quota[time][hour] == 0 && $quota[time][min] == 29 && $quota[time][sec] == 59} { + #format {quota_display_line} {%c[Quota] %c*%c %s's quota flips over in %chalf an hour%c.} {bold blue} {bold yellow} {bold blue} {$quota[who]} {bold red} {bold blue}; + #echo {$quota_display_line \a}; + }; + + #nop Message 10 minutes before; + #if {$quota[time][hour] == 0 && $quota[time][min] == 9 && $quota[time][sec] == 59} { + #format {quota_display_line} {%c[Quota] %c*%c %s's quota flips over in %cten minutes%c.} {bold blue} {bold yellow} {bold blue} {$quota[who]} {bold red} {bold blue}; + #echo {$quota_display_line \a}; + }; + }; +} {1}; + + +#alias {quota alert %1} { + #if {"%1" == "on"} { + #var {quota[alert]} {on}; + } { + #var {quota[alert]} {off}; + }; +}; + + +#function {zero_pad} { + #if {%1 < 10} { + #format {result} {0%d} {%0}; + }; + #else { + #format {result} {%d} {%0}; + }; + + #return $result; +}; + +#function {quota_time_left} { + #if {$quota[time][hour] == 0 && $quota[time][min] < 60} { + #format {result} { %s:%s<099>} {@zero_pad{$quota[time][hour]}} {@zero_pad{$quota[time][min]}}; + } { + #format {result} {%s:%s<099>} {$quota[time][hour]} {@zero_pad{$quota[time][min]}}; + }; + + #return $result; +}; + + +#CLASS {QUOTA} {CLOSE};