File: intro-02-whatsyourname.pl

package info (click to toggle)
libnet-async-irc-perl 0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 200 kB
  • sloc: perl: 970; sh: 2; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl

use v5.14;
use warnings;

use Future::AsyncAwait 0.47; # toplevel await

use IO::Async::Loop;
use Net::Async::IRC;

my $loop = IO::Async::Loop->new;

my $irc = Net::Async::IRC->new;
$loop->add( $irc );

my $SERVER = "irc.example.net";
my $NICK = "MyNick";
my $TARGET = "TargetNick";

await $irc->login(
   host => $SERVER,
   nick => $NICK,
);

my $target_folded = $irc->casefold_name( $TARGET );

$irc->configure(
   on_message_text => sub {
      my ( undef, $message, $hints ) = @_;
      return unless $hints->{prefix_nick_folded} eq $target_folded;

      print "The user said: $hints->{text}\n";
   },
   on_message_ctcp_ACTION => sub {
      my ( undef, $message, $hints ) = @_;
      return unless $hints->{prefix_nick_folded} eq $target_folded;

      print "The user acted: $hints->{ctcp_args}\n";
   },
);

await $irc->do_PRIVMSG(
   target => $TARGET,
   text   => "Hello, what's your name?"
);

$loop->run;