[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() } |
---|
[dace02a] | 13 | sub complete_channels { |
---|
| 14 | my %channels; |
---|
| 15 | for my $conn (values %BarnOwl::Module::IRC::ircnets) { |
---|
| 16 | for my $chan (keys %{$conn->conn->{channel_list}}) { |
---|
| 17 | $channels{$chan} = 1; |
---|
| 18 | } |
---|
| 19 | } |
---|
| 20 | return keys %channels; |
---|
| 21 | } |
---|
[27a1903] | 22 | sub complete_nicks { keys %users } |
---|
[ab9cd8f] | 23 | sub complete_servers { keys %servers } |
---|
| 24 | |
---|
| 25 | sub complete_irc_connect { |
---|
| 26 | my $ctx = shift; |
---|
| 27 | return complete_flags($ctx, |
---|
| 28 | [qw(-s)], |
---|
| 29 | { |
---|
| 30 | "-a" => \&complete_networks, |
---|
| 31 | "-p" => sub {}, |
---|
| 32 | "-n" => sub {}, |
---|
| 33 | }, |
---|
| 34 | \&complete_servers |
---|
| 35 | ); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | sub complete_irc_network { |
---|
| 39 | my $ctx = shift; |
---|
| 40 | return complete_flags($ctx, |
---|
| 41 | [], |
---|
| 42 | { |
---|
| 43 | "-a" => \&complete_networks, |
---|
| 44 | }, |
---|
| 45 | ); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | sub complete_irc_dest { |
---|
| 49 | my $ctx = shift; |
---|
| 50 | return complete_flags($ctx, |
---|
| 51 | [], |
---|
| 52 | { |
---|
| 53 | "-a" => \&complete_networks, |
---|
| 54 | }, |
---|
| 55 | \&complete_dests |
---|
| 56 | ); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | sub complete_irc_channel { |
---|
| 60 | my $ctx = shift; |
---|
| 61 | return complete_flags($ctx, |
---|
| 62 | [], |
---|
| 63 | { |
---|
| 64 | "-a" => \&complete_networks, |
---|
| 65 | }, |
---|
| 66 | \&complete_channels |
---|
| 67 | ); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | sub complete_irc_nick { |
---|
| 71 | my $ctx = shift; |
---|
| 72 | return complete_flags($ctx, |
---|
| 73 | [], |
---|
| 74 | { |
---|
| 75 | "-a" => \&complete_networks, |
---|
| 76 | }, |
---|
| 77 | \&complete_nicks |
---|
| 78 | ); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | sub on_message { |
---|
| 82 | my $m = shift; |
---|
| 83 | return unless $m->type eq 'IRC'; |
---|
[955a36e] | 84 | if ($m->recipient && $m->recipient !~ m{^#}) { |
---|
[27a1903] | 85 | $users{$m->recipient} = 1; |
---|
| 86 | } |
---|
[955a36e] | 87 | if ($m->sender && $m->sender !~ m{^#}) { |
---|
[27a1903] | 88 | $users{$m->sender} = 1; |
---|
| 89 | } |
---|
[ab9cd8f] | 90 | $servers{$m->server} = 1; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | BarnOwl::Completion::register_completer('irc-connect' => \&complete_irc_connect); |
---|
| 94 | BarnOwl::Completion::register_completer('irc-disconnect' => \&complete_irc_network); |
---|
| 95 | BarnOwl::Completion::register_completer('irc-msg' => \&complete_irc_dest); |
---|
| 96 | BarnOwl::Completion::register_completer('irc-mode' => \&complete_irc_dest); |
---|
| 97 | BarnOwl::Completion::register_completer('irc-join' => \&complete_irc_channel); |
---|
| 98 | BarnOwl::Completion::register_completer('irc-part' => \&complete_irc_channel); |
---|
| 99 | BarnOwl::Completion::register_completer('irc-names' => \&complete_irc_channel); |
---|
| 100 | BarnOwl::Completion::register_completer('irc-whois' => \&complete_irc_nick); |
---|
| 101 | BarnOwl::Completion::register_completer('irc-motd' => \&complete_irc_network); |
---|
| 102 | BarnOwl::Completion::register_completer('irc-topic' => \&complete_irc_channel); |
---|
| 103 | BarnOwl::Completion::register_completer('irc-quote' => \&complete_irc_network); |
---|
| 104 | |
---|
| 105 | $BarnOwl::Hooks::newMessage->add("BarnOwl::Module::IRC::Completion::on_message"); |
---|
| 106 | |
---|
| 107 | 1; |
---|