This repository was archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreconnect.js
More file actions
47 lines (43 loc) · 1.29 KB
/
reconnect.js
File metadata and controls
47 lines (43 loc) · 1.29 KB
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
registerPlugin({
name: 'Reconnect',
version: '1.0.3',
description: 'Reconnects the bot',
author: 'Lala Sabathil <aiko@aitsys.dev>',
engine: '>= 1.0.0',
backends: ['discord', 'ts3'],
requiredModules: [],
autorun: true,
vars: [
{
name: 'ignconfail',
title: 'Ignore connection failed (Infinity reconnect)',
type: 'checkbox'
}
]
}, function(_, config, meta) {
var engine = require('engine');
var event = require('event');
var backend = require('backend');
engine.log("Loaded Reconnect");
event.on('discord:VOICE_STATE_UPDATE', function (ev) {
var cid = ev.channel_id;
if (typeof cid === undefined || cid == null) {
if (ev.user_id.split("/").pop() != backend.getBotClientID().split("/").pop()) {
return;
}
engine.log("Reconnecting");
if(backend.connect()) {
engine.log("Successfully");
} else {
engine.log("Error");
}
}
});
event.on('connectionFailed', function (reason) {
engine.log("Connection failed: " + reason);
if (config.ignconfail) {
engine.log("Reconnecting");
backend.connect();
}
});
});