about summary refs log tree commit diff stats
path: root/js/blotbotboot/node_modules/irc/README.md
blob: 69cfc87cfb915047a5ae42dc2742945066d3afe9 (plain) (blame)
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
[![Travis](https://img.shields.io/travis/martynsmith/node-irc.svg?style=flat)](https://travis-ci.org/martynsmith/node-irc)
[![npm](https://img.shields.io/npm/v/irc.svg?style=flat)](https://www.npmjs.com/package/irc)
[![Dependency Status](https://img.shields.io/david/martynsmith/node-irc.svg?style=flat)](https://david-dm.org/martynsmith/node-irc#info=Dependencies)
[![devDependency Status](https://img.shields.io/david/dev/martynsmith/node-irc.svg?style=flat)](https://david-dm.org/martynsmith/node-irc#info=devDependencies)
[![License](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](http://opensource.org/licenses/GPL-3.0)
[![Join the chat at https://gitter.im/martynsmith/node-irc](https://badges.gitter.im/martynsmith/node-irc.svg)](https://gitter.im/martynsmith/node-irc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


[node-irc](http://node-irc.readthedocs.org/) is an IRC client library written in [JavaScript](http://en.wikipedia.org/wiki/JavaScript) for [Node](http://nodejs.org/).

You can access more detailed documentation for this module at [Read the Docs](http://readthedocs.org/docs/node-irc/en/latest/)


## Installation

The easiest way to get it is via [npm](http://github.com/isaacs/npm):

```
npm install irc
```

If you want to run the latest version (i.e. later than the version available via
[npm](http://github.com/isaacs/npm)) you can clone this repo, then use [npm](http://github.com/isaacs/npm) to link-install it:

```
    npm link /path/to/your/clone
```

Of course, you can just clone this, and manually point at the library itself,
but we really recommend using [npm](http://github.com/isaacs/npm)!

Note that as of version 0.3.8, node-irc supports character set detection using
[icu](http://site.icu-project.org/). You'll need to install libiconv (if
necessary; Linux systems tend to ship this in their glibc) and libicu (and its
headers, if necessary, [install instructions](https://github.com/mooz/node-icu-charset-detector#installing-icu)) in order to use this feature. If you do not have these
libraries or their headers installed, you will receive errors when trying to
build these dependencies. However, node-irc will still install (assuming
nothing else failed) and you'll be able to use it, just not the character
set features.

## Basic Usage

This library provides basic IRC client functionality. In the simplest case you
can connect to an IRC server like so:

```js
var irc = require('irc');
var client = new irc.Client('irc.yourserver.com', 'myNick', {
    channels: ['#channel'],
});
```

Of course it's not much use once it's connected if that's all you have!

The client emits a large number of events that correlate to things you'd
normally see in your favorite IRC client. Most likely the first one you'll want
to use is:

```js
client.addListener('message', function (from, to, message) {
    console.log(from + ' => ' + to + ': ' + message);
});
```

or if you're only interested in messages to the bot itself:

```js
client.addListener('pm', function (from, message) {
    console.log(from + ' => ME: ' + message);
});
```

or to a particular channel:

```js
client.addListener('message#yourchannel', function (from, message) {
    console.log(from + ' => #yourchannel: ' + message);
});
```

At the moment there are functions for joining:

```js
client.join('#yourchannel yourpass');
```

parting:

```js
client.part('#yourchannel');
```

talking:

```js
client.say('#yourchannel', "I'm a bot!");
client.say('nonbeliever', "SRSLY, I AM!");
```

and many others. Check out the API documentation for a complete reference.

For any commands that there aren't methods for you can use the send() method
which sends raw messages to the server:

```js
client.send('MODE', '#yourchannel', '+o', 'yournick');
```

## Help! - it keeps crashing!

When the client receives errors from the IRC network, it emits an "error"
event. As stated in the [Node JS EventEmitter documentation](http://nodejs.org/api/events.html#events_class_events_eventemitter) if you don't bind
something to this error, it will cause a fatal stack trace.

The upshot of this is basically that if you bind an error handler to your
client, errors will be sent there instead of crashing your program.:

```js
client.addListener('error', function(message) {
    console.log('error: ', message);
});
```


## Further Support

Further documentation (including a complete API reference) is available in
reStructuredText format in the docs/ folder of this project, or online at [Read the Docs](http://readthedocs.org/docs/node-irc/en/latest/).

If you find any issues with the documentation (or the module) please send a pull
request or file an issue and we'll do our best to accommodate.

You can also visit us on ##node-irc on freenode to discuss issues you're having
with the library, pull requests, or anything else related to node-irc.
nsi foreground and background colors fg = n - 30 elif n == 39: fg = -1 elif n >= 40 and n <= 47: bg = n - 40 elif n == 49: bg = -1 # 8 aixterm high intensity colors (light but not bold) elif n >= 90 and n <= 97: fg = n - 90 + 8 elif n == 99: fg = -1 elif n >= 100 and n <= 107: bg = n - 100 + 8 elif n == 109: bg = -1 yield (fg, bg, attr) else: yield chunk def char_len(ansi_text): """Count the number of visible characters. >>> char_len("\x1b[0;30;40mX\x1b[0m") 1 >>> char_len("\x1b[0;30;40mXY\x1b[0m") 2 >>> char_len("\x1b[0;30;40mX\x1b[0mY") 2 >>> char_len("hello") 5 >>> char_len("") 0 """ return len(WideString(ansi_re.sub('', ansi_text))) def char_slice(ansi_text, start, length): """Slices a string with respect to ansi code sequences Acts as if the ansi codes aren't there, slices the text from the given start point to the given length and adds the codes back in. >>> test_string = "abcde\x1b[30mfoo\x1b[31mbar\x1b[0mnormal" >>> split_ansi_from_text(test_string) ['abcde', '\\x1b[30m', 'foo', '\\x1b[31m', 'bar', '\\x1b[0m', 'normal'] >>> char_slice(test_string, 1, 3) 'bcd' >>> char_slice(test_string, 5, 6) '\\x1b[30mfoo\\x1b[31mbar' >>> char_slice(test_string, 0, 8) 'abcde\\x1b[30mfoo' >>> char_slice(test_string, 4, 4) 'e\\x1b[30mfoo' >>> char_slice(test_string, 11, 100) '\\x1b[0mnormal' >>> char_slice(test_string, 9, 100) '\\x1b[31mar\\x1b[0mnormal' >>> char_slice(test_string, 9, 4) '\\x1b[31mar\\x1b[0mno' """ chunks = [] last_color = "" pos = old_pos = 0 for i, chunk in enumerate(split_ansi_from_text(ansi_text)): if i % 2 == 1: last_color = chunk continue chunk = WideString(chunk) old_pos = pos pos += len(chunk) if pos <= start: pass # seek elif old_pos < start and pos >= start: chunks.append(last_color) chunks.append(str(chunk[start - old_pos:start - old_pos + length])) elif pos > length + start: chunks.append(last_color) chunks.append(str(chunk[:start - old_pos + length])) else: chunks.append(last_color) chunks.append(str(chunk)) if pos - start >= length: break return ''.join(chunks) if __name__ == '__main__': import doctest doctest.testmod()