1POE::Component::IRC::CoUoskebrooCko:n:tRreisboultvePedOrE(P:3e:)rClomDpoocnuemnetn:t:aItRiCo:n:Cookbook::Resolver(3)
2
3
4

NAME

6       POE::Component::IRC::Cookbook::Resolver - A bot that can resolve DNS
7       records
8

SYNOPSIS

10       This bot uses POE::Component::Client::DNS to DNS records for channel
11       members.
12

DESCRIPTION

14        #!/usr/bin/env perl
15
16        use strict;
17        use warnings;
18        use IRC::Utils qw(parse_user);
19        use POE;
20        use POE::Component::Client::DNS;
21        use POE::Component::IRC::State;
22        use POE::Component::IRC::Plugin::AutoJoin;
23        use POE::Component::IRC::Plugin::BotCommand;
24
25        POE::Session->create(
26            package_states => [
27                main => [ qw(_start irc_botcmd_resolve dns_response) ]
28            ],
29        );
30
31        $poe_kernel->run();
32
33        sub _start {
34            my $heap = $_[HEAP];
35            my $irc = POE::Component::IRC::State->spawn(
36                Nick   => 'resolver_bot',
37                Server => 'irc.freenode.net',
38            );
39            $heap->{irc} = $irc;
40
41            $irc->plugin_add('AutoJoin', POE::Component::IRC::Plugin::AutoJoin->new(
42                Channels => [ '#test_channel1', '#test_channel2' ]
43            ));
44
45            $irc->plugin_add('BotCommand', POE::Component::IRC::Plugin::BotCommand->new(
46                Commands => {
47                   resolve => 'Usage: resolve <host>'
48                }
49            ));
50
51            $heap->{dns} = POE::Component::Client::DNS->spawn();
52
53            $irc->yield(register => 'botcmd_resolve');
54            $irc->yield('connect');
55            return;
56        }
57
58        sub irc_botcmd_resolve {
59            my $dns = $_[HEAP]->{dns};
60            my $nick = parse_user( $_[ARG0] );
61            my ($channel, $host) = @_[ARG1, ARG2];
62
63            my $res = $dns->resolve(
64                event => 'dns_response',
65                host => $host,
66                context => {
67                    channel => $channel,
68                    nick    => $nick,
69                },
70            );
71
72            $poe_kernel->yield(dns_response => $res) if $res;
73            return;
74        }
75
76        sub dns_response {
77            my $irc = $_[HEAP]->{irc};
78            my $res = $_[ARG0];
79            my @answers = $res->{response}
80                ? map { $_->rdatastr } $res->{response}->answer()
81                : ();
82
83            $irc->yield(
84                'privmsg',
85                $res->{context}->{channel},
86                $res->{context}->{nick} . (@answers
87                    ? ": @answers"
88                    : ': no answers for "' . $res->{host} . '"')
89            );
90
91            return;
92        }
93

AUTHOR

95       Hinrik Örn Sigurðsson, hinrik.sig@gmail.com
96
97
98
99perl v5.30.1                      202P0O-E0:1:-C3o0mponent::IRC::Cookbook::Resolver(3)
Impressum