summaryrefslogtreecommitdiffstats
path: root/scripts/slack_complete.pl
diff options
context:
space:
mode:
authorfimojoha2015-04-29 11:11:15 +0200
committerfimojoha2015-04-29 11:11:15 +0200
commit13d05886dbc6f10a513c67dc29e0221bff1150e4 (patch)
treeeff2b02c51bb6a0c4af04f3410c146b2712a016c /scripts/slack_complete.pl
parent0a0ba125acd8e929dfcd4809f900ce251b5ddc50 (diff)
downloadscripts.irssi.org-13d05886dbc6f10a513c67dc29e0221bff1150e4.tar.bz2
Script to suggest slack-mention versions of nicks when completing
Diffstat (limited to 'scripts/slack_complete.pl')
-rw-r--r--scripts/slack_complete.pl62
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/slack_complete.pl b/scripts/slack_complete.pl
new file mode 100644
index 0000000..c4b0443
--- /dev/null
+++ b/scripts/slack_complete.pl
@@ -0,0 +1,62 @@
+#
+# Copyright (C) 2015 by Morten Lied Johansen <mortenjo@ifi.uio.no>
+#
+
+use strict;
+
+use Irssi;
+use Irssi::Irc;
+
+# ======[ Script Header ]===============================================
+
+use vars qw{$VERSION %IRSSI};
+($VERSION) = '$Revision: 1.0 $' =~ / (\d+\.\d+) /;
+%IRSSI = (
+ name => 'slack_complete',
+ authors => 'Morten Lied Johansen',
+ contact => 'mortenjo@ifi.uio.no',
+ license => 'GPL',
+ description => 'Convert to slack-mention when completing nicks',
+ );
+
+# ======[ Hooks ]=======================================================
+
+# --------[ sig_complete_slack_nick ]-----------------------------------
+
+sub sig_complete_slack_nick {
+my ($complist, $window, $word, $linestart, $want_space) = @_;
+
+ my $wi = Irssi::active_win()->{active};
+ return unless ref $wi and $wi->{type} eq 'CHANNEL';
+ return unless $wi->{server}->{chatnet} eq
+ Irssi::settings_get_str('slack_network');
+
+ if ($word =~ /^@/) {
+ $word =~ s/^@//;
+ }
+ foreach my $nick ($wi->nicks()) {
+ if ($nick->{nick} =~ /^\Q$word\E/i) {
+ if ($linestart) {
+ push(@$complist, "\@$nick->{nick}");
+ } else {
+ push(@$complist, "\@$nick->{nick}:");
+ }
+ }
+ }
+
+ @$complist = sort {
+ return $a =~ /^\@\Q$word\E(.*)$/i ? 0 : 1;
+ } @$complist;
+}
+
+# ======[ Setup ]=======================================================
+
+# --------[ Register settings ]-----------------------------------------
+
+Irssi::settings_add_str('slack_complete', 'slack_network', 'Slack');
+
+# --------[ Register signals ]------------------------------------------
+
+Irssi::signal_add('complete word', \&sig_complete_slack_nick);
+
+# ======[ END ]=========================================================