This repository has been archived by the owner on Apr 6, 2024. It is now read-only.
generated from RainyXeon/nano-template-slashbot
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New cache system for autofix lavalink
- Loading branch information
Showing
6 changed files
with
130 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,4 +105,6 @@ dist | |
|
||
application.yml | ||
|
||
cylane.database.json | ||
cylane.database.json | ||
|
||
.cylane/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
const cron = require('node-cron') | ||
|
||
module.exports = async (client) => { | ||
if (client.config.get.features.AUTOFIX_LAVALINK && !client.has_run) { | ||
if (client.config.get.features.AUTOFIX_LAVALINK) { | ||
require("../lava_scrap/check_lavalink_server")(client) | ||
cron.schedule('* 30 * * * *', async () => { | ||
require("../lava_scrap/check_lavalink_server")(client) | ||
}) | ||
client.has_run = true | ||
setInterval(async () => { | ||
require("../lava_scrap/check_lavalink_server")(client) | ||
}, 1800000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,67 @@ | ||
const axios = require("axios") | ||
var MarkdownIt = require('markdown-it'); | ||
var md = new MarkdownIt(); | ||
|
||
const fse = require('fs-extra'); | ||
const logger = require("../plugins/logger") | ||
module.exports = async () => { | ||
let filter_data = [] | ||
let filter_data_2 = [] | ||
let final_data = [] | ||
|
||
const res = await axios.get("https://raw.githubusercontent.com/DarrenOfficial/lavalink-list/master/docs/NoSSL/lavalink-without-ssl.md") | ||
var result = md.parse(res.data); | ||
|
||
result.filter(async data => { | ||
if (data.tag == "code") { | ||
filter_data.push(data.content) | ||
function getLavalinkServerInfo(data) { | ||
var result = md.parse(data); | ||
|
||
result.filter(async data => { | ||
if (data.tag == "code") { | ||
filter_data.push(data.content) | ||
} | ||
}) | ||
|
||
for (let i = 0; i < filter_data.length; i++) { | ||
const element = filter_data[i]; | ||
// Phrase data | ||
const res = element.replace(/\n/g, ""); | ||
const res2 = res.replace(/\s+/g, "") | ||
const res3 = res2.replace(/Host/g, "") | ||
const res4 = res3.replace(/Port/g, "") | ||
const res5 = res4.replace(/Password/g, "") | ||
const res6 = res5.replace(/Secure/g, "") | ||
const res7 = res6.replace(/[&\/\\#,+()$~%'"*?<>{}]/g, "") | ||
filter_data_2.push(res7) | ||
} | ||
}) | ||
|
||
for (let i = 0; i < filter_data.length; i++) { | ||
const element = filter_data[i]; | ||
// Phrase data | ||
const res = element.replace(/\n/g, ""); | ||
const res2 = res.replace(/\s+/g, "") | ||
const res3 = res2.replace(/Host/g, "") | ||
const res4 = res3.replace(/Port/g, "") | ||
const res5 = res4.replace(/Password/g, "") | ||
const res6 = res5.replace(/Secure/g, "") | ||
const res7 = res6.replace(/[&\/\\#,+()$~%'"*?<>{}]/g, "") | ||
filter_data_2.push(res7) | ||
|
||
for (let i = 0; i < filter_data_2.length; i++) { | ||
const regex_extract = /:(.{0,99999}):([0-9]{0,99999}):(.{0,99999}):(false|true)/ | ||
const element = filter_data_2[i]; | ||
const res = regex_extract.exec(element) | ||
final_data.push({ | ||
host: res[1], | ||
port: res[2], | ||
pass: res[3], | ||
secure: res[4] == "false" || res[4] == "False" ? false : true, | ||
online: false | ||
}) | ||
} | ||
|
||
return final_data | ||
} | ||
|
||
for (let i = 0; i < filter_data_2.length; i++) { | ||
const regex_extract = /:(.{0,99999}):([0-9]{0,99999}):(.{0,99999}):(false|true)/ | ||
const element = filter_data_2[i]; | ||
const res = regex_extract.exec(element) | ||
final_data.push({ | ||
host: res[1], | ||
port: res[2], | ||
pass: res[3], | ||
secure: res[4] == "false" || res[4] == "False" ? false : true, | ||
online: false | ||
}) | ||
} | ||
if (!fse.existsSync("./.cylane")) { | ||
const res = await axios.get("https://raw.githubusercontent.com/DarrenOfficial/lavalink-list/master/docs/NoSSL/lavalink-without-ssl.md") | ||
|
||
return final_data | ||
fse.outputFile('.cylane/lavalink_no_ssl.md', res.data) | ||
.then(() => { | ||
logger.info('New cache has been created!'); | ||
}) | ||
.catch(err => { | ||
logger.error(err) | ||
}); | ||
|
||
return getLavalinkServerInfo(res.data) | ||
|
||
} else if (fse.existsSync("./.cylane")) { | ||
logger.info('Cache found. Now using for speed up'); | ||
const data = await fse.readFile('./.cylane/lavalink_no_ssl.md', { encoding: 'utf8' }); | ||
return getLavalinkServerInfo(data) | ||
} | ||
} |