forked from Supositware/Haha-Yes
Script to convert to new blacklist db format
This commit is contained in:
parent
8863fa6050
commit
219ecfaab5
2 changed files with 48 additions and 0 deletions
45
scripts/convertBlacklists.js
Normal file
45
scripts/convertBlacklists.js
Normal 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
3
scripts/readme.md
Normal 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)
|
Loading…
Reference in a new issue