1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
use strict;
use vars qw(%topics);
use vars qw($VERSION %IRSSI);
use Irssi qw(signal_add_last signal_add_first settings_add_bool settings_add_str
settings_get_bool settings_get_str signal_stop);
use Irssi::Irc;
$VERSION = '1.00';
%IRSSI = (
authors => 'Tijmen Ruizendaal & Wilmer van der Gaast',
contact => 'timing@fokdat.nl timing@OFTC',
name => 'BitlBee_tab_completion',
description => 'Intelligent Tab-completion for Bitlbee commands (for more info: http://www.bitlbee.org).',
license => 'GPLv2',
url => 'http://fokdat.nl/~tijmen/software/index.html',
changed => '05-18-2004',
);
my $debug = 0; ## change this into 1 if you want to see some output in your control panel, it's not much, so don't be scared.
## Hardcoded defaults, most of these will be auto-guessed when the BitlBee server supports this.
my $root_nick = 'root';
my $bitlbee_channel = '#bitlbee';
my $getting_completions = '0';
my @commands = ('account','allow','block','blist','help','identify','info','nick','qlist','register','remove','rename','save','set');
my @setlist = ('auto_connect','auto_reconnect','auto_reconnect_delay','away_devoice','buddy_sendbuffer','buddy_sendbuffer_delay','charset','debug','handle_unknown','html','ops','private','save_on_quit','typing_notice','to_char');
my @helplist = ('away','commands','groupchats','groupchats2','groupchats3','index','quickstart','quickstart2','quickstart3','quickstart4','quickstart5','smileys');
my @accountlist = ('add','del','list','on','off');
my @blist = ('all','away','offline','online');
my @boolean = ('true', 'false');
my @handle_unknown = ('root', 'add', 'add_private', 'add_channel', 'ignore');
my @ops = ('both', 'root', 'user', 'none');
my @html = ('strip', 'nostrip');
##pfft, done with that...
my $i;
for $i ( @commands )
{
@helplist = ( @helplist, $i );
}
signal_add_last 'channel sync' => sub {
my( $channel ) = @_;
my( $server ) = $channel->{server};
if( $channel->{topic} eq "Welcome to the control channel. Type \x02help\x02 for help information." )
{
$bitlbee_channel = $channel->{name};
$getting_completions = 1;
$server->send_raw( 'COMPLETIONS' );
if($debug == 1){
print( 'Detected a #bitlbee: ' . $channel->{name} );
}
}
};
signal_add_last 'message irc notice' => sub {
my( $server, $msg, $from, $address, $target ) = @_;
## Ignore the notice if we have the completions already.
return unless $getting_completions;
if( $msg =~ s/^COMPLETIONS // )
{
$root_nick = $from;
if( $msg eq 'OK' )
{
## We're sure that the server supports the COMPLETIONS
## command now, so let's flush our hardcoded stuff.
@commands = @setlist = @helplist = ();
if($debug == 1)
{
print( 'COMPLETIONS fetching supported!' );
}
}
elsif( $msg eq 'END' )
{
## Ignore further notices.
$getting_completions = 0;
if($debug == 1)
{
print( 'COMPLETIONS fetching finished!' );
}
}
elsif( $msg =~ s/^help // )
{
@helplist = ( @helplist, $msg );
}
elsif( $msg =~ s/^set // )
{
@setlist = ( @setlist, $msg );
}
else
{
@commands = ( @commands, $msg );
}
signal_stop();
}
};
signal_add_last 'complete word' => sub {
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;
if ($linestart eq ""){
foreach my $command(@commands)
{
if ($command =~ /^$word/i)
{
push @$complist, $command;
}
}
}elsif ($linestart eq "set" or $linestart eq "help set")
{
foreach my $set(@setlist)
{
if ($set =~ /^$word/i)
{
push @$complist, $set;
}
}
}elsif ($linestart eq "help")
{
foreach my $help(@helplist)
{
if ($help =~ /^$word/i)
{
push @$complist, $help;
}
}
}elsif ($linestart eq "blist")
{
foreach my $list(@blist)
{
if ($list =~ /^$word/i)
{
push @$complist, $list;
}
}
}elsif ($linestart eq "account" || $linestart eq "help account")
{
foreach my $account(@accountlist)
{
if ($account =~ /^$word/i)
{
push @$complist, $account;
}
}
}elsif($linestart eq 'set away_devoice' || $linestart eq 'set auto_connect' || $linestart eq 'set auto_reconnect' || $linestart eq 'set buddy_sendbuffer' || $linestart eq 'set debug' || $linestart eq 'set private' || $linestart eq 'set save_on_quit' || $linestart eq 'set typing_notice')
{
foreach my $bool(@boolean)
{
if ($bool =~ /^$word/i)
{
push @$complist, $bool;
}
}
}elsif($linestart eq 'set handle_unknown')
{
foreach my $handle(@handle_unknown)
{
if ($handle =~ /^$word/i)
{
push @$complist, $handle;
}
}
}elsif($linestart eq 'set ops')
{
foreach my $op(@ops)
{
if ($op =~ /^$word/i)
{
push @$complist, $op;
}
}
}elsif($linestart eq 'set html')
{
foreach my $strip(@html)
{
if ($strip =~ /^$word/i)
{
push @$complist, $strip;
}
}
}
}
};
|