Script to convert to new blacklist db format

This commit is contained in:
supositware 2021-03-13 18:19:26 +01:00
parent 8863fa6050
commit 219ecfaab5
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,45 @@
const TwitterBlacklist = require('../models').TwitterBlacklist;
const ytpblacklist = require('../models').ytpblacklist;
const userBlacklist = require('../models').userBlacklist;
const guildBlacklist = require('../models').guildBlacklist;
const Blacklists = require('../models').Blacklists;
console.log('Starting conversions');
convert(userBlacklist, 'global');
convert(ytpblacklist, 'ytp');
convert(TwitterBlacklist, 'tweet');
convert(guildBlacklist, 'guild');
console.log('Conversion finished.');
async function convert(database, type) {
const prefix = `[${type}]`;
console.log(`${prefix} Starting conversion`);
let db = await database.findAll();
for (let dbKey in db) {
let reason = 'No reason specified.';
let uid;
if (db[dbKey].guildID != undefined)
uid = db[dbKey].guildID;
else
uid = db[dbKey].userID;
if (uid == undefined)
return console.error(`${prefix}: FATAL ERROR`);
if (db[dbKey].reason != undefined)
reason = db[dbKey].reason;
const body = {type: type, uid: uid, reason: reason};
Blacklists.findOrCreate({where: body, defaults: body})
.catch(err => {
console.error(`${prefix}: ${err}`);
})
.then(() => {
console.log(`${prefix}: Successfully converted table`);
});
}
}

3
scripts/readme.md Normal file
View file

@ -0,0 +1,3 @@
# Various scripts for... things... idk
[ConvertBlacklists.js](convertBlacklists.js) - As the name imply, convert old blacklist format to the current one (as of 13.03.21)