Added support for url lists
This commit is contained in:
parent
56bb0d47a2
commit
2ad6627e02
2 changed files with 51 additions and 27 deletions
|
@ -2,6 +2,7 @@
|
||||||
"Username": "",
|
"Username": "",
|
||||||
"Password": "",
|
"Password": "",
|
||||||
"PNSLToken": "",
|
"PNSLToken": "",
|
||||||
|
"UsePNSL": true,
|
||||||
"Users": [],
|
"Users": [],
|
||||||
"Prefix": "!!",
|
"Prefix": "!!",
|
||||||
"MaxConnections": 30,
|
"MaxConnections": 30,
|
||||||
|
|
33
index.js
33
index.js
|
@ -19,6 +19,8 @@ const pnslClient = createGotClient({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const urlClient = createGotClient();
|
||||||
|
|
||||||
const fetchList = async (list) => {
|
const fetchList = async (list) => {
|
||||||
const listID = uuidRegex.exec(list)?.[0];
|
const listID = uuidRegex.exec(list)?.[0];
|
||||||
if (!listID) {
|
if (!listID) {
|
||||||
|
@ -44,6 +46,19 @@ const fetchList = async (list) => {
|
||||||
return {listMeta, listData};
|
return {listMeta, listData};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchUrlList = async (list) => {
|
||||||
|
const {body: listMetaBody, statusCode} = await urlClient(list);
|
||||||
|
if (statusCode === 404) {
|
||||||
|
throw new Error('List was not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusCode !== 200) {
|
||||||
|
throw new Error('Unexpected error occured!');
|
||||||
|
}
|
||||||
|
|
||||||
|
return listMetaBody;
|
||||||
|
};
|
||||||
|
|
||||||
const runList = async (listData, listID, channel) => {
|
const runList = async (listData, listID, channel) => {
|
||||||
const banArr = listData.split('\n');
|
const banArr = listData.split('\n');
|
||||||
|
|
||||||
|
@ -106,13 +121,14 @@ const say = (channel, message) => {
|
||||||
getConnection().say(channel, message);
|
getConnection().say(channel, message);
|
||||||
};
|
};
|
||||||
|
|
||||||
const pnslWebSocket = new WS('wss://bot.tetyys.com/api/wss', [], {headers: {Authorization: `Bearer ${Config.PNSLToken}`}});
|
if (Config.UsePNSL){
|
||||||
|
const pnslWebSocket = new WS('wss://bot.tetyys.com/api/wss', [], {headers: {Authorization: `Bearer ${Config.PNSLToken}`}});
|
||||||
|
|
||||||
pnslWebSocket.on('open', () => {
|
pnslWebSocket.on('open', () => {
|
||||||
console.log(`${chalk.green('[P&SL]')} || Connected to P&SL Websocket server`);
|
console.log(`${chalk.green('[P&SL]')} || Connected to P&SL Websocket server`);
|
||||||
});
|
});
|
||||||
|
|
||||||
pnslWebSocket.on('message', async (data) => {
|
pnslWebSocket.on('message', async (data) => {
|
||||||
const {o: type, p: payload} = JSON.parse(data);
|
const {o: type, p: payload} = JSON.parse(data);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: {
|
case 0: {
|
||||||
|
@ -132,7 +148,8 @@ pnslWebSocket.on('message', async (data) => {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await Promise.all([...Array(Config.MaxConnections)].map(async (_, i) => {
|
await Promise.all([...Array(Config.MaxConnections)].map(async (_, i) => {
|
||||||
|
@ -193,8 +210,14 @@ pnslWebSocket.on('message', async (data) => {
|
||||||
const mods = await getConnection().getMods(channel);
|
const mods = await getConnection().getMods(channel);
|
||||||
if (!mods.includes(Config.Username)) return say(Config.Username, `I am not a moderator in channel ${channel}!`);
|
if (!mods.includes(Config.Username)) return say(Config.Username, `I am not a moderator in channel ${channel}!`);
|
||||||
}
|
}
|
||||||
|
if (Config.UsePNSL) {
|
||||||
const data = await fetchList(listID);
|
const data = await fetchList(listID);
|
||||||
await runList(data.listData, listID, channel || channelName);
|
await runList(data.listData, listID, channel || channelName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const data = await fetchUrlList(listID);
|
||||||
|
await runList(data, listID, channel || channelName);
|
||||||
|
}
|
||||||
say(Config.Username, `List ${listID} executed successfully on channel ${channel || channelName}`);
|
say(Config.Username, `List ${listID} executed successfully on channel ${channel || channelName}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
Loading…
Reference in a new issue