source: perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm @ 216b1d0

release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 216b1d0 was 216b1d0, checked in by Nelson Elhage <nelhage@mit.edu>, 12 years ago
IRC Completion: Complete based on observed senders, too.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1use strict;
2use warnings;
3
4package BarnOwl::Module::IRC::Completion;
5
6use BarnOwl::Completion::Util qw(complete_flags);
7
8my %networks = ();
9my %dests = ();
10my %servers = ();
11
12sub complete_networks { keys %networks }
13sub complete_dests    { keys %dests }
14sub complete_channels { grep /^#/, keys %dests }
15sub complete_nicks    { grep /^[^#]/, keys %dests }
16sub complete_servers  { keys %servers }
17
18sub complete_irc_connect {
19    my $ctx = shift;
20    return complete_flags($ctx,
21        [qw(-s)],
22        {
23            "-a" => \&complete_networks,
24            "-p" => sub {},
25            "-n" => sub {},
26        },
27        \&complete_servers
28       );
29}
30
31sub complete_irc_network {
32    my $ctx = shift;
33    return complete_flags($ctx,
34        [],
35        {
36            "-a" => \&complete_networks,
37        },
38       );
39}
40
41sub complete_irc_dest {
42    my $ctx = shift;
43    return complete_flags($ctx,
44        [],
45        {
46            "-a" => \&complete_networks,
47        },
48        \&complete_dests
49       );
50}
51
52sub complete_irc_channel {
53    my $ctx = shift;
54    return complete_flags($ctx,
55        [],
56        {
57            "-a" => \&complete_networks,
58        },
59        \&complete_channels
60       );
61}
62
63sub complete_irc_nick {
64    my $ctx = shift;
65    return complete_flags($ctx,
66        [],
67        {
68            "-a" => \&complete_networks,
69        },
70        \&complete_nicks
71       );
72}
73
74sub on_message {
75    my $m = shift;
76    return unless $m->type eq 'IRC';
77    $networks{$m->network} = 1;
78    $dests{$m->recipient} = 1;
79    $dests{$m->sender} = 1;
80    $servers{$m->server} = 1;
81}
82
83BarnOwl::Completion::register_completer('irc-connect'    => \&complete_irc_connect);
84BarnOwl::Completion::register_completer('irc-disconnect' => \&complete_irc_network);
85BarnOwl::Completion::register_completer('irc-msg'        => \&complete_irc_dest);
86BarnOwl::Completion::register_completer('irc-mode'       => \&complete_irc_dest);
87BarnOwl::Completion::register_completer('irc-join'       => \&complete_irc_channel);
88BarnOwl::Completion::register_completer('irc-part'       => \&complete_irc_channel);
89BarnOwl::Completion::register_completer('irc-names'      => \&complete_irc_channel);
90BarnOwl::Completion::register_completer('irc-whois'      => \&complete_irc_nick);
91BarnOwl::Completion::register_completer('irc-motd'       => \&complete_irc_network);
92BarnOwl::Completion::register_completer('irc-topic'      => \&complete_irc_channel);
93BarnOwl::Completion::register_completer('irc-quote'      => \&complete_irc_network);
94
95$BarnOwl::Hooks::newMessage->add("BarnOwl::Module::IRC::Completion::on_message");
96
971;
Note: See TracBrowser for help on using the repository browser.