diff options
| author | 2016-02-14 01:26:49 +0000 | |
|---|---|---|
| committer | 2016-02-14 01:26:49 +0000 | |
| commit | b94bc040e22560259f7f7ac0dd7a044edf4f6aa5 (patch) | |
| tree | fb8f2ba1210c1aba5e4cc4b4684e6b79379c4f6c /lib/ASM/Commander.pm | |
| parent | b91e545add34ab42915ed054b5da18be2bff16ae (diff) | |
;suppress: don't touch the monitor flag
Diffstat (limited to 'lib/ASM/Commander.pm')
| -rw-r--r-- | lib/ASM/Commander.pm | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/ASM/Commander.pm b/lib/ASM/Commander.pm index 0813dff..707d1ef 100644 --- a/lib/ASM/Commander.pm +++ b/lib/ASM/Commander.pm @@ -42,6 +42,9 @@ my $cmdtbl = { '^;suppress (?<chan>\S+) *$' => { 'flag' => 's', 'cmd' => \&cmd_suppress }, + '^;unsuppress (?<chan>\S+) *$' => { + 'flag' => 's', + 'cmd' => \&cmd_unsuppress }, '^;silence (?<chan>\S+) *$' => { 'flag' => 's', 'cmd' => \&cmd_silence }, @@ -371,19 +374,39 @@ sub cmd_monitor2 { sub cmd_suppress { my ($conn, $event) = @_; + my $minutes = 30; + my $duration = $minutes * 60; + my $chan = lc $1; my $old = $::channels->{channel}->{$chan}->{monitor}; if ($old eq 'no') { $conn->privmsg($event->replyto, "$chan is not currently monitored"); return; } - $::channels->{channel}->{$chan}->{monitor} = "no"; - $conn->schedule(30*60, sub { - $::channels->{channel}->{$chan}->{monitor} = $old; - $conn->privmsg($event->replyto, "Unsuppressed $chan"); - ASM::XML->writeChannels(); + $::channels->{channel}->{$chan}->{suppress} = time + $duration; + $conn->schedule($duration, sub { + if (($::channels->{channel}{$chan}{suppress} // 0) - 10 <= time) { + # we needn't actually delete this here, but doing so + # avoids cluttering the XML + delete $::channels->{channel}{$chan}{suppress}; + $conn->privmsg($event->replyto, "Unsuppressed $chan"); + ASM::XML->writeChannels(); + } }); - $conn->privmsg($event->replyto, "Suppressing alerts from $chan for 30 minutes. If the bot restarts or the config is changed, you will need to do ;monitor $chan to check the status of the monitor flag"); + $conn->privmsg($event->replyto, "Suppressing alerts from $chan for $minutes minutes."); +} + +sub cmd_unsuppress { + my ($conn, $event) = @_; + + my $chan = lc $1; + if (ASM::Util->isSuppressed($chan)) { + delete $::channels->{channel}{$chan}{suppress}; + $conn->privmsg($event->replyto, "Unsuppressed $chan"); + } + else { + $conn->privmsg($event->replyto, "Alerts for $chan are not currently suppressed"); + } } sub cmd_silence { |
