source: perl/modules/IRC/lib/BarnOwl/Module/IRC/Completion.pm @ 09bd74c

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