[ab9cd8f] | 1 | use strict; |
---|
| 2 | use warnings; |
---|
| 3 | |
---|
| 4 | package BarnOwl::Module::IRC::Completion; |
---|
| 5 | |
---|
| 6 | use BarnOwl::Completion::Util qw(complete_flags); |
---|
| 7 | |
---|
[27a1903] | 8 | our %users = (); |
---|
| 9 | our %servers = (); |
---|
[ab9cd8f] | 10 | |
---|
[27a1903] | 11 | sub complete_networks { keys %BarnOwl::Module::IRC::ircnets } |
---|
| 12 | sub complete_dests { keys %users, complete_channels() } |
---|
| 13 | sub complete_channels { keys %BarnOwl::Module::IRC::channels } |
---|
| 14 | sub complete_nicks { keys %users } |
---|
[ab9cd8f] | 15 | sub complete_servers { keys %servers } |
---|
| 16 | |
---|
| 17 | sub 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 | |
---|
| 30 | sub complete_irc_network { |
---|
| 31 | my $ctx = shift; |
---|
| 32 | return complete_flags($ctx, |
---|
| 33 | [], |
---|
| 34 | { |
---|
| 35 | "-a" => \&complete_networks, |
---|
| 36 | }, |
---|
| 37 | ); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | sub 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 | |
---|
| 51 | sub 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 | |
---|
| 62 | sub 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 | |
---|
| 73 | sub on_message { |
---|
| 74 | my $m = shift; |
---|
| 75 | return unless $m->type eq 'IRC'; |
---|
[955a36e] | 76 | if ($m->recipient && $m->recipient !~ m{^#}) { |
---|
[27a1903] | 77 | $users{$m->recipient} = 1; |
---|
| 78 | } |
---|
[955a36e] | 79 | if ($m->sender && $m->sender !~ m{^#}) { |
---|
[27a1903] | 80 | $users{$m->sender} = 1; |
---|
| 81 | } |
---|
[ab9cd8f] | 82 | $servers{$m->server} = 1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | BarnOwl::Completion::register_completer('irc-connect' => \&complete_irc_connect); |
---|
| 86 | BarnOwl::Completion::register_completer('irc-disconnect' => \&complete_irc_network); |
---|
| 87 | BarnOwl::Completion::register_completer('irc-msg' => \&complete_irc_dest); |
---|
| 88 | BarnOwl::Completion::register_completer('irc-mode' => \&complete_irc_dest); |
---|
| 89 | BarnOwl::Completion::register_completer('irc-join' => \&complete_irc_channel); |
---|
| 90 | BarnOwl::Completion::register_completer('irc-part' => \&complete_irc_channel); |
---|
| 91 | BarnOwl::Completion::register_completer('irc-names' => \&complete_irc_channel); |
---|
| 92 | BarnOwl::Completion::register_completer('irc-whois' => \&complete_irc_nick); |
---|
| 93 | BarnOwl::Completion::register_completer('irc-motd' => \&complete_irc_network); |
---|
| 94 | BarnOwl::Completion::register_completer('irc-topic' => \&complete_irc_channel); |
---|
| 95 | BarnOwl::Completion::register_completer('irc-quote' => \&complete_irc_network); |
---|
| 96 | |
---|
| 97 | $BarnOwl::Hooks::newMessage->add("BarnOwl::Module::IRC::Completion::on_message"); |
---|
| 98 | |
---|
| 99 | 1; |
---|