aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/01-uppercase-bot.p68
-rw-r--r--examples/02-trickster-bot.p620
-rw-r--r--examples/03-github-notifications.p638
-rw-r--r--examples/04-bash-bot.p626
-rw-r--r--examples/05-bash-bot-with-filter.p632
-rw-r--r--examples/06-multi-server.p623
-rw-r--r--examples/07-multi-server-message-forwarder.p637
-rw-r--r--examples/08-numeric-bot.p632
-rw-r--r--examples/README.md14
9 files changed, 0 insertions, 230 deletions
diff --git a/examples/01-uppercase-bot.p6 b/examples/01-uppercase-bot.p6
deleted file mode 100644
index c432710..0000000
--- a/examples/01-uppercase-bot.p6
+++ /dev/null
@@ -1,8 +0,0 @@
-use lib <lib>;
-use IRC::Client;
-.run with IRC::Client.new:
- :nick<MahBot>
- :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
- :channels<#zofbot>
- :debug
- :plugins(class { method irc-to-me ($_) { .text.uc } })
diff --git a/examples/02-trickster-bot.p6 b/examples/02-trickster-bot.p6
deleted file mode 100644
index 64171a7..0000000
--- a/examples/02-trickster-bot.p6
+++ /dev/null
@@ -1,20 +0,0 @@
-use lib <lib>;
-
-use IRC::Client;
-class Trickster {
- multi method irc-to-me ($ where /time/) { DateTime.now }
- multi method irc-to-me ($ where /temp \s+ $<temp>=\d+ $<unit>=[F|C]/) {
- $<unit> eq 'F' ?? "That's {($<temp> - 32) × .5556}°C"
- !! "That's { $<temp> × 1.8 + 32 }°F"
- }
-}
-
-class BFF { method irc-to-me ($ where /'♥'/) { 'I ♥ YOU!' } }
-
-.run with IRC::Client.new:
- :nick<MahBot>
- :alias('foo', /b.r/)
- :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
- :channels<#zofbot>
- :debug
- :plugins(Trickster, BFF)
diff --git a/examples/03-github-notifications.p6 b/examples/03-github-notifications.p6
deleted file mode 100644
index 58596c6..0000000
--- a/examples/03-github-notifications.p6
+++ /dev/null
@@ -1,38 +0,0 @@
-use lib <lib>;
-
-use IRC::Client;
-use HTTP::Tinyish;
-use JSON::Fast;
-
-class GitHub::Notifications does IRC::Client::Plugin {
- has Str:D $.token = %*ENV<GITHUB_TOKEN>;
- has $!ua = HTTP::Tinyish.new;
- constant $API_URL = 'https://api.github.com/notifications';
-
- method irc-connected ($) {
- start react {
- whenever self!notification.grep(* > 0) -> $num {
- $.irc.send: :where<Zoffix>
- :text("You have $num unread notifications!")
- :notice;
- }
- }
- }
-
- method !notification {
- supply {
- loop {
- my $res = $!ua.get: $API_URL, :headers{ :Authorization("token $!token") };
- $res<success> and emit +grep *.<unread>, |from-json $res<content>;
- sleep $res<headers><X-Poll-Interval> || 60;
- }
- }
- }
-}
-
-.run with IRC::Client.new:
- :nick<MahBot>
- :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
- :channels<#zofbot>
- :debug
- :plugins(GitHub::Notifications.new)
diff --git a/examples/04-bash-bot.p6 b/examples/04-bash-bot.p6
deleted file mode 100644
index 53baf87..0000000
--- a/examples/04-bash-bot.p6
+++ /dev/null
@@ -1,26 +0,0 @@
-use lib <lib>;
-
-use IRC::Client;
-use Mojo::UserAgent:from<Perl5>;
-
-class Bash {
- constant $BASH_URL = 'http://bash.org/?random1';
- constant $cache = Channel.new;
- has $!ua = Mojo::UserAgent.new;
-
- multi method irc-to-me ($ where /bash/) {
- start $cache.poll or do { self!fetch-quotes; $cache.poll };
- }
-
- method !fetch-quotes {
- $cache.send: $_
- for $!ua.get($BASH_URL).res.dom.find('.qt').each».all_text.lines.join: ' ';
- }
-}
-
-.run with IRC::Client.new:
- :nick<MahBot>
- :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
- :channels<#zofbot>
- :debug
- :plugins(Bash.new);
diff --git a/examples/05-bash-bot-with-filter.p6 b/examples/05-bash-bot-with-filter.p6
deleted file mode 100644
index f2aa692..0000000
--- a/examples/05-bash-bot-with-filter.p6
+++ /dev/null
@@ -1,32 +0,0 @@
-use lib <lib>;
-
-use IRC::Client;
-use Pastebin::Shadowcat;
-use Mojo::UserAgent:from<Perl5>;
-
-class Bash {
- constant $BASH_URL = 'http://bash.org/?random1';
- constant $cache = Channel.new;
- has $!ua = Mojo::UserAgent.new;
-
- multi method irc-to-me ($ where /bash/) {
- start $cache.poll or do { self!fetch-quotes; $cache.poll };
- }
-
- method !fetch-quotes {
- $cache.send: $_
- for $!ua.get($BASH_URL).res.dom.find('.qt').each».all_text;
- }
-}
-
-.run with IRC::Client.new:
- :nick<MahBot>
- :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
- :channels<#zofbot>
- :debug
- :plugins(Bash.new)
- :filters(
- -> $text where .lines > 1 || .chars > 300 {
- Pastebin::Shadowcat.new.paste: $text.lines.join: "\n";
- }
- )
diff --git a/examples/06-multi-server.p6 b/examples/06-multi-server.p6
deleted file mode 100644
index 3a5f5fc..0000000
--- a/examples/06-multi-server.p6
+++ /dev/null
@@ -1,23 +0,0 @@
-use lib <lib>;
-
-use IRC::Client;
-
-class BFF {
- method irc-to-me ($ where /'♥'/) { 'I ♥ YOU!' }
-}
-
-.run with IRC::Client.new:
- :debug
- :plugins(BFF)
- :nick<MahBot>
- :channels<#zofbot>
- :servers(
- freenode => %(
- :host<irc.freenode.net>,
- ),
- local => %(
- :nick<P6Bot>,
- :channels<#zofbot #perl6>,
- :host<localhost>,
- )
- )
diff --git a/examples/07-multi-server-message-forwarder.p6 b/examples/07-multi-server-message-forwarder.p6
deleted file mode 100644
index 06d07ec..0000000
--- a/examples/07-multi-server-message-forwarder.p6
+++ /dev/null
@@ -1,37 +0,0 @@
-use lib <lib>;
-
-use IRC::Client;
-
-class Messenger does IRC::Client::Plugin {
- method irc-privmsg-channel ($e) {
- for $.irc.servers.values -> $server {
- for $server.channels -> $channel {
- next if $server eq $e.server and $channel eq $e.channel;
-
- $.irc.send: :$server, :where($channel), :text(
- "$e.nick() over at $e.server.host()/$e.channel() says $e.text()"
- );
- }
- }
-
- $.irc.send: :where<Zoffix>
- :text('I spread the messages!')
- :server<local>;
- }
-}
-
-.run with IRC::Client.new:
- :debug
- :plugins[Messenger.new]
- :nick<MahBot>
- :channels<#zofbot>
- :servers{
- freenode => %(
- :host<irc.freenode.net>,
- ),
- local => %(
- :nick<P6Bot>,
- :channels<#zofbot #perl6>,
- :host<localhost>,
- )
- }
diff --git a/examples/08-numeric-bot.p6 b/examples/08-numeric-bot.p6
deleted file mode 100644
index c8edac9..0000000
--- a/examples/08-numeric-bot.p6
+++ /dev/null
@@ -1,32 +0,0 @@
-use lib <lib>;
-use IRC::Client;
-
-.run with IRC::Client.new:
- :nick<MahBot>
- :host(%*ENV<IRC_CLIENT_HOST> // 'irc.freenode.net')
- :channels<#zofbot>
- :2debug
- :plugins(class :: does IRC::Client::Plugin {
- my class NameLookup { has $.channel; has @.users; has $.e; }
- has %.lookups of NameLookup;
-
- method irc-to-me ($e where /^ 'users in ' $<channel>=\S+/) {
- my $channel = ~$<channel>;
- return 'Look up of this channel is already in progress'
- if %!lookups{$channel};
-
- %!lookups{$channel} = NameLookup.new: :$channel :$e;
- $.irc.send-cmd: 'NAMES', $channel;
- Nil;
- }
- method irc-n353 ($e where so %!lookups{ $e.args[2] }) {
- %!lookups{ $e.args[2] }.users.append: $e.args[3].words;
- Nil;
- }
- method irc-n366 ($e where so %!lookups{ $e.args[1] }) {
- my $lookup = %!lookups{ $e.args[1] }:delete;
- $lookup.e.reply: "Users in $lookup.channel(): $lookup.users()[]";
- Nil;
- }
-
- }.new)
diff --git a/examples/README.md b/examples/README.md
deleted file mode 100644
index 49b9056..0000000
--- a/examples/README.md
+++ /dev/null
@@ -1,14 +0,0 @@
-[[back to doc map]](../docs/README.md)
-
-# Examples
-
-These examples are covered in [the IRC::Client blog
-post](http://perl6.party/post/IRC-Client-Perl-6-Multi-Server-IRC-Module)
-
-* [Uppercasing bot](01-uppercase-bot.p6)
-* [Small bot with a couple of features](02-trickster-bot.p6)
-* [Bot to announce GitHub notifications](03-github-notifications.p6)
-* [Bash.org bot](04-bash-bot.p6)
-* [Bash.org bot with pastebin filter](05-bash-bot-with-filter.p6)
-* [Multi-server bot](06-multi-server.p6)
-* [Multi-server message forwarder bot](07-multi-server-message-forwarder.p6)