summaryrefslogtreecommitdiffstats
path: root/scripts/notonline.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:19:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:19:02 +0000
commit03929dac2a29664878d2c971648a4fe1fb698462 (patch)
tree02c5e2b3e006234aa29545f7a93a1ce01b291a8b /scripts/notonline.pl
parentInitial commit. (diff)
downloadirssi-scripts-03929dac2a29664878d2c971648a4fe1fb698462.tar.xz
irssi-scripts-03929dac2a29664878d2c971648a4fe1fb698462.zip
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/notonline.pl')
-rw-r--r--scripts/notonline.pl76
1 files changed, 76 insertions, 0 deletions
diff --git a/scripts/notonline.pl b/scripts/notonline.pl
new file mode 100644
index 0000000..57a28a8
--- /dev/null
+++ b/scripts/notonline.pl
@@ -0,0 +1,76 @@
+# Answers "$nick: No." if you're away and someone asks are you online on a channel.
+
+use strict;
+use Irssi;
+use locale;
+
+use vars qw($VERSION %IRSSI %answers $floodlimit %floodi);
+
+$VERSION = '0.9';
+%IRSSI = (
+ authors => 'Johan "Ion" Kiviniemi',
+ contact => 'ion at hassers.org',
+ name => 'NotOnline',
+ description =>
+'Answers "$nick: No." if you\'re away and someone asks are you online on a channel',
+ license => 'Public Domain',
+ url => 'http://ion.amigafin.org/irssi/',
+ changed => 'Tue Mar 12 22:20 EET 2002',
+);
+
+%answers = (
+ 'online' => 'Offline.',
+ 'there' => 'Not here.',
+ 'idle' => 'Of course.',
+ 'paikalla' => 'En, vaan paikassa.',
+ 'siellä' => 'Ei kun tuolla.',
+ 'siellä' => 'Ei kun tuolla.',
+ 'hereillä' => 'Nukkumassa.',
+ 'hereillä' => 'Nukkumassa.',
+);
+
+$floodlimit = 600; # notice the same channel only once in N seconds
+%floodi = ();
+
+Irssi::signal_add_last(
+ 'message public' => sub {
+ my ($server, $msg, $nick, $address, $target) = @_;
+
+ # Am i away?
+ return unless $server->{usermode_away};
+
+ # Am i asked about something?
+ my $own_nick = $server->{nick};
+ $own_nick =~ s/\W//g;
+ return
+ unless $msg =~ /^(\Q$server->{nick}\E|\Q$own_nick\E)\s*[,:].+\?/i;
+
+ # Is it me who's talking?
+ return if $nick eq $server->{nick};
+
+ # Are you asking the right question?
+ my $answer;
+ foreach (keys %answers) {
+ $answer = $answers{$_} if $msg =~ /\b\Q$_\E\b/i;
+ }
+ return unless $answer;
+
+ # You aren't flooding, are you?
+ if (defined $floodi{$target}) {
+ if (time - $floodi{$target} < $floodlimit) {
+ return;
+ } else {
+ undef $floodi{$target};
+ }
+ }
+
+ $nick =~ s/\W//g;
+ $nick = lc $nick
+ if Irssi::settings_get_bool('completion_nicks_lowercase');
+ $nick .= Irssi::settings_get_str('completion_char') || ":";
+
+ $floodi{$target} = time;
+ $server->command("msg $target $nick $answer");
+ # Irssi::print("msg $target $nick $answer");
+ }
+);