Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
New cache system for autofix lavalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RainyXeon committed Jun 21, 2023
1 parent 0cf5806 commit 4e1df87
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ dist

application.yml

cylane.database.json
cylane.database.json

.cylane/
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"express-rate-limit": "^6.7.0",
"express-session": "^1.17.3",
"express-status-monitor": "^1.3.4",
"fs-extra": "^11.1.1",
"humanize-duration": "^3.27.3",
"js-yaml": "^4.1.0",
"jsonwebtoken": "^9.0.0",
Expand Down
11 changes: 4 additions & 7 deletions src/handlers/loadCheck.js
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);
}
}
2 changes: 1 addition & 1 deletion src/lava_scrap/check_lavalink_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = async (client) => {
name: `${config.host}:${config.port}`,
online: false
})
client.logger.error(`Server: ${url}`)
client.logger.offline(`Server: ${url}`)
});

}
Expand Down
87 changes: 54 additions & 33 deletions src/lava_scrap/get_lavalink_server.js
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)
}
}

0 comments on commit 4e1df87

Please sign in to comment.