summaryrefslogtreecommitdiff
path: root/boha.raku
blob: 40ceb6b3fb37475b206aa936d0ae5b0fa8edde51 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env rakudo 
use v6.d;
use Config::TOML;
use lib $?FILE.IO.sibling('lib').Str;
use lib $?FILE.IO.parent(2).child('Red/lib').Str;
use Boha::TrackOps;
use Boha::Karma;
use IRC::Client;
use Red:api<2>;
 
my $config = from-toml(
    file => (%*ENV<BOHA_CONFIG_FILE> // $?FILE.IO.sibling('boha.toml').Str)
);
 
my $*RED-DEBUG=True;
 
red-defaults :boha['SQLite':default];
 
# if-not-exists? 
schema(Boha::KarmaEvent).create;
 
Boha::KarmaEvent.new-karma('dakkar',$_for (1,-1,1,1);
Boha::KarmaEvent.new-karma('boha',$_for (-1,-1,-1,-1);
 
say Boha::KarmaEvent.current-karma();
 
 
=finish
 
class Boha1 does IRC::Client::Plugin {
    has Boha::TrackOps $.ops handles <is-op>;
 
    # irc-addressed for in-channel messages
    # irc-privmsg-me for direct messages
 
    method irc-addressed($e) {
        my @words = $e.text.split(/\s+/);
 
        if @words[0] eq 'op' {
            my $nick = @words[1];
            if self.is-op($e.server,$e.channel,$nick) {
                return "$nick is op";
            }
            else {
                return "$nick is a normal user";
            }
        }
        else {
            return "I don't know understand '$e.text'";
        }
    }
}
 
my Boha::TrackOps $ops .= new;
my Boha1 $boha .= new(:$ops);
 
.run with IRC::Client.new(
    |($config<server>),
    channels => $config<channels>.map(*.<name>),
    :debug,
    :plugins(
        $ops,
        $boha,
    ),
);