From 13d05886dbc6f10a513c67dc29e0221bff1150e4 Mon Sep 17 00:00:00 2001 From: fimojoha Date: Wed, 29 Apr 2015 11:11:15 +0200 Subject: Script to suggest slack-mention versions of nicks when completing --- scripts/slack_complete.pl | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 scripts/slack_complete.pl (limited to 'scripts/slack_complete.pl') 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 +# + +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 ]========================================================= -- cgit v1.2.3