-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
278 lines (239 loc) · 6.27 KB
/
example.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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
const nova = require('./irc-nova');
// Create the instance
const bot = new nova();
const channel = "#novatesting";
// ##############################################
// Credentials and Authentication
// ##############################################
// Set bot credentials (nickname and username)
// @Nick
// @Realname
// @password (optional, null by default)
bot.setCredentials('NovaIRC', 'Nova IRC Bot');
// Connect to the chat
bot.connect({
server: 'irc.libera.chat',
port: 6697,
ssl: true,
messageColor: "white", // Choose an allowed color from the IRC table
removeColors: true,
rejectUnauthorized: false, // Optional, default is false
rejoinLimit: 3,
rejoinDelay: 5000, // ms
maxLineLength: 350
});
// ##############################################
// Event Listeners
// ##############################################
// Triggered when the bot connects
bot.on('connected', () => {
// Join the channel.
bot.joinChannel(channel);
});
// Receive a RAW message
// @data
bot.on('raw', (data) => {
// console.log(data);
});
// Receive a disconnect event
bot.on('disconnected', () => {
console.log('Bot disconnected from the server.');
});
// Receive an error
// @err.message
// @raw - Returns raw parsed message
bot.on('error', (err, raw) => {
console.error('Error:', raw);
});
// Receive a ping (automatically responds with a pong)
// @data.server
bot.on('ping', (data) => {
console.log(`PING received from ${data.server}`);
});
// Triggered whenever a message is received.
// @data.sender
// @data.target
// @data.content
// @data.raw
bot.on('message', (data) => {
// console.log(`Message received in ${data.target}: ${data.content}`);
});
// Triggered when a private message is received
// @data.sender
// @data.content
// @data.raw
bot.on('directMessage', (data) => {
console.log(`Private message from ${data.sender}: ${data.content}`);
if(data.content == "<message>")
{
// Send a message to the channel
// @channel
// @message
let longMessage = "This is a very long message ".repeat(50); // Just an example of a long message
bot.sendMessage(channel, longMessage, "blue");
// Send a private message
// @user
// @message
bot.sendMessage("nickname", 'Hello, nickname! How are you?.');
}
if(data.content == "<part>")
{
// Leave a specific channel
// @channel
// @Leaving Message
bot.part(channel, 'Im done.');
}
if(data.content == "<join>")
{
// Join a channel
// @channel
bot.joinChannel(channel);
}
if(data.content == "<names>")
{
// Get users in the channel
// @channel
bot.names(channel);
}
if(data.content == "<kick>")
{
// Kick a user
// @channel
// @user
// @reason
bot.kick(channel, 'JohnDoe59', "Kicked by the bot");
}
if(data.content == "<ban>")
{
// Ban a user
// @channel
// @user
// @reason
bot.ban(channel, 'JohnDoe59@2001:818:df14:8c00:f08b:fad2:e1cd:63c5');
}
if(data.content == "<banlist>")
{
// Get the channel ban list
// @channel
bot.banlist(channel);
}
if(data.content == "<whois>")
{
// Get information about a user
// @user
bot.whois('Nickname').then((whoisData) => {
console.log('WHOIS data:', whoisData);
})
.catch((err) => {
console.error('WHOIS error:', err);
});
}
if(data.content == "<getusers>")
{
console.log(bot.userManager.getUserInfo('Joaquim'));
}
});
// Triggered whenever a message is received in a channel
// @data.sender
// @channel,
// @data.content
// @data.raw:
bot.on('channelMessage', (data) => {
console.log(`Channel message in ${data.channel} from ${data.sender}: ${data.content}`);
});
// Message of the Day (MOTD)
// @data.user,
// @data.content
// @data.raw:
bot.on('motd', (data) => {
console.log(`${data.content}`);
});
// User joined the channel, raw event with basic info.
// @data.user
// @data.channel
// @data.raw
bot.on('join', (data) => {
console.log(`${data.user} joined ${data.channel}`);
});
// User joined the channel via userManager module that returns a complete whois info of that user.
// @data.username
// @data.host
// @data.realName
// @data.server
// @data.serverInfo
// @data.idleTime
// @data.channels
// @data.isOperator
// @data.isRegistered
bot.userManager.on('join', (data) => {
console.log(`User Join:`);
console.log(data);
});
// Receive complete Whois info
// @data.username
// @data.host
// @data.realName
// @data.server
// @data.serverInfo
// @data.idleTime
// @data.channels
// @data.isOperator
// @data.isRegistered
bot.on('whois', (data) => {
// console.log(data);
});
// User left the channel
// @data.user
// @data.channel
// @data.reason
// @data.raw
bot.on('part', (data) => {
console.log(`${data.user} left ${data.channel}: ${data.reason}`);
});
// Unknown command received
// @data.command
// @data.raw
bot.on('unknown', (data) => {
console.log(`Unknown command ${data.command}: ${data.raw}`);
});
// List of users in a channel
// @data.channel
// @data.names
// @data.raw
bot.on('names', (data) => {
console.log(`Users in ${data.channel}:`, data.names);
});
// Triggered when a notice is received
// @data.target
// @data.content
// @data.raw
bot.on('notice', (data) => {
console.log(`${data.content}`);
});
// Triggered when bot is kicked
bot.on('botKicked', () => {
console.log(`Bot was kicked.`);
});
// Triggered when a user quits
// @data.user
// @data.channel
// @data.reason
// @data.raw
bot.on('quit', (data) => {
console.log(`User ${data.user} quit. (${data.reason})`);
});
// Mode was applied (triggered whenever a +mode is set)
// @data.user (channel or user, starting with # or not)
// @data.mode
// @affected
bot.on('+mode', (data) => {
console.log(`[MODE] ${data.user} - Modes: ${data.mode}, Affected: ${data.affected}`);
});
// Mode was applied (triggered whenever a -mode is set)
// @data.user (channel or user, starting with # or not)
// @data.mode
// @affected
bot.on('-mode', (data) => {
console.log(`[MODE] ${data.user} - Modes: ${data.mode}, Affected: ${data.affected}`);
});
// Triggered whenever