summaryrefslogtreecommitdiffstats
path: root/scripts/bitlbee_tab_completion.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/bitlbee_tab_completion.pl
parentInitial commit. (diff)
downloadirssi-scripts-upstream.tar.xz
irssi-scripts-upstream.zip
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/bitlbee_tab_completion.pl')
-rw-r--r--scripts/bitlbee_tab_completion.pl88
1 files changed, 88 insertions, 0 deletions
diff --git a/scripts/bitlbee_tab_completion.pl b/scripts/bitlbee_tab_completion.pl
new file mode 100644
index 0000000..8d19128
--- /dev/null
+++ b/scripts/bitlbee_tab_completion.pl
@@ -0,0 +1,88 @@
+use strict;
+use vars qw($VERSION %IRSSI);
+
+$VERSION = '1.3';
+
+%IRSSI = (
+ authors => 'Tijmen "timing" Ruizendaal & Wilmer van der Gaast',
+ contact => 'tijmen.ruizendaal@gmail.com',
+ name => 'BitlBee_tab_completion',
+ description => 'Intelligent Tab-completion for BitlBee commands.',
+ license => 'GPLv2',
+ url => 'http://the-timing.nl/stuff/irssi-bitlbee',
+ changed => '2009-08-11',
+);
+
+my $root_nick = 'root';
+my $bitlbee_channel = '&bitlbee';
+my $bitlbee_server_tag = 'localhost';
+my $get_completions = 0;
+
+my @commands;
+
+Irssi::signal_add_last 'channel sync' => sub {
+ my( $channel ) = @_;
+ if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." ){
+ $bitlbee_server_tag = $channel->{server}->{tag};
+ $bitlbee_channel = $channel->{name};
+ request_completions();
+ }
+};
+
+if (get_channel()) {
+ request_completions();
+}
+
+sub request_completions {
+ $get_completions = 1;
+ Irssi::server_find_tag($bitlbee_server_tag)->send_raw( 'COMPLETIONS' );
+}
+
+sub get_channel {
+ my @channels = Irssi::channels();
+ foreach my $channel(@channels) {
+ if ($channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information.") {
+ $bitlbee_channel = $channel->{name};
+ $bitlbee_server_tag = $channel->{server}->{tag};
+ return 1;
+ }
+ }
+ return 0;
+}
+
+sub irc_notice {
+ return unless $get_completions;
+ my( $server, $msg, $from, $address, $target ) = @_;
+
+ if( $msg =~ s/^COMPLETIONS // ) {
+ $root_nick = $from;
+ if( $msg eq 'OK' ) {
+ @commands = ();
+ }
+ elsif( $msg eq 'END' ) {
+ $get_completions = 0;
+ }
+ @commands = ( @commands, $msg );
+
+ Irssi::signal_stop();
+ }
+}
+
+sub complete_word {
+ my ($complist, $window, $word, $linestart, $want_space) = @_;
+ my $channel = $window->get_active_name();
+ if ($channel eq $bitlbee_channel or $channel eq $root_nick or $linestart =~ /^\/(msg|query) \Q$root_nick\E */i){
+ $linestart =~ s/^\/(msg|query) \Q$root_nick\E *//i;
+ $linestart =~ s/^\Q$root_nick\E[:,] *//i;
+ foreach my $command(@commands) {
+ if ($command =~ /^$word/i) {
+ push @$complist, $command;
+ }
+ }
+ }
+}
+
+
+Irssi::signal_add_last('complete word', 'complete_word');
+Irssi::signal_add_first('message irc notice', 'irc_notice');
+