-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathirc-framework.js
83 lines (74 loc) · 2.02 KB
/
irc-framework.js
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
/**
* How to use IRC-FRAMEWORK API within xdccJS :
* This file only contains a few examples.
*
* IRC-FRAMEWORK documentation is available at:
* https://github.com/kiwiirc/irc-framework/blob/master/docs/clientapi.md
*/
/**
* xdccJS SETUP
*/
const XDCC = require('xdccjs').default
let opts = {
host: 'irc.server.net',
port: 6660,
nick: 'ItsMeJiPaix',
chan: ['#mychannel'],
path: 'downloads',
retry: 2,
verbose: false,
randomizeNick: false,
passivePort: [5000, 5001, 5002],
}
/**
* Middleware (NickServ authentification)
* modified version of: https://github.com/kiwiirc/irc-framework#middleware
*/
const nicksev = { account: 'JiPaix', password: 'secret' }
function ExampleMiddleware() {
return function(client, raw_events, parsed_events) {
parsed_events.use(theMiddleware);
}
function theMiddleware(command, event, client, next) {
if (command === 'registered') {
client.say('nickserv', 'identify ' + nicksev.account + ' ' + nicksev.password);
}
if (command === 'message' && client.caseCompare(event.event.nick, 'nickserv')) {
// Handle success/retries/failures
}
next();
}
}
/**
* Start xdccJS using a middleware
*/
const xdccJS = new XDCC(opts)
xdccJS.irc.use(ExampleMiddleware)
xdccJS.on('ready', async () => {
/**
* Access IRC-FRAMEWORK methods :
* https://github.com/kiwiirc/irc-framework/blob/master/docs/clientapi.md#methods
*/
xdccJS.irc.join('#channel')
xdccJS.irc.join('#joinPrivateChannel', 'password')
xdccJS.irc.say('SomeOne', 'Hello babe')
xdccJS.irc.say('#someWhere', 'Hey!')
/**
* Access to IRC-FRAMEWORK events
* https://github.com/kiwiirc/irc-framework/blob/master/docs/events.md
*/
xdccJS.irc
.on('privmsg', info => {
if(info.target.indexOf('#') === -1) {
// Private message
} else {
//=> Channel message
}
})
.on('topic', info => {
console.log(info.topic) //=> Display the new topic
})
.on('kick', info => {
console.log(info.nick, 'kicked', info.kicked, 'from', info.channel)
})
})