summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarJanik Kleinhoff <ilbelkyr@shalture.org>2016-02-14 01:26:49 +0000
committerLibravatarJanik Kleinhoff <ilbelkyr@shalture.org>2016-02-14 01:26:49 +0000
commitb94bc040e22560259f7f7ac0dd7a044edf4f6aa5 (patch)
treefb8f2ba1210c1aba5e4cc4b4684e6b79379c4f6c
parentb91e545add34ab42915ed054b5da18be2bff16ae (diff)
;suppress: don't touch the monitor flag
-rw-r--r--lib/ASM/Commander.pm35
-rw-r--r--lib/ASM/Inspect.pm2
-rw-r--r--lib/ASM/Util.pm14
3 files changed, 44 insertions, 7 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 {
diff --git a/lib/ASM/Inspect.pm b/lib/ASM/Inspect.pm
index 14796ee..363be54 100644
--- a/lib/ASM/Inspect.pm
+++ b/lib/ASM/Inspect.pm
@@ -94,7 +94,7 @@ sub inspect {
# because we can't yet respect stuff like notrigger for these
next unless $::synced{lc $chan};
next unless $chan =~ /^#/;
- next if ((defined($::channels->{channel}->{$chan}->{monitor})) and ($::channels->{channel}->{$chan}->{monitor} eq "no"));
+ next unless ASM::Util->mayAlert($chan);
foreach $id (keys %aonx) {
next unless ( grep { $event->{type} eq $_ } split(/[,:; ]+/, $aonx{$id}{type}) );
if (defined($response)) {
diff --git a/lib/ASM/Util.pm b/lib/ASM/Util.pm
index e6519de..6372037 100644
--- a/lib/ASM/Util.pm
+++ b/lib/ASM/Util.pm
@@ -117,6 +117,20 @@ sub speak
return 1;
}
+sub isSuppressed {
+ my ($module, $chan) = @_;
+
+ # While we set a timer to remove the suppression, this check allows it to Just Work(tm) even across bot restarts.
+ my $expiration = $::channels->{channel}{lc $chan}{suppress} // 0;
+ return (($expiration > time) ? $expiration : undef);
+}
+
+sub mayAlert {
+ my ($module, $chan) = @_;
+
+ return !( ($::channels->{channel}{lc $chan}{monitor} // 'yes') eq 'no' || $module->isSuppressed($chan) );
+}
+
#this item is a stub, dur
sub hostip {
return gethostbyname($_[0]);