tests stuff

This commit is contained in:
Erik 2022-04-27 20:06:54 +03:00
parent 5443ed294c
commit 17a3186005
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
15 changed files with 2536 additions and 26 deletions

View File

@ -7,7 +7,8 @@
"start": "node index.js",
"dev": "nodemon --trace-warnings --unhandled-rejections=strict index.js",
"debug": "node --trace-warnings --inspect index.js",
"update": "git pull && cd api && yarn update"
"update": "git pull && cd api && yarn update",
"test": "jest --detectOpenHandles"
},
"repository": {
"type": "git",
@ -38,6 +39,7 @@
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"jest": "^28.0.2",
"nodemon": "^2.0.7"
}
}

View File

@ -110,6 +110,12 @@ class DiscordClient extends Client {
}
async destroy() {
await this.storageManager.destroy();
await super.destroy();
clearInterval(this._activityInterval);
}
// Wait until the client is actually ready, i.e. all structures from discord are created
ready() {
@ -161,6 +167,7 @@ class DiscordClient extends Client {
}
};
if (!this.shard) return;
await activities[this._activity]();
if(this._activity === Math.max(...Object.keys(activities))) this._activity = 0;
else this._activity++;
@ -168,6 +175,7 @@ class DiscordClient extends Client {
}
get singleton() {
if (!this.shard) return true;
return this.shard.count === 1;
}
@ -266,10 +274,11 @@ class DiscordClient extends Client {
}
module.exports = DiscordClient;
// module.exports = DiscordClient;
const client = new DiscordClient(options);
client.build();
module.exports = { client, DiscordClient };
// process.on("unhandledRejection", (error) => {
// console.error("[DiscordClient.js] Unhandled promise rejection:", error); //eslint-disable-line no-console

View File

@ -14,6 +14,7 @@ class Intercom {
send(type, message = {}) {
if (typeof message !== 'object') return false;
if (!process.send) return; // Nowhere to send, the client was not spawned as a shard
return process.send({
[`_${type}`]: true,
...message

View File

@ -1,6 +1,6 @@
const timestring = require('timestring');
// eslint-disable-next-line no-unused-vars
const DiscordClient = require('../DiscordClient');
const { DiscordClient } = require('../DiscordClient');
// eslint-disable-next-line no-unused-vars
const Component = require('../interfaces/Component');
const { Constants: { InfractionResolves } } = require('../../constants');

View File

@ -1,5 +1,5 @@
// eslint-disable-next-line no-unused-vars
const DiscordClient = require("../DiscordClient");
const { DiscordClient } = require("../DiscordClient");
class Component {

View File

@ -8,7 +8,7 @@ const Component = require("./Component.js");
// eslint-disable-next-line no-unused-vars
const InteractionWrapper = require("../client/wrappers/InteractionWrapper.js");
// eslint-disable-next-line no-unused-vars
const DiscordClient = require("../DiscordClient.js");
const { DiscordClient } = require("../DiscordClient.js");
const TypeResolves = ['USER', 'GUILD'];

View File

@ -1,7 +1,7 @@
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const DiscordClient = require('../../DiscordClient.js');
const { DiscordClient } = require('../../DiscordClient.js');
const Component = require('../Component.js');
const CommandOption = require('../CommandOption.js');

View File

@ -1,7 +1,7 @@
const Command = require('./Command.js');
const { Commands: CommandsConstant } = require('../../../constants/');
// eslint-disable-next-line no-unused-vars
const DiscordClient = require('../../DiscordClient.js');
const { DiscordClient } = require('../../DiscordClient.js');
class SlashCommand extends Command {

View File

@ -42,6 +42,11 @@ class StorageManager {
}
async destroy() {
const keys = Object.keys(this.providers);
for (const provider of keys) await this.providers[provider].destroy();
}
_getName(instance) {
if (instance instanceof Provider) return instance.name.substring(0, 5);
return `${instance.provider.name.substring(0, 5)}:${instance.name}`;

View File

@ -44,8 +44,8 @@ class MariaDBProvider extends Provider {
}
close() {
this.db.end();
destroy() {
this.db?.end();
}
/**

View File

@ -30,6 +30,10 @@ class MongoDBProvider extends Provider {
}
destroy() {
return this.connection.close();
}
stats(options = {}) {
return new Promise((resolve, reject) => {

View File

@ -15,7 +15,10 @@ class Logger {
if (typeof message !== 'string') message = inspect(message);
message = `${chalk.bold(`[${this.name.substring(0, 6)}]`)} ${message}`;
process.send({ _logger: true, message, ...opts });
// eslint-disable-next-line no-console
if (!process.send) console.log(message);
else process.send({ _logger: true, message, ...opts });
//return this.client.intercom.send('logger', { message, ...opts });
}

44
tests/Migrator.test.js Normal file
View File

@ -0,0 +1,44 @@
/* eslint-disable no-undef */
require('dotenv').config();
const Migrator = require('../src/utilities/SettingsMigrator.js');
const sampleSettingsV2 = require('./sampleSettingsV2.json');
const { client } = require('../src/structure/DiscordClient.js');
//const client = new Client();
const dbs = {
'2': process.env.NODE_ENV === 'development' ? 'navybot' : 'galacticbot',
'3': 'newgbot'
};
const version = '2';
const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env;
const migrator = new Migrator(client, '264527028751958016', {
host: MONGODB_HOST,
username: MONGODB_USERNAME,
password: MONGODB_PASSWORD,
database: dbs[version], // Default to v3
version
});
const _test = async () => {
await client.ready();
await migrator.connect();
const { settings, webhook, permissions } = await migrator.migrate();
await migrator.end();
await client.destroy();
client.removeAllListeners();
console.log(settings);
console.log(permissions);
// expect(settings).toMatchObject({
// guildId: expect.any(String),
// mute: {
// role: expect.any(String),
// type: expect.any(Number)
// }
// });
};
_test();
// test('migration', _test);

847
tests/sampleSettingsV2.json Normal file
View File

@ -0,0 +1,847 @@
{
"desc": "Hi we're stylis",
"modlogs": "187022003679526912",
"roles": {
"403345643310940160": {
"perms": [
"category:moderation",
"override",
"mod",
"command:mute",
"moderation",
"command:modmail",
"command:lockdown",
"command:activity"
],
"ch": {}
},
"346732470466772994": {
"perms": [
"mod",
"override",
"command:kick",
"command:softban",
"command:mute",
"command:tempban",
"command:warn",
"command:moderation",
"command:reason",
"command:roleadd",
"command:roleremove",
"command:unmute",
"command:moderator",
"command:edit",
"command:note",
"command:case"
],
"ch": {}
},
"495059370640539648": {
"perms": [
"command:activity",
"moderation:dehoist"
],
"ch": {}
},
"478698979429974017": {
"perms": [
"command:music",
"command:poll"
],
"ch": {}
},
"458399776296140801": {
"perms": [
"command:music"
],
"ch": {}
},
"187018446288977920": {
"perms": [
"administrator"
],
"ch": {}
}
},
"ignore": [
"187017643448991745",
"720888875391909929",
"200318949135613952",
"630572011189698591",
"672851001115541504",
"673936079136751654",
"187020781094567936",
"486250928761208863",
"461549994541973504",
"234818083116679169",
"565272623811133450",
"366765951603048449",
"562200986261782531",
"364046721699020812",
"602613788151250955",
"653821761867218967",
"826925301527347220",
"843455554190049280",
"882859596585242655",
"888149099600289852",
"941898301366730752"
],
"muterole": "212020404196212736",
"automod": {
"enabled": true,
"thresholds": {
"7": "mute",
"10": "mute",
"15": "mute",
"20": "hardban"
},
"lengths": {
"7": 21600,
"10": 43200,
"15": 86400
},
"standalone": false,
"modBetweenT": false
},
"modpoints": {
"enabled": true,
"note": 0,
"warn": 0,
"kick": 0,
"mute": 0,
"ban": 0,
"softban": 0,
"hardban": 0,
"tempban": 0,
"noteExpire": false,
"warnExpire": 1209600,
"kickExpire": 1209600,
"muteExpire": 1209600,
"banExpire": 1209600,
"softbanExpire": 1209600,
"hardbanExpire": false,
"tempbanExpire": 1209600,
"associations": {},
"multiplier": true
},
"wordFilter": {
"filter": [
"fag",
"nigger",
"nigga",
"faggot",
"nibba",
"furfag",
"niqqer",
"kys",
"kms",
"coon",
"kike",
"nignog",
"pedophile",
"bestiality",
"zoophile",
"chink",
"spic",
"gook",
"niqqa",
"fags",
"retard",
"retarded",
"rarted",
"autistic",
"penis",
"vagina",
"niggas",
"nibbas",
"tard",
"nig",
"☭",
"naegur",
"卐",
"卍",
"porn",
"hentai",
"horn pub",
"libtard",
"yiff",
"cock and ball torture",
"pedo",
"blowjob",
"blow job",
"﷽",
"retardation",
"kill myself",
"cbt",
"lolita",
"shotacon",
"cdn.dlcordapp.com",
"dlcordapp.com",
"nixggas",
"horny",
"kontol",
"cock",
"cockface",
"pornhub",
"cum",
"dildo",
"kill yourself",
"negro",
"sex",
"fap",
"blowie",
"bellend",
"h*ntai",
"nnn",
"pussy",
"no nut november",
"e621",
"onlyfans",
"semen",
"erotic",
"slut",
"cunt",
"nudes",
"dick",
"fucktard",
"ahegao",
"masturbate",
"r34",
"8=d",
"https://twitter.com/marnsfw",
"https://www.youtube.com/watch?v=9xt75_0ufeu",
"9xt75_0ufeu",
"https://meet.google.com/",
"pornography",
"edp445",
"https://youtu.be/p3zr0qbgxzq",
"p3zr0qbgxzq",
"https://www.youtube.com/watch?v=1iaew3sk40w",
"1iaew3sk40w",
"foreskin",
"milf",
"trial version of a very cool fps booster",
"masturbating",
"https://www.youtube.com/watch?v=qslsum7hjxw",
"https://youtu.be/qslsum7hjxw",
"nft",
"non fungible"
],
"enabled": false,
"roleExempt": [
"187018446288977920",
"187023659922227200"
],
"channelExempt": [
"201035821644644352",
"422639212421054464",
"647825119061737472",
"562520178295046154",
"187018824518729728",
"478723173320491008",
"832028099570171904",
"831345944829886570",
"819163367297515530"
],
"explicit": false,
"silent": false,
"multi": false,
"joint": false,
"whitelist": [
"blobsob",
"tarnation",
"audio",
"shots",
"lofi",
"lol",
"shot",
"at",
"audit",
"lol i",
"aldi",
"lols",
"lol it",
"shot a",
"logi",
"loki",
"lol ik",
"hola",
"detonation",
"shot and",
"lol idk",
"tar-",
"lole",
"saudi",
"control",
"corny",
"recreations",
"s",
"coco",
"noob",
"boom",
"babies",
"hoodie",
"hoodies",
"boot",
"poob",
"zombies",
"spicy",
"spicy a",
"cockroach",
"pogn",
"cork ",
"antistatic",
"horns",
"cocky",
"yelled",
"coca",
"cork",
"ap",
"belle",
"devastation",
"seperation",
"bowie",
"blend",
"degradation",
"celled",
"blondie",
"nero",
"gooi",
"brownie",
"festivity",
"exotic",
"heretic",
"pissy",
"figs",
"pick",
"rattled",
"readed",
"shore",
"slug",
"slur",
"dudes",
"nukes",
"nades",
"spice",
"belted",
"nodes",
"welland",
"leotard",
"punt",
"hag",
"dice",
"blowing",
"more",
"vote",
"disturbance",
"tock",
"segment",
"disk",
"an alt",
"canal",
"tudi",
"anti-optic",
"antioptic",
"ellen",
"intervention",
"shotgon",
"recomendation",
"photography",
"geography",
"paragraph",
"sussy",
"paragraphs",
"restorations",
"exotics",
"milk",
"mile",
"mild",
"redirection",
"freakin",
"deterioration",
"biography",
"discography",
"reskin",
"erratic",
"refraction",
"mcthink",
"runt"
]
},
"linkfilter": {
"filter": [
"puu.sh",
"imgur.com",
"discordapp.com",
"tumblr.com",
"steamcommunity.com",
"steampowered.com",
"youtube.com",
"youtu.be",
"wikipedia.org",
"strawpoll.me",
"roblox.com",
"xkcd.com",
"giphy.com",
"bing.com",
"imdb.com",
"google.com",
"twitch.tv",
"intel.com",
"stylis-studios.com",
"twitter.com",
"reddit.com",
"gyazo.com",
"tenor.co",
"soundcloud.com",
"streamable.com",
"spotify.com",
"redd.it",
"trello.com",
"desmos.com",
"prntscr.com",
"media.discordapp.net",
"minecraft.curseforge.com",
"amazon.com",
"guild.id",
"stackoverflow.com",
"ggplot2.tidyverse.org",
"rdocumentation.org",
"lua.org",
"repl.it",
"github.io",
"jetbrains.com",
"roblox.fandom.com",
"scriptinghelpers.org",
"bost.ocks.org",
"www.geeksforgeeks.org",
"mozilla.org",
"npmjs.com",
"pcpartpicker.com",
"r6.tracker.network",
"businessinsider.com",
"bbc.com",
"curseforge.com",
"technicpack.net",
"minecraft.net",
"roblox-phantom-forces.fandom.com",
"discord.com",
"forms.gle",
"medal.tv",
"chess.com",
"gfycat.com",
"virustotal.com",
"drop.com"
],
"enabled": false,
"whitelist": true,
"channels": [
"201035821644644352",
"565272623811133450"
],
"roles": [
"478698979429974017",
"187023659922227200",
"268102802256035853",
"187018446288977920"
],
"message": null,
"silent": false,
"logs": "343789680598450186"
},
"invitefilter": {
"enabled": true,
"roles": [
"478701197625131018",
"187018446288977920",
"187023659922227200",
"416633532773957633"
],
"channels": {
"831345944829886570": -1,
"723398397238706276": -1,
"478751205083054100": -1,
"187020781094567936": -1,
"415031088142876673": -1,
"461549994541973504": -1,
"824935751035912202": -1,
"843455554190049280": -1,
"439283221037842453": -1,
"313777885917872128": -1,
"478723173320491008": -1,
"826398852725866567": -1,
"422640215857954826": -1,
"366765951603048449": -1,
"544897383650295818": -1,
"446094920709701634": -1,
"837115044017471509": -1,
"343789680598450186": -1,
"585544997546491915": -1,
"414875181019037708": -1,
"673936079136751654": -1,
"815011934851301406": -1,
"850779945734111242": -1,
"462809032638332928": -1,
"849880723518259200": -1,
"422643057654235137": -1,
"631879837157556224": -1,
"721683025196351508": -1,
"564897832331640872": -1,
"427574426700349450": -1,
"562519878033080330": -1,
"690086640613720078": -1,
"371545522823102472": -1,
"646855785380577280": -1,
"673935629851033620": -1,
"234818083116679169": -1,
"720888875391909929": -1,
"201035821644644352": 1,
"607319286838591503": -1,
"565272623811133450": -1,
"653821761867218967": -1,
"187017643448991745": -1,
"562520178295046154": -1,
"850778778794852389": -1,
"187022003679526912": -1,
"582348959284985886": -1,
"723404892106129470": -1,
"672851001115541504": -1,
"407304030570938368": -1,
"486250928761208863": -1,
"673935743911198726": -1,
"337791537801068545": -1,
"727244360760164394": -1,
"364046721699020812": -1,
"819163367297515530": -1,
"722211815320453121": -1,
"630572011189698591": -1,
"808782477963296848": -1,
"242333621166276609": -1,
"774661138452709436": -1,
"422639212421054464": -1,
"432389374018322432": -1,
"562493165953875968": -1,
"832028099570171904": -1,
"677221132402950184": -1,
"647825119061737472": -1,
"414664329477226516": -1,
"572872032560218112": -1,
"200318949135613952": -1,
"775271447689429023": -1,
"187018991074541568": -1,
"720330462467194981": -1,
"461080350488133633": -1,
"740260150111240263": -1,
"187027110546636802": -1,
"562200986261782531": -1,
"480950367191040000": -1,
"673935222135586856": -1,
"602613788151250955": -1
}
},
"chatlogs": {
"roleignore": [],
"channelignore": [
"187018991074541568",
"201035821644644352",
"422639212421054464",
"562493165953875968",
"723398397238706276",
"723404892106129470",
"727244360760164394"
],
"webhook": "808140522417684541",
"channel": "343789680598450186",
"enabled": true,
"imageLogs": true
},
"activity": {
"voice": true,
"messages": true,
"ignored": []
},
"selfrole": {
"roles": [
"517348025257951233",
"566003265775599640",
"737801772663308338",
"739895933008871542",
"888211923139706950",
"937204560500502568"
],
"enabled": true
},
"killitwithfire": {
"startsWith": [
"-set",
"killitwithfire",
"startsWith",
"add",
"@",
"あ",
"や",
"ぶ",
"ん",
"丸",
"",
"?",
"█",
"`",
"_",
"!",
"\"",
"#",
"$",
"%",
"&",
"'",
"(",
")",
"*",
"+",
",",
"-",
".",
"/"
],
"enabled": true,
"strict": false
},
"memberlogs": {
"channel": "562520178295046154",
"enabled": true,
"join": "{mention} has joined the server. Account age: {accage}",
"leave": "**{tag}** (<@{id}>) has left the server. Was a member for: {memberfor}"
},
"staffRole": "495059370640539648",
"staffRule": "Only use this command in the case of an emergency, and in any other case ping individual mods.\n\n__Emergencies include:__\n*- Raids*\n*- Mass spam*\n*- NSFW posts*\n*- No mods responding*\n\nMisuse / Trolling of this command will result in punishment.",
"userlogs": {
"channel": "562519878033080330",
"vc": true,
"nick": true
},
"music": {
"override": [
"495059370640539648"
],
"perm": true,
"skip": true
},
"permissions": {
"458399776296140801": [],
"403345643310940160": []
},
"grantable": {
"enabled": true,
"roles": [
"381510668387483650",
"565272463265497088",
"473727112692498443",
"483598479013183488",
"349590423603380236",
"475894578214469662",
"476610706142396437",
"475894578034114571",
"475894576977281034",
"475894576645799963",
"475894576087826433",
"476609269492482052",
"475894575022735375",
"475894574292664380",
"792537483401101332",
"816869078462496790",
"944363540632985680",
"475894575588704265"
],
"logs": null
},
"moderation": {
"resolve": {
"delete": false
},
"banlogs": {
"enabled": true
},
"modloglevel": 2,
"anonymous": false,
"silent": false,
"onban": false
},
"commands": {
"approve": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/707963490526298112/799817898347855902/Meme_Approved_Knuckles.mp4",
"type": 1
},
"default-dance": {
"perm": false,
"content": "https://tenor.com/view/roblox-default-dance-reakize-funny-epic-gif-13539724",
"type": 1
},
"toot": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/461549994541973504/568824804749344778/toot_toot.jpg",
"type": 1
},
"bruh": {
"perm": false,
"content": "bruh",
"type": 1
},
"fire": {
"perm": false,
"content": "{user} fired {mention}, find a new job loser 😎",
"type": 1
},
"appeal": {
"perm": false,
"content": "Read <#427574426700349450> carefully and do as instructed. Commands should go into <@!236583664031367168>'s DMs.",
"type": 1
},
"support": {
"perm": false,
"content": "Read <#427574426700349450> carefully and do as instructed. Commands should go into <@!236583664031367168> DMs.",
"type": 1
},
"animepfp": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/201035821644644352/600805917566566458/unknown.png",
"type": 1
},
"animepfp2": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/422639212421054464/613133536739983360/f405e63.png",
"type": 1
},
"animepfp3": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/647825119061737472/671766802220449807/damn_weebs.png",
"type": 1
},
"animepfp4": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/647825119061737472/671767465532850176/animepfp.png",
"type": 1
},
"furrypfp": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/201035821644644352/373245645789593601/unknown.png",
"type": 1
},
"abuse": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/187020781094567936/607343156400357377/3f67ec4.png",
"type": 1
},
"bully": {
"perm": false,
"content": "{user} bullied {mention}, what a loser",
"type": 1
},
"warme": {
"perm": false,
"content": "{mention} has been warmed.",
"type": 1
},
"weewoo": {
"perm": false,
"content": "<a:siren:584438234302382100> **WEE WOO** <a:siren:584438234302382100>",
"type": 1
},
"ceasr": {
"perm": false,
"content": "https://i.imgur.com/QmsB6K6.png",
"type": 1
},
"doubt": {
"perm": false,
"content": "https://i.gyazo.com/77e2d2b18a3f94a3aa4da9c5dc6aaaa6.jpg",
"type": 1
},
"og": {
"perm": false,
"content": "Did you ever hear the tragedy of OG_JustinYT? I thought not. Its not a story the moderators would tell you. Its a shitpost story. OG_JustinYT was a horrible shitposter of the community, so bad and so terrible he couldnt use the Force to influence the moderators to create, garbage memes… He had such a knowledge of the cancer force that he could even keep the ones he cared about from becoming edgy. The cancer side of the Force is a pathway to many abilities some consider to be bannable. He became so powerful… the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught everyone how cancerous he was, everything he knew, then the moderators killed his account. Ironic. He could shitpost on others servers, but couldnt save his account.",
"type": 1
},
"cease": {
"perm": false,
"content": "https://i.imgur.com/hwTUFCY.png",
"type": 1
},
"no": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/187027110546636802/460756371248381953/tenor.gif",
"type": 1
},
"robux": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/335481931544395776/360400208611508225/Screenshot_383.png",
"type": 1
},
"f": {
"perm": false,
"content": "f",
"type": 1
},
"navy": {
"perm": false,
"content": "https://i.imgur.com/WbJs4m1.png",
"type": 1
},
"megaban": {
"perm": false,
"content": "**{mention} HAS JUST BEEN SMASHED WITH ORBITAL BAN, USER IS NOW BANNED FROM DISCORD AND IN GAME**/s",
"type": 1
},
"nukeban": {
"perm": false,
"content": "**{mention} HAS JUST BEEN NUKE BANNED**\nhttps://tenor.com/view/explosion-nuke-boom-nuclear-gif-5791468",
"type": 1
},
"deny": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/422639212421054464/808507102309384202/video0_10.mp4",
"type": 1
},
"banne": {
"perm": false,
"content": "{user} smashed {mention} with banne",
"type": 1
},
"warm": {
"perm": false,
"content": "{mention} has been warmed.",
"type": 1
},
"hardbam": {
"perm": false,
"content": "🗨️❌ {mention} was hard-banned because ``lame``",
"type": 1
},
"war": {
"perm": false,
"content": "https://cdn.discordapp.com/attachments/422639212421054464/923997220683018251/unknown.png",
"type": 1
},
"cool": {
"perm": false,
"content": "{mention} has been cooled. <:b1:939788964007641128>",
"type": 1
},
"weebbgon": {
"perm": false,
"content": "https://media.discordapp.net/attachments/187017643448991745/964092043347525702/d40aq79m7yr21.png",
"type": 1
}
},
"mutetype": 1,
"raidprotection": {
"enabled": false,
"age": 300
},
"privatelog": {
"custom": false,
"onban": "You may join this server (discord.gg/asdasd) to look into appealing.",
"ontempban": false
}
}

1625
yarn.lock

File diff suppressed because it is too large Load Diff