Skip to content

Commit

Permalink
refactor: update submodule URL and refactor imageToTensor()
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Feb 23, 2024
1 parent c41a307 commit 2f7fc71
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "locales"]
path = locales
url = https://github.com/Discord-InterChat/locales.git
url = https://github.com/Discord-InterChat/localization.git
15 changes: 6 additions & 9 deletions src/api/routes/nsfw.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { load } from 'nsfwjs';
import { Router } from 'express';
import { captureException } from '@sentry/node';
import { enableProdMode, tensor3d } from '@tensorflow/tfjs-node';
import { Tensor3D } from '@tensorflow/tfjs';
import { tensor3d } from '@tensorflow/tfjs-node';
import Logger from '../../utils/Logger.js';
import sharp from 'sharp';
import jpeg from 'jpeg-js';

// disable tfjs logs
enableProdMode();

let nsfwModel;
const router: Router = Router();

const imageToTensor = async (rawImageData: ArrayBuffer) => {
rawImageData = await sharp(rawImageData).raw().jpeg().toBuffer();
const decoded = jpeg.decode(rawImageData); // This is key for the prediction to work well
const { width, height, data } = decoded;
const jpegImg = await sharp(rawImageData).jpeg().toBuffer();

const { width, height, data } = jpeg.decode(jpegImg); // This is key for the prediction to work well
const buffer = new Uint8Array(width * height * 3);

let offset = 0;
for (let i = 0; i < buffer.length; i += 3) {
buffer[i] = data[offset];
Expand All @@ -27,7 +24,7 @@ const imageToTensor = async (rawImageData: ArrayBuffer) => {
offset += 4;
}

return tensor3d(buffer, [height, width, 3]) as unknown as Tensor3D;
return tensor3d(buffer, [height, width, 3]);
};


Expand Down
12 changes: 6 additions & 6 deletions src/commands/slash/Information/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ButtonStyle,
} from 'discord.js';
import BaseCommand from '../../BaseCommand.js';
import { colors } from '../../../utils/Constants.js';
import { colors, emojis } from '../../../utils/Constants.js';
import { t } from '../../../utils/Locale.js';

export default class Vote extends BaseCommand {
Expand All @@ -15,17 +15,17 @@ export default class Vote extends BaseCommand {
description: 'Voting perks and vote link.',
};
async execute(interaction: ChatInputCommandInteraction) {
const { locale } = interaction.user;
const embed = new EmbedBuilder()
.setDescription(
t({ phrase: 'vote', locale: interaction.user.locale }),
)
.setDescription(t({ phrase: 'vote.description', locale }))
.setFooter({ text: t({ phrase: 'vote.footer', locale }), iconURL: 'https://i.imgur.com/NKKmav5.gif' })
.setColor(colors.interchatBlue);

const button = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setStyle(ButtonStyle.Link)
.setLabel('Vote!')
.setEmoji('🗳️')
.setLabel('Vote')
.setEmoji(emojis.ghost_heart)
.setURL('https://top.gg/bot/769921109209907241/vote'),
);

Expand Down
1 change: 1 addition & 0 deletions src/utils/JSON/emojis.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"crystal": "<:crystal:1175819837281403040>",
"arrow": "<:arrow:1186172756031717487>",
"divider": "<:divider:1077200517379403816>",
"ghost_heart": "<:ghostheart:1155729003676700704>",

"star": "<:ic_star:1195641776271265852>",
"star_empty": "<:ic_star_tr:1195641648395341824>",
Expand Down
10 changes: 5 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"useUnknownInCatchVariables": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*", "src/**/*.json",],
"exclude": ["node_modules"],
"include": ["src/**/*", "src/**/*.json"],
"exclude": ["node_modules"]
}

0 comments on commit 2f7fc71

Please sign in to comment.