mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 05:31:38 +01:00
auth softlock fixes, added shortcut to enable/disable redeem for sfx
This commit is contained in:
@@ -96,6 +96,7 @@ Redeems will be created automatically when the bot starts.
|
||||
Redeems or Pointredeems are events/commands triggered when a chatter uses their channel points.
|
||||
Redeems can be enabled and disabled by moderators using the [`enableredeem` and `disableredeem` commands](#administrative-commands).
|
||||
Note: The commands mentioned above require the internal name. For example, to disable the free money redeem, you do `disableredeem qbucksredeem` and not `disableredeem FREE MONEY`.
|
||||
The enable and disable redeem commands have a way to enable/disable all sound alert redeems at one by specifying the redeem as `sfx` or `sound`.
|
||||
|
||||
When running the development database and twitch api application, the redeems will not get created. This is because twitch only allows editing or deleting rewards when the same application created the reward. (fucking stupid)
|
||||
|
||||
|
||||
@@ -65,7 +65,13 @@ export async function createAuthProvider(user: string, intents: string[], stream
|
||||
clientId,
|
||||
clientSecret
|
||||
});
|
||||
try {
|
||||
await authData.addUserForToken(token, intents);
|
||||
} catch (err) {
|
||||
logger.err(`Failed to setup user auth. Please restart the bot and re-authenticate.`);
|
||||
await deleteAuthRecord(user);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
authData.onRefresh(async (user, token) => {
|
||||
logger.ok(`Successfully refreshed auth for user ${user}`);
|
||||
@@ -81,6 +87,7 @@ export async function createAuthProvider(user: string, intents: string[], stream
|
||||
} catch (err) {
|
||||
logger.err(`Failed to refresh user ${user}. Please restart the bot and re-authenticate it. Make sure the user that auths the bot and the user that's defined in .env are the same.`);
|
||||
await deleteAuthRecord(user);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
return authData;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { disableRedeem, idMap, namedRedeems } from "pointRedeems";
|
||||
import { disableRedeem, idMap, namedRedeems, sfxRedeems } from "pointRedeems";
|
||||
import logger from "lib/logger";
|
||||
|
||||
export default new Command({
|
||||
name: 'disableRedeem',
|
||||
@@ -10,6 +11,16 @@ export default new Command({
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage("Please specify a point redemption to disable", msg.messageId); return; };
|
||||
if (args[0] === 'sfx' || args[0] === 'sound') {
|
||||
sfxRedeems.forEach(async redeem => {
|
||||
const id = idMap.get(redeem.name);
|
||||
if (!id) { await sendMessage(`Failed to find the ID for redeem ${redeem.name}`, msg.messageId); logger.err(`Failed to find the ID for ${redeem.name} while enabling`); return; };
|
||||
await disableRedeem(redeem, id);
|
||||
});
|
||||
await sendMessage(`Disabled all sound (sfx) channel point redemptions`, msg.messageId);
|
||||
return;
|
||||
};
|
||||
|
||||
const selection = namedRedeems.get(args[0]);
|
||||
if (!selection) { await sendMessage(`Redeem ${args[0]} doesn't exist. The internal names for redeems are here: https://github.com/qwerinope/qweribot#point-redeems`, msg.messageId); return; };
|
||||
const id = idMap.get(selection.name);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import logger from "lib/logger";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { enableRedeem, idMap, namedRedeems } from "pointRedeems";
|
||||
import { enableRedeem, idMap, namedRedeems, sfxRedeems } from "pointRedeems";
|
||||
|
||||
export default new Command({
|
||||
name: 'enableRedeem',
|
||||
@@ -10,6 +11,15 @@ export default new Command({
|
||||
execution: async msg => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage("Please specify a point redemption to enable", msg.messageId); return; };
|
||||
if (args[0] === 'sfx' || args[0] === 'sound') {
|
||||
sfxRedeems.forEach(async redeem => {
|
||||
const id = idMap.get(redeem.name);
|
||||
if (!id) { await sendMessage(`Failed to find the ID for redeem ${redeem.name}`, msg.messageId); logger.err(`Failed to find the ID for ${redeem.name} while enabling`); return; };
|
||||
await enableRedeem(redeem, id);
|
||||
});
|
||||
await sendMessage(`Enabled all sound (sfx) channel point redemptions`, msg.messageId);
|
||||
return;
|
||||
};
|
||||
const selection = namedRedeems.get(args[0]);
|
||||
if (!selection) { await sendMessage(`Redeem ${args[0]} doesn't exist. The internal names for redeems are here: https://github.com/qwerinope/qweribot#point-redeems`, msg.messageId); return; };
|
||||
const id = idMap.get(selection.name);
|
||||
|
||||
@@ -7,6 +7,7 @@ export type pointRedeemOptions = {
|
||||
prompt?: string;
|
||||
cost: number;
|
||||
color?: string;
|
||||
sfxredeem?: boolean;
|
||||
execution: (message: EventSubChannelRedemptionAddEvent, sender: User) => Promise<void>;
|
||||
};
|
||||
|
||||
@@ -17,6 +18,7 @@ export default class PointRedeem {
|
||||
public readonly prompt?: string;
|
||||
public readonly cost: number;
|
||||
public readonly color?: string;
|
||||
public readonly sfxredeem?: boolean;
|
||||
public readonly execute: (message: EventSubChannelRedemptionAddEvent, sender: User) => Promise<void>;
|
||||
constructor(options: pointRedeemOptions) {
|
||||
this.name = options.name.toLowerCase();
|
||||
@@ -25,6 +27,7 @@ export default class PointRedeem {
|
||||
this.cost = options.cost;
|
||||
this.color = options.color;
|
||||
this.execute = options.execution;
|
||||
this.sfxredeem = options.sfxredeem;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -33,15 +36,18 @@ import { readdir } from 'node:fs/promises';
|
||||
/** A map of all (including inactive) redeems mapped to names */
|
||||
const namedRedeems = 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);
|
||||
};
|
||||
|
||||
export { namedRedeems };
|
||||
export { namedRedeems, sfxRedeems };
|
||||
|
||||
const activeRedeems = new Map<string, PointRedeem>;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ export default new PointRedeem({
|
||||
cost: 100,
|
||||
color: "#A020F0",
|
||||
prompt: "Eddie screaming",
|
||||
sfxredeem: true,
|
||||
execution: async msg => await playAlert({
|
||||
name: 'sound',
|
||||
user: msg.userDisplayName,
|
||||
|
||||
@@ -7,6 +7,7 @@ export default new PointRedeem({
|
||||
cost: 100,
|
||||
color: "#A020F0",
|
||||
prompt: "mrockstar20 saying 'Welcome to the Madhouse'",
|
||||
sfxredeem: true,
|
||||
execution: async msg => await playAlert({
|
||||
name: 'sound',
|
||||
user: msg.userDisplayName,
|
||||
|
||||
@@ -7,6 +7,7 @@ export default new PointRedeem({
|
||||
cost: 500,
|
||||
color: "#A020F0",
|
||||
prompt: "Coffeezilla calls me a conman",
|
||||
sfxredeem: true,
|
||||
execution: async msg => await playAlert({
|
||||
name: 'sound',
|
||||
user: msg.userDisplayName,
|
||||
|
||||
Reference in New Issue
Block a user