Skip to content

Commit 419d80a

Browse files
committed
chore: add Makefile, README and LICENSE
1 parent c6e4da4 commit 419d80a

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Jerome Ludmann
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:
2+
@deno test --failfast --allow-net core plugins

README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# deno-irc
2+
3+
IRC client protocol module for [Deno](https://deno.land/).
4+
5+
## Overview
6+
7+
IRC is not dead yet.
8+
9+
This module aims to provide to Deno community an easy way to communicate with
10+
IRC through an abstraction built on top of the client protocol.
11+
12+
Semantic Versioning will be used but breaking changes are expected on minor versions prior to `1.0.0`.
13+
14+
Any feedback and contributions are welcome.
15+
16+
## Contents
17+
18+
- [Usage](#usage)
19+
- API
20+
- [Contributing](#contributing)
21+
- [License](#license)
22+
23+
## Usage
24+
25+
Code is better than words:
26+
27+
```ts
28+
import { Client } from "https://deno.land/x/irc/mod.ts";
29+
30+
const client = new Client({ nick: "my_nick" });
31+
client.connect("irc.freenode.net", 6667);
32+
client.on("register", () => client.join("#my_chan"));
33+
```
34+
35+
Note that this code above requires the `--allow-net` option.
36+
37+
It is also better to have at least one `"error"` event listener to avoid the client from crashing:
38+
39+
```ts
40+
client.on("error", (error) => console.error(error));
41+
```
42+
43+
There are only two main concepts to know to use this module: [events](#events) and [commands](#commands).
44+
45+
### Events
46+
47+
Events are simple messages which are emitted from the client instance.
48+
49+
They can be received by listening to their event names:
50+
51+
```ts
52+
client.on("join" (msg) => {
53+
console.log(`${msg.origin.nick} joins ${msg.channel}`);
54+
});
55+
56+
client.on("nick" (msg) => {
57+
console.log(`${msg.origin.nick} is now known as ${msg.nick}`);
58+
});
59+
60+
client.on("msg:channel", (msg) => {
61+
console.log(`${msg.origin.nick} talks to ${msg.channel}: ${msg.text}`);
62+
});
63+
64+
client.on("msg:private", (msg) => {
65+
console.log(`${msg.origin.nick} talks to you: ${msg.text}`);
66+
});
67+
```
68+
69+
Thanks to TypeScript, type of `msg` is always inferred from the event name so you do not have to worry about what is in the object or about the pecificities of the protocol.
70+
71+
### Commands
72+
73+
Commands are the way to send messages to the server.
74+
75+
They can be sent by calling them:
76+
77+
```ts
78+
client.join("#channel");
79+
80+
client.msg("#channel", "Hello world!");
81+
82+
client.nick("new_nick");
83+
84+
client.topic("#channel", "New topic of the channel");
85+
86+
client.quit("Goodbye!");
87+
```
88+
89+
### Uncaught errors
90+
91+
When an error is thrown, it causes a crash.
92+
93+
By listening to `"error"` events, errors will no longer be thrown and you will be
94+
able to handle them properly:
95+
96+
```ts
97+
client.on("error", (error) => {
98+
// deal with the error message
99+
100+
switch (error.name) {
101+
case "ConnectError":
102+
case "SendError":
103+
console.log(`${error.name}: ${error.message}`);
104+
break;
105+
default:
106+
console.error(error);
107+
}
108+
});
109+
```
110+
111+
This behavior is heavily inspired by the Node.js event emitter pattern.
112+
113+
## Contributing
114+
115+
_This is a first draft of a contributing section._
116+
117+
This module is built around two patterns: event driven architecture and plugins.
118+
119+
It involves keeping the core as minimal as possible and delegates implementation of features to small independent parts (which are called plugins).
120+
121+
The core contains some internal parts related to main parsers, sockets and event emitter. The plugins contain all the extra features built on top of the core client.
122+
123+
In most of the cases, it is quite handy to add new features using plugins without touching the core.
124+
125+
## License
126+
127+
MIT

0 commit comments

Comments
 (0)