Skip to content

Commit

Permalink
Debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cafeed28 committed Jun 1, 2023
1 parent 53bf02c commit 745688f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export function Settings() {
<SwitchItem {...util.useSetting(config, "streamQualityEnable")} hideBorder>
Spoof stream quality (Use at your own risk! May lead to account ban)
</SwitchItem>
<SwitchItem {...util.useSetting(config, "debugMode")} hideBorder>
Enable verbose logging in console
</SwitchItem>
</Category>
</div>
);
Expand Down
17 changes: 16 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injector } from "replugged";

import { config, ready, userChanged, userInit } from "./misc";
import { config, logger, ready, userChanged, userInit } from "./misc";

import {
addStickerPreview,
Expand All @@ -21,6 +21,12 @@ import { spoofSticker } from "./sticker";
const injector = new Injector();

export async function start(): Promise<void> {
if (config.get("debugMode")) {
logger.log("stickerInfo:", stickerInfo);
logger.log("stickerSendability:", stickerSendability);
logger.log("stickerPreview:", stickerPreview);
}

// using premiumType from common.users.getCurrentUser will broke with plugins like No Nitro Upsell
await userInit();

Expand All @@ -44,8 +50,17 @@ export async function start(): Promise<void> {
injector.instead(stickerSendability, isSendableSticker, () => true);

injector.instead(stickerPreview, addStickerPreview, async ([channelId, sticker, d], orig) => {
const debugMode = config.get("debugMode");
if (debugMode) {
logger.log("ready:", ready);
}

if (ready) {
const spoofed = await spoofSticker(sticker);
if (debugMode) {
logger.log("orig:", orig);
}

if (!spoofed) {
orig(channelId, sticker, d);
}
Expand Down
6 changes: 5 additions & 1 deletion src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { common, settings } from "replugged";
import { Logger, common, settings } from "replugged";
import { userProfileFetch } from "./webpack";

import { User } from "discord-types/general";
Expand All @@ -11,8 +11,12 @@ export const config = await settings.init<Config>("com.cafeed28.NitroSpoof", {
stickerSize: 160,

streamQualityEnable: false,

debugMode: false,
});

export const logger = Logger.plugin("NitroSpoof");

export const HIDE_TEXT_SPOILERS = "||\u200b||".repeat(199);

export let userPremiumType: PremiumType;
Expand Down
8 changes: 7 additions & 1 deletion src/sticker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { common } from "replugged";
import { userPremiumType } from "./misc";
import { config, logger, userPremiumType } from "./misc";
import { PremiumType, Sticker, StickerFormat, StickerType } from "./types";
import { files } from "./webpack";
import { renderPng } from "./renderer";
Expand All @@ -21,6 +21,12 @@ function getUrl(sticker: Sticker): string {
}

function isStickerAvailable(sticker: Sticker): boolean {
if (config.get("debugMode")) {
logger.log("sticker:", sticker);
logger.log("userPremiumType:", userPremiumType);
logger.log("common.guilds.getGuildId:", common.guilds.getGuildId());
}

if (sticker.type == StickerType.STANDARD) return true;

// Emoji not available on Discord (e.g. GUILD_SUBSCRIPTION_UNAVAILABLE)
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type Config = {
stickerSize?: number;

streamQualityEnable?: boolean;

debugMode?: boolean;
};

export enum PremiumType {
Expand Down

0 comments on commit 745688f

Please sign in to comment.