From 51a81624f3747f808f5faa20a400082d3e27a3dc Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 20 Mar 2024 17:09:53 -0400 Subject: [PATCH] Fix parse-domain --- Xiao.js | 4 ++++ commands/analyze/domain-available.js | 5 ++--- commands/analyze/is-it-down.js | 5 ++--- structures/Client.js | 7 +++++++ util/Util.js | 7 ++++++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Xiao.js b/Xiao.js index 8ad6616a..330d9abf 100644 --- a/Xiao.js +++ b/Xiao.js @@ -203,6 +203,10 @@ client.on('ready', async () => { client.logger.error(`[TIMEZONES] Failed to set timezones\n${err.stack}`); } + // Set up parse-domain + await client.loadParseDomain(); + client.logger.info('[PARSE DOMAIN] parse-domain loaded.'); + // Fetch adult site list try { await client.fetchAdultSiteList(); diff --git a/commands/analyze/domain-available.js b/commands/analyze/domain-available.js index cf3a87af..1c3665f4 100644 --- a/commands/analyze/domain-available.js +++ b/commands/analyze/domain-available.js @@ -1,6 +1,5 @@ const Command = require('../../framework/Command'); const request = require('node-superfetch'); -const { parseDomain, ParseResultType } = import('parse-domain'); const { GODADDY_KEY, GODADDY_SECRET } = process.env; module.exports = class DomainAvailableCommand extends Command { @@ -30,8 +29,8 @@ module.exports = class DomainAvailableCommand extends Command { } async run(msg, { url }) { - const { type, domain, topLevelDomains } = parseDomain(url.hostname); - if (type !== ParseResultType.Listed) return msg.reply('This domain is not supported.'); + const { type, domain, topLevelDomains } = this.client.parseDomain(url.hostname); + if (type !== this.client.ParseResultType.Listed) return msg.reply('This domain is not supported.'); try { const { body } = await request .get('https://api.godaddy.com/v1/domains/available') diff --git a/commands/analyze/is-it-down.js b/commands/analyze/is-it-down.js index 4c52b5ec..51922c1a 100644 --- a/commands/analyze/is-it-down.js +++ b/commands/analyze/is-it-down.js @@ -1,6 +1,5 @@ const Command = require('../../framework/Command'); const request = require('node-superfetch'); -const { parseDomain, ParseResultType } = import('parse-domain'); module.exports = class IsItDownCommand extends Command { constructor(client) { @@ -28,8 +27,8 @@ module.exports = class IsItDownCommand extends Command { } async run(msg, { url }) { - const { type, domain, topLevelDomains } = parseDomain(url.hostname); - if (type !== ParseResultType.Listed) return msg.reply('This domain is not supported.'); + const { type, domain, topLevelDomains } = this.client.parseDomain(url.hostname); + if (type !== this.client.ParseResultType.Listed) return msg.reply('This domain is not supported.'); try { const { text } = await request .post('https://www.isitdownrightnow.com/check.php') diff --git a/structures/Client.js b/structures/Client.js index 59114670..a94cb697 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -55,6 +55,13 @@ module.exports = class XiaoClient extends CommandClient { this.nsfwModel = null; } + async loadParseDomain() { + const parseDomainModule = await import('parse-domain'); + this.parseDomain = parseDomainModule.parseDomain; + this.ParseResultType = parseDomainModule.ParseResultType; + return parseDomainModule; + } + async registerFontsIn(filepath) { const files = fs.readdirSync(filepath); for (const file of files) { diff --git a/util/Util.js b/util/Util.js index a1387b47..3a8cbbde 100644 --- a/util/Util.js +++ b/util/Util.js @@ -3,7 +3,12 @@ const crypto = require('crypto'); const request = require('node-superfetch'); const fs = require('fs'); const tf = require('@tensorflow/tfjs-node'); -const { parseDomain, ParseResultType } = import('parse-domain'); +let parseDomain; +let ParseResultType; +import('parse-domain').then(loadedModule => { + parseDomain = loadedModule.parseDomain; + ParseResultType = loadedModule.ParseResultType; +}); const { decode: decodeHTML } = require('html-entities'); const { stripIndents } = require('common-tags'); const { URL } = require('url');