mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 21:44:48 +02:00
Update Font system
This commit is contained in:
@@ -221,7 +221,7 @@ client.on('ready', async () => {
|
|||||||
|
|
||||||
// Register all canvas fonts
|
// Register all canvas fonts
|
||||||
try {
|
try {
|
||||||
await client.registerFontsIn(path.join(__dirname, 'assets', 'fonts'));
|
await client.fonts.registerFontsIn(path.join(__dirname, 'assets', 'fonts'));
|
||||||
client.logger.info('[FONTS] All fonts loaded.');
|
client.logger.info('[FONTS] All fonts loaded.');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
client.logger.error(`[FONTS] Failed to load fonts\n${err.stack}`);
|
client.logger.error(`[FONTS] Failed to load fonts\n${err.stack}`);
|
||||||
@@ -243,9 +243,9 @@ client.on('ready', async () => {
|
|||||||
client.logger.error(`[ADULT SITES] Failed to fetch list\n${err.stack}`);
|
client.logger.error(`[ADULT SITES] Failed to fetch list\n${err.stack}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch NSFW model
|
// Set up nsfwjs
|
||||||
try {
|
try {
|
||||||
await client.tensorflow.loadNSFWModel();
|
await client.tensorflow.loadNSFWJS();
|
||||||
client.logger.info('[NSFW MODEL] Loaded NSFW model.');
|
client.logger.info('[NSFW MODEL] Loaded NSFW model.');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
client.logger.error(`[NSFW MODEL] Failed to load NSFW model\n${err.stack}`);
|
client.logger.error(`[NSFW MODEL] Failed to load NSFW model\n${err.stack}`);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ module.exports = class IsItDownCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { url }) {
|
async run(msg, { url }) {
|
||||||
|
if (!parseDomain || !ParseResultType) return msg.reply('Give me a second, still getting ready.');
|
||||||
const { type, domain, topLevelDomains } = parseDomain(url.hostname);
|
const { type, domain, topLevelDomains } = parseDomain(url.hostname);
|
||||||
if (type !== ParseResultType.Listed) return msg.reply('This domain is not supported.');
|
if (type !== ParseResultType.Listed) return msg.reply('This domain is not supported.');
|
||||||
const { text } = await request
|
const { text } = await request
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "148.0.0",
|
"version": "149.0.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
+2
-17
@@ -1,14 +1,10 @@
|
|||||||
const CommandClient = require('../framework/Client');
|
const CommandClient = require('../framework/Client');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const { Collection } = require('@discordjs/collection');
|
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const fontFinder = require('font-finder');
|
|
||||||
const moment = require('moment-timezone');
|
const moment = require('moment-timezone');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const Redis = require('./Redis');
|
const Redis = require('./Redis');
|
||||||
const Tensorflow = require('./Tensorflow');
|
const Tensorflow = require('./Tensorflow');
|
||||||
const Font = require('./Font');
|
const FontManager = require('./fonts/FontManager');
|
||||||
const PhoneManager = require('./phone/PhoneManager');
|
const PhoneManager = require('./phone/PhoneManager');
|
||||||
const TimerManager = require('./remind/TimerManager');
|
const TimerManager = require('./remind/TimerManager');
|
||||||
const PokemonStore = require('./pokemon/PokemonStore');
|
const PokemonStore = require('./pokemon/PokemonStore');
|
||||||
@@ -26,7 +22,7 @@ module.exports = class XiaoClient extends CommandClient {
|
|||||||
winston.format.printf(log => `[${log.timestamp}] [${log.level.toUpperCase()}]: ${log.message}`)
|
winston.format.printf(log => `[${log.timestamp}] [${log.level.toUpperCase()}]: ${log.message}`)
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
this.fonts = new Collection();
|
this.fonts = new FontManager(this);
|
||||||
this.redis = Redis ? Redis.db : null;
|
this.redis = Redis ? Redis.db : null;
|
||||||
this.timers = new TimerManager(this);
|
this.timers = new TimerManager(this);
|
||||||
this.pokemon = new PokemonStore();
|
this.pokemon = new PokemonStore();
|
||||||
@@ -38,17 +34,6 @@ module.exports = class XiaoClient extends CommandClient {
|
|||||||
this.adultSiteList = null;
|
this.adultSiteList = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async registerFontsIn(filepath) {
|
|
||||||
const files = fs.readdirSync(filepath);
|
|
||||||
for (const file of files) {
|
|
||||||
const metadata = await fontFinder.get(path.join(filepath, file));
|
|
||||||
const font = new Font(path.join(filepath, file), file, metadata);
|
|
||||||
this.fonts.set(file, font);
|
|
||||||
font.register();
|
|
||||||
}
|
|
||||||
return this.fonts;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimezones() {
|
setTimezones() {
|
||||||
moment.tz.link('America/Vancouver|Neopia');
|
moment.tz.link('America/Vancouver|Neopia');
|
||||||
moment.tz.link('America/Los_Angeles|Discord');
|
moment.tz.link('America/Los_Angeles|Discord');
|
||||||
|
|||||||
@@ -8,18 +8,17 @@ module.exports = class Tensorflow {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
Object.defineProperty(this, 'client', { value: client });
|
Object.defineProperty(this, 'client', { value: client });
|
||||||
|
|
||||||
this.nsfwModel = null;
|
this.nsfwjs = null;
|
||||||
this.faceModel = faceDetection.SupportedModels.MediaPipeFaceDetector;
|
|
||||||
this.faceDetector = null;
|
this.faceDetector = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadNSFWModel() {
|
async loadNSFWJS() {
|
||||||
const nsfwModel = await nsfw.load(
|
const nsfwjs = await nsfw.load(
|
||||||
`${url.pathToFileURL(path.join(__dirname, '..', 'tf_models', 'nsfw', 'web_model')).href}/`,
|
`${url.pathToFileURL(path.join(__dirname, '..', 'tf_models', 'nsfw', 'web_model')).href}/`,
|
||||||
{ type: 'graph' }
|
{ type: 'graph' }
|
||||||
);
|
);
|
||||||
this.nsfwModel = nsfwModel;
|
this.nsfwjs = nsfwjs;
|
||||||
return this.nsfwModel;
|
return this.nsfwjs;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadFaceDetector() {
|
async loadFaceDetector() {
|
||||||
@@ -42,7 +41,7 @@ module.exports = class Tensorflow {
|
|||||||
|
|
||||||
async isImageNSFW(image, bool = true) {
|
async isImageNSFW(image, bool = true) {
|
||||||
const img = await tfnode.node.decodeImage(image, 3);
|
const img = await tfnode.node.decodeImage(image, 3);
|
||||||
const predictions = await this.nsfwModel.classify(img);
|
const predictions = await this.nsfwjs.classify(img);
|
||||||
img.dispose();
|
img.dispose();
|
||||||
if (bool) {
|
if (bool) {
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
const { Collection } = require('@discordjs/collection');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const fontFinder = require('font-finder');
|
||||||
|
const Font = require('./Font');
|
||||||
|
|
||||||
|
module.exports = class FontManager extends Collection {
|
||||||
|
constructor(client, options) {
|
||||||
|
super(options);
|
||||||
|
|
||||||
|
Object.defineProperty(this, 'client', { value: client });
|
||||||
|
}
|
||||||
|
|
||||||
|
async registerFontsIn(filepath) {
|
||||||
|
const files = fs.readdirSync(filepath);
|
||||||
|
for (const file of files) {
|
||||||
|
const metadata = await fontFinder.get(path.join(filepath, file));
|
||||||
|
const font = new Font(path.join(filepath, file), file, metadata);
|
||||||
|
this.set(file, font);
|
||||||
|
font.register();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -211,6 +211,7 @@ module.exports = class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async isUrlNSFW(uri, siteList) {
|
static async isUrlNSFW(uri, siteList) {
|
||||||
|
if (!parseDomain || !ParseResultType) throw new Error('parse-domain still loading');
|
||||||
const parsed = new URL(uri);
|
const parsed = new URL(uri);
|
||||||
const { type, domain, topLevelDomains } = parseDomain(parsed.hostname);
|
const { type, domain, topLevelDomains } = parseDomain(parsed.hostname);
|
||||||
if (type !== ParseResultType.Listed) return null;
|
if (type !== ParseResultType.Listed) return null;
|
||||||
@@ -230,6 +231,7 @@ module.exports = class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static stripNSFWURLs(str, siteList, text = '[redacted nsfw url]') {
|
static stripNSFWURLs(str, siteList, text = '[redacted nsfw url]') {
|
||||||
|
if (!parseDomain || !ParseResultType) throw new Error('parse-domain still loading');
|
||||||
if (!str) return '';
|
if (!str) return '';
|
||||||
const uris = str.match(/(https?:\/\/\S+)/g);
|
const uris = str.match(/(https?:\/\/\S+)/g);
|
||||||
if (!uris) return str;
|
if (!uris) return str;
|
||||||
|
|||||||
Reference in New Issue
Block a user