proper formatting and linting YAY, change cheer constructor to take object

This commit is contained in:
2025-11-24 17:05:18 +01:00
parent 253775a66e
commit af946e59b8
123 changed files with 4890 additions and 3383 deletions

View File

@@ -1,112 +1,123 @@
import { EventSubChannelRedemptionAddEvent } from "@twurple/eventsub-base";
import User from "user";
import type { EventSubChannelRedemptionAddEvent } from "@twurple/eventsub-base";
import type User from "user";
export type pointRedeemOptions = {
name: string;
title: string;
prompt?: string;
cost: number;
color?: string;
sfxredeem?: boolean;
input?: boolean;
execution: (message: EventSubChannelRedemptionAddEvent, sender: User) => Promise<void>;
name: string;
title: string;
prompt?: string;
cost: number;
color?: string;
sfxredeem?: boolean;
input?: boolean;
execution: (
message: EventSubChannelRedemptionAddEvent,
sender: User,
) => Promise<void>;
};
/** The Command class represents a command */
export default class PointRedeem {
public readonly name: string;
public readonly title: string;
public readonly prompt?: string;
public readonly cost: number;
public readonly color?: string;
public readonly sfxredeem?: boolean;
public readonly input?: boolean;
public readonly execute: (message: EventSubChannelRedemptionAddEvent, sender: User) => Promise<void>;
constructor(options: pointRedeemOptions) {
this.name = options.name.toLowerCase();
this.title = options.title;
this.prompt = options.prompt;
this.cost = options.cost;
this.color = options.color;
this.execute = options.execution;
this.sfxredeem = options.sfxredeem;
this.input = options.input;
};
};
public readonly name: string;
public readonly title: string;
public readonly prompt?: string;
public readonly cost: number;
public readonly color?: string;
public readonly sfxredeem?: boolean;
public readonly input?: boolean;
public readonly execute: (
message: EventSubChannelRedemptionAddEvent,
sender: User,
) => Promise<void>;
constructor(options: pointRedeemOptions) {
this.name = options.name.toLowerCase();
this.title = options.title;
this.prompt = options.prompt;
this.cost = options.cost;
this.color = options.color;
this.execute = options.execution;
this.sfxredeem = options.sfxredeem;
this.input = options.input;
}
}
import { readdir } from 'node:fs/promises';
import { readdir } from "node:fs/promises";
/** A map of all (including inactive) redeems mapped to names */
const namedRedeems = new Map<string, PointRedeem>;
const namedRedeems = new Map<string, PointRedeem>();
const sfxRedeems = new Map<string, PointRedeem>;
const sfxRedeems = new Map<string, PointRedeem>();
const files = await readdir(import.meta.dir);
for (const file of files) {
if (!file.endsWith('.ts')) continue;
if (file === import.meta.file) continue;
const redeem: PointRedeem = await import(import.meta.dir + '/' + file.slice(0, -3)).then(a => a.default);
namedRedeems.set(redeem.name, redeem);
if (redeem.sfxredeem) sfxRedeems.set(redeem.name, redeem);
};
if (!file.endsWith(".ts")) continue;
if (file === import.meta.file) continue;
const redeem: PointRedeem = await import(
`${import.meta.dir}/${file.slice(0, -3)}`
).then((a) => a.default);
namedRedeems.set(redeem.name, redeem);
if (redeem.sfxredeem) sfxRedeems.set(redeem.name, redeem);
}
export { namedRedeems, sfxRedeems };
const activeRedeems = new Map<string, PointRedeem>;
const activeRedeems = new Map<string, PointRedeem>();
/** Map of redeemname to twitch redeem ID */
const idMap = new Map<string, string>;
const idMap = new Map<string, string>();
import { streamerId } from "main";
import logger from "lib/logger";
import { api } from "index";
import logger from "lib/logger";
import { streamerId } from "main";
const currentRedeems = new Map<string, string>;
await api.channelPoints.getCustomRewards(streamerId).then(a => a.map(b => currentRedeems.set(b.title, b.id)));
const currentRedeems = new Map<string, string>();
await api.channelPoints
.getCustomRewards(streamerId)
.then((a) => a.map((b) => currentRedeems.set(b.title, b.id)));
for (const [_, redeem] of Array.from(namedRedeems)) {
const selection = currentRedeems.get(redeem.title);
if (selection) {
currentRedeems.delete(redeem.title);
idMap.set(redeem.name, selection);
activeRedeems.set(selection, redeem);
} else {
if (process.env.NODE_ENV !== 'production') continue; // If created with dev-app we won't be able to change it with prod app
const creation = await api.channelPoints.createCustomReward(streamerId, {
title: redeem.title,
prompt: redeem.prompt,
cost: redeem.cost,
backgroundColor: redeem.color,
userInputRequired: redeem.input
});
logger.ok(`Created custom point redeem ${redeem.title}`);
idMap.set(redeem.name, creation.id);
activeRedeems.set(creation.id, redeem);
};
};
const selection = currentRedeems.get(redeem.title);
if (selection) {
currentRedeems.delete(redeem.title);
idMap.set(redeem.name, selection);
activeRedeems.set(selection, redeem);
} else {
if (process.env.NODE_ENV !== "production") continue; // If created with dev-app we won't be able to change it with prod app
const creation = await api.channelPoints.createCustomReward(streamerId, {
title: redeem.title,
prompt: redeem.prompt,
cost: redeem.cost,
backgroundColor: redeem.color,
userInputRequired: redeem.input,
});
logger.ok(`Created custom point redeem ${redeem.title}`);
idMap.set(redeem.name, creation.id);
activeRedeems.set(creation.id, redeem);
}
}
Array.from(currentRedeems).map(async ([title, redeem]) => {
if (process.env.NODE_ENV !== 'production') return;
await api.channelPoints.deleteCustomReward(streamerId, redeem); logger.ok(`Deleted custom point redeem ${title}`);
if (process.env.NODE_ENV !== "production") return;
await api.channelPoints.deleteCustomReward(streamerId, redeem);
logger.ok(`Deleted custom point redeem ${title}`);
});
logger.ok("Successfully synced all custom point redeems");
export async function enableRedeem(redeem: PointRedeem, id: string) {
if (process.env.NODE_ENV !== 'production') return;
await api.channelPoints.updateCustomReward(streamerId, id, {
isEnabled: true
});
activeRedeems.set(id, redeem);
logger.ok(`Enabled the ${redeem.name} point redeem`);
};
if (process.env.NODE_ENV !== "production") return;
await api.channelPoints.updateCustomReward(streamerId, id, {
isEnabled: true,
});
activeRedeems.set(id, redeem);
logger.ok(`Enabled the ${redeem.name} point redeem`);
}
export async function disableRedeem(redeem: PointRedeem, id: string) {
if (process.env.NODE_ENV !== 'production') return;
await api.channelPoints.updateCustomReward(streamerId, id, {
isEnabled: false
});
activeRedeems.delete(id);
logger.ok(`Disabled the ${redeem.name} point redeem`);
};
if (process.env.NODE_ENV !== "production") return;
await api.channelPoints.updateCustomReward(streamerId, id, {
isEnabled: false,
});
activeRedeems.delete(id);
logger.ok(`Disabled the ${redeem.name} point redeem`);
}
export { activeRedeems, idMap };
export { activeRedeems, idMap };

View File

@@ -1,16 +1,18 @@
import { sendMessage } from "lib/commandUtils";
import PointRedeem from "pointRedeems";
import { getUserRecord } from "db/dbUser";
import { changeBalance } from "lib/changeBalance";
import PointRedeem from "pointRedeems";
import { sendMessage } from "lib/commandUtils";
export default new PointRedeem({
name: "qbucksredeem",
title: "FREE MONEY",
prompt: "GET 100 QBUCKS!",
color: '#00FF00',
cost: 1000,
execution: async (_msg, user) => {
await changeBalance(user, await getUserRecord(user), 100);
await sendMessage(`${user.displayName} got 100 qbucks for their point redeem`);
}
})
name: "qbucksredeem",
title: "FREE MONEY",
prompt: "GET 100 QBUCKS!",
color: "#00FF00",
cost: 1000,
execution: async (_msg, user) => {
await changeBalance(user, await getUserRecord(user), 100);
await sendMessage(
`${user.displayName} got 100 qbucks for their point redeem`,
);
},
});

View File

@@ -2,15 +2,16 @@ import PointRedeem from "pointRedeems";
import { playAlert } from "web/alerts/serverFunctions";
export default new PointRedeem({
name: "sfxEddieScream",
title: "Eddie scream",
cost: 100,
color: "#A020F0",
prompt: "Eddie screaming",
sfxredeem: true,
execution: async msg => await playAlert({
name: 'sound',
user: msg.userDisplayName,
sound: 'eddiescream'
})
name: "sfxEddieScream",
title: "Eddie scream",
cost: 100,
color: "#A020F0",
prompt: "Eddie screaming",
sfxredeem: true,
execution: async (msg) =>
await playAlert({
name: "sound",
user: msg.userDisplayName,
sound: "eddiescream",
}),
});

View File

@@ -2,15 +2,16 @@ import PointRedeem from "pointRedeems";
import { playAlert } from "web/alerts/serverFunctions";
export default new PointRedeem({
name: "sfxMrockMadhouse",
title: "Welcome to the Madhouse",
cost: 100,
color: "#A020F0",
prompt: "mrockstar20 saying 'Welcome to the Madhouse'",
sfxredeem: true,
execution: async msg => await playAlert({
name: 'sound',
user: msg.userDisplayName,
sound: 'mrockmadhouse'
})
name: "sfxMrockMadhouse",
title: "Welcome to the Madhouse",
cost: 100,
color: "#A020F0",
prompt: "mrockstar20 saying 'Welcome to the Madhouse'",
sfxredeem: true,
execution: async (msg) =>
await playAlert({
name: "sound",
user: msg.userDisplayName,
sound: "mrockmadhouse",
}),
});

View File

@@ -2,15 +2,16 @@ import PointRedeem from "pointRedeems";
import { playAlert } from "web/alerts/serverFunctions";
export default new PointRedeem({
name: "sfxRipBozo",
title: "RIP BOZO",
cost: 500,
color: "#A020F0",
prompt: "Coffeezilla calls me a conman",
sfxredeem: true,
execution: async msg => await playAlert({
name: 'sound',
user: msg.userDisplayName,
sound: 'ripbozo'
})
name: "sfxRipBozo",
title: "RIP BOZO",
cost: 500,
color: "#A020F0",
prompt: "Coffeezilla calls me a conman",
sfxredeem: true,
execution: async (msg) =>
await playAlert({
name: "sound",
user: msg.userDisplayName,
sound: "ripbozo",
}),
});