aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: c7636e4a75d45bc68326986aab35b98ccfe27979 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
[![Build Status](https://travis-ci.org/zoffixznet/perl6-IRC-Client.svg)](https://travis-ci.org/zoffixznet/perl6-IRC-Client)

# NAME

IRC::Client - Extendable Internet Relay Chat client

# SYNOPSIS

```perl6
    use IRC::Client;
    use IRC::Client::Plugin::Debugger;

    IRC::Client.new(
        :host('localhost'),
        :debug,
        plugins => [ IRC::Client::Plugin::Debugger.new ]
    ).run;
```

# DESCRIPTION

***Note: this is a preview dev release. Things might change and new things
might get added rapidly. The first stable version is currently planned
to appear by January 3, 2016***

This modules lets you create
[IRC clients](https://en.wikipedia.org/wiki/Internet_Relay_Chat)
in Perl 6. The plugin system lets you work on the behaviour, without worrying
about IRC layer.

# METHODS

## `new`

```perl6
my $irc = IRC::Client.new;
```

```perl6
# Defaults are shown
my $irc = IRC::Client.new(
    debug             => False,
    host              => 'localhost',
    port              => 6667,
    nick              => 'Perl6IRC',
    username          => 'Perl6IRC',
    userhost          => 'localhost',
    userreal          => 'Perl6 IRC Client',
    channels          => ['#perl6bot'],
    plugins           => [],
    plugins-essential => [ IRC::Client::Plugin::PingPong.new ],
);
```

Creates and returns a new `IRC::Client` objects. All arguments are optional
and are as follows:

### `debug`

```perl6
    debug => True,
```
Takes `True` and `False` values. When set to `True`, debugging information
will be printed by the modules on the STDOUT. **Defaults to:** `False`

### `host`

```perl6
    host => 'irc.freenode.net',
```
Specifies the hostname of the IRC server to connect to. **Defaults to:**
`localhost`

### `port`

```perl6
    port => 7000,
```
Specifies the port of the IRC server to connect to. **Defaults to:** `6667`

### `nick`

```perl6
    nick => 'Perl6IRC',
```
Specifies the nick for the client to use. **Defaults to:** `Perl6IRC`

### `username`

```perl6
    username => 'Perl6IRC',
```
Specifies the username for the client to user. **Defaults to:** `Perl6IRC`

### `userhost`

```perl6
    userhost => 'localhost',
```
Specifies the hostname for the client to use when sending messages.
**Defaults to:** `localhost` (Note: it's probably safe to leave this at
default. Currently, this attribute is fluid and might be changed or
removed in the future).

### `userreal`

```perl6
    userreal => 'Perl6 IRC Client',
```
Specifies the "real name" of the client. **Defaults to:** `Perl6 IRC Client`

### `channels`

```perl6
    channels => ['#perl6bot'],
```
Takes an array of channels for the client to join. **Defaults to:**
`['#perl6bot']`

### `plugins`

```perl6
    plugins => [ IRC::Client::Plugin::Debug.new ],
```
Takes an array of IRC::Client Plugin objects. To run while the client is
connected.

### `plugins-essential`

```perl6
    plugins-essential => [ IRC::Client::Plugin::PingPong.new ],
```
Same as `plugins`. The only difference is something will be set to
these by default, as these plugins are assumed to be essential to proper
working order of any IRC client. **Defaults to:**
`[ IRC::Client::Plugin::PingPong.new ]`

## `run`

    $irc.run;

Takes no arguments. Starts the IRC client. Exits when the connection
to the IRC server ends.

# PLUGINS

Currently, this distribution comes with two IRC Client plugins:

## Writing your own

```perl6
    unit class IRC::Client::Plugin::Foo:ver<1.001001>;

    multi method msg () { True }
    multi method msg ($irc, $msg) {
        $irc.privmsg( Zoffix => Dump $msg, :indent(4) );
    }

    multi method interval () {  6  }
    multi method interval ($irc) {
        $irc.privmsg(
            $irc.channels[0], "5 seconds passed. Time is now " ~ now
        );
    }
```

Above is a sample plugin. You can choose to respond either to server
messages or do things at a specific interval.

### Responding to server messages

```perl6
    multi method msg () { True }
    multi method msg ($irc, $msg) {
        $irc.privmsg( Zoffix => Dump $msg, :indent(4) );
    }
```

If your plugin can resond to server messages, declare two multi methods
`msg` as seen above. The one without parameters needs to return `True`
(or `False`, if your plugin does not respond to messages). The second
gets the `IRC::Client` object as the first argument and the parsed message
as the second argument.

### Acting in intervals

```perl6
    multi method interval () {  6  }
    multi method interval ($irc) {
        $irc.privmsg(
            $irc.channels[0], "5 seconds passed. Time is now " ~ now
        );
    }
```
Your plugin can also repsond in intervals. Declare an `interval` multi
that takes no arguments and returns an interval in seconds that your
action should happen in (return `0` if your plugin does not handle intervals).
The other multi method `interval` takes the `IRC::Client` as the argument.

## Methods for plugins

You can make use of these `IRC::Client` methods in your plugins:

### `.ssay`

```perl6
    $irc.ssay("Foo bar!");
```
Sends a message to the server, automatically appending `\r\n`.

### `.privmsg`

```perl6
    $irc.privmsg( Zoffix => "Hallo!" );
```
Sends a `PRIVMSG` message specified in the second argument
to the user/channel specified as the first argument.

## Included Plugins

### `IRC::Client::Plugin::Debugger`

    plugins => [IRC::Client::Plugin::Debugger.new]

Including this plugin will pretty-print parsed IRC messages on STDOUT.

### `IRC::Client::Plugin::PingPong`

    plugins-essential => [IRC::Client::Plugin::PingPong.new]

This plugin responds to server's `PING` requests and is automatically
included in the `plugins-essential` by default.

# REPOSITORY

Fork this module on GitHub:
https://github.com/zoffixznet/perl6-IRC-Client

# BUGS

To report bugs or request features, please use
https://github.com/zoffixznet/perl6-IRC-Client/issues

# AUTHOR

http://zoffix.com/

# LICENSE

You can use and distribute this module under the terms of the
The Artistic License 2.0. See the C<LICENSE> file included in this
distribution for complete details.