mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 00:51:37 +01:00
minor fixes, add superloot cheer
This commit is contained in:
@@ -19,7 +19,7 @@ export default new Cheer('execute', 666, async (msg, user) => {
|
||||
|
||||
const result = await timeout(target, `You got executed by ${user.displayName}!`, 60 * 30);
|
||||
if (result.status) await Promise.all([
|
||||
sendMessage(`${target.displayName} RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO`),
|
||||
sendMessage(`KEKPOINT KEKPOINT KEKPOINT ${target.displayName.toUpperCase()} RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO`),
|
||||
createTimeoutRecord(user, target, ITEMNAME),
|
||||
createCheerEventRecord(user, ITEMNAME),
|
||||
playAlert({
|
||||
|
||||
68
src/cheers/superloot.ts
Normal file
68
src/cheers/superloot.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { Cheer } from "cheers";
|
||||
import { sendMessage } from "commands";
|
||||
import { getUserRecord, updateUserRecord } from "db/dbUser";
|
||||
import itemMap, { type inventory, type items } from "items";
|
||||
import { createGetLootRecord } from "db/dbGetLoot";
|
||||
import { timeout } from "lib/timeout";
|
||||
import { redis } from "bun";
|
||||
|
||||
export default new Cheer('superloot', 150, async (msg, user) => {
|
||||
if (!await redis.exists('streamIsLive')) { await sendMessage(`No loot while stream is offline`, msg.messageId); return; };
|
||||
if (await user.itemLock()) { await sendMessage(`Cannot get loot (itemlock)`, msg.messageId); return; };
|
||||
await user.setLock();
|
||||
const userData = await getUserRecord(user);
|
||||
|
||||
await sendMessage("HOLD");
|
||||
await new Promise(res => setTimeout(res, 1000 * 5));
|
||||
|
||||
if (Math.random() > 0.5) {
|
||||
await Promise.all([
|
||||
sendMessage(`SUPERLOOT FAILED!!! KEKPOINT KEKPOINT KEKPOINT ${msg.chatterDisplayName.toUpperCase()} SEE YOU IN 5 MINUTES!!!`),
|
||||
timeout(user, `RIP BOZO! NO SUPERLOOT FOR YOU`, 60 * 5),
|
||||
user.clearLock()
|
||||
]);
|
||||
return;
|
||||
};
|
||||
|
||||
const gainedqbucks = Math.floor(Math.random() * 250) + 150; // range from 150 to 400
|
||||
userData.balance += gainedqbucks;
|
||||
|
||||
const itemDiff: inventory = {
|
||||
grenade: 0,
|
||||
blaster: 0,
|
||||
tnt: 0,
|
||||
silverbullet: 0
|
||||
};
|
||||
|
||||
for (let i = 0; i < 15; i++) {
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.grenade! += 1; // 1 in 5
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.blaster! += 1; // 1 in 5
|
||||
if (Math.floor(Math.random() * 50) === 0) itemDiff.tnt! += 1; // 1 in 50
|
||||
if (Math.floor(Math.random() * 250) === 0) itemDiff.silverbullet! += 1; // 1 in 250
|
||||
};
|
||||
|
||||
for (const [item, amount] of Object.entries(itemDiff) as [items, number][]) {
|
||||
if (userData.inventory[item]) userData.inventory[item] += amount;
|
||||
else userData.inventory[item] = amount;
|
||||
};
|
||||
|
||||
const itemstrings: string[] = [`${gainedqbucks} qbucks`];
|
||||
|
||||
for (const [item, amount] of Object.entries(itemDiff)) {
|
||||
if (amount === 0) continue;
|
||||
const selection = itemMap.get(item);
|
||||
if (!selection) continue;
|
||||
itemstrings.push(`${amount} ${selection.prettyName + (amount === 1 ? '' : selection.plural)}`);
|
||||
};
|
||||
|
||||
const last = itemstrings.pop();
|
||||
const itemstring = itemstrings.length === 0 ? last : itemstrings.join(', ') + " and " + last;
|
||||
const message = `You got ${itemstring}`;
|
||||
|
||||
await Promise.all([
|
||||
updateUserRecord(user, userData),
|
||||
sendMessage(message, msg.messageId),
|
||||
createGetLootRecord(user, gainedqbucks, itemDiff, 'superloot'),
|
||||
user.clearLock()
|
||||
]);
|
||||
}, true);
|
||||
@@ -35,7 +35,7 @@ export default new Command({
|
||||
await changeBalance(user, userRecord, -amount)
|
||||
]);
|
||||
|
||||
if (!data.includes(false)) {
|
||||
if (data[0] !== false && data[1] !== false) {
|
||||
const { balance: newamount } = data[0];
|
||||
await sendMessage(`${user.displayName} gave ${amount} qweribuck${amount === 1 ? '' : 's'} to ${target.displayName}. They now have ${newamount} qweribuck${newamount === 1 ? '' : 's'}`, msg.messageId);
|
||||
} else {
|
||||
|
||||
@@ -56,7 +56,7 @@ export default new Command({
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.grenade! += 1; // 1 in 5
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.blaster! += 1; // 1 in 5
|
||||
if (Math.floor(Math.random() * 25) === 0) itemDiff.tnt! += 1; // 1 in 25
|
||||
if (Math.floor(Math.random() * 50) === 0) itemDiff.tnt! += 1; // 1 in 50
|
||||
if (Math.floor(Math.random() * 250) === 0) itemDiff.silverbullet! += 1; // 1 in 250
|
||||
};
|
||||
|
||||
@@ -81,7 +81,7 @@ export default new Command({
|
||||
await Promise.all([
|
||||
updateUserRecord(user, userData),
|
||||
sendMessage(message, msg.messageId),
|
||||
createGetLootRecord(user, gainedqbucks, itemDiff),
|
||||
createGetLootRecord(user, gainedqbucks, itemDiff, 'getloot'),
|
||||
user.clearLock()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import db from "db/connection";
|
||||
import { getLoots } from "db/schema";
|
||||
import { getLoots, type lootTriggers } from "db/schema";
|
||||
import type { inventory } from "items";
|
||||
import type User from "user";
|
||||
|
||||
export async function createGetLootRecord(user: User, qbucks: number, inventory: inventory) {
|
||||
export async function createGetLootRecord(user: User, qbucks: number, inventory: inventory, trigger: lootTriggers) {
|
||||
await db.insert(getLoots).values({
|
||||
user: parseInt(user.id),
|
||||
qbucks: qbucks,
|
||||
items: inventory
|
||||
items: inventory,
|
||||
trigger
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import db from "db/connection";
|
||||
import { timeouts, users } from "db/schema";
|
||||
import { itemarray, type inventory } from "items";
|
||||
import type User from "user";
|
||||
import { count, desc, eq, inArray, sql, ne, between, and, SQL } from "drizzle-orm";
|
||||
import { count, desc, eq, inArray, sql, ne, between, and, SQL, type InferInsertModel, type InferSelectModel } from "drizzle-orm";
|
||||
|
||||
/** Use this function to both ensure existance and to retreive data */
|
||||
export async function getUserRecord(user: User) {
|
||||
@@ -32,11 +32,9 @@ async function createUserRecord(user: User) {
|
||||
});
|
||||
};
|
||||
|
||||
export type balanceUpdate = { balance: number; };
|
||||
export type inventoryUpdate = { inventory: inventory; };
|
||||
type updateUser = balanceUpdate | inventoryUpdate;
|
||||
export type UserRecord = InferSelectModel<typeof users>;
|
||||
|
||||
export async function updateUserRecord(user: User, newData: updateUser) {
|
||||
export async function updateUserRecord(user: User, newData: UserRecord) {
|
||||
await db.update(users).set(newData).where(eq(users.id, parseInt(user.id)));
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -107,11 +107,14 @@ export const anivTimeoutsRelations = relations(anivTimeouts, ({ one }) => ({
|
||||
})
|
||||
}));
|
||||
|
||||
export type lootTriggers = "getloot" | "superloot";
|
||||
|
||||
export const getLoots = pgTable('getLoots', {
|
||||
id: uuid().defaultRandom().primaryKey(),
|
||||
user: integer().notNull().references(() => users.id),
|
||||
qbucks: integer().notNull(),
|
||||
items: jsonb().$type<inventory>().notNull(),
|
||||
trigger: varchar().$type<lootTriggers>().notNull(),
|
||||
created: timestamp().defaultNow().notNull()
|
||||
});
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export class Item {
|
||||
};
|
||||
|
||||
import { readdir } from 'node:fs/promises';
|
||||
import { updateUserRecord, type inventoryUpdate } from "db/dbUser";
|
||||
import { updateUserRecord, type UserRecord } from "db/dbUser";
|
||||
const itemAliasMap = new Map<string, Item>;
|
||||
const itemObjectArray: Item[] = []
|
||||
const specialAliasItems = new Map<string, Item>;
|
||||
@@ -72,7 +72,7 @@ export type inventory = {
|
||||
[key in items]?: number;
|
||||
};
|
||||
|
||||
export async function changeItemCount(user: User, userRecord: inventoryUpdate, itemname: items, amount = -1): Promise<false | inventoryUpdate> {
|
||||
export async function changeItemCount(user: User, userRecord: UserRecord, itemname: items, amount = -1): Promise<false | UserRecord> {
|
||||
userRecord.inventory[itemname] = userRecord.inventory[itemname]! += amount;
|
||||
if (userRecord.inventory[itemname] < 0) return false;
|
||||
await updateUserRecord(user, userRecord);
|
||||
|
||||
@@ -33,7 +33,7 @@ export default new Item({
|
||||
|
||||
const result = await timeout(target, `You got blasted by ${user.displayName}!`, 60 * 30);
|
||||
if (result.status) await Promise.all([
|
||||
sendMessage(`${target.displayName} RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO`),
|
||||
sendMessage(`KEKPOINT KEKPOINT KEKPOINT ${target.displayName.toUpperCase()} RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO`),
|
||||
changeItemCount(user, userObj, ITEMNAME),
|
||||
createTimeoutRecord(user, target, ITEMNAME),
|
||||
createUsedItemRecord(user, ITEMNAME),
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { updateUserRecord } from "db/dbUser";
|
||||
import { type userRecord } from "db/connection";
|
||||
import { updateUserRecord, type UserRecord } from "db/dbUser";
|
||||
import User from "user";
|
||||
|
||||
export async function changeBalance(user: User, userRecord: userRecord, amount: number): Promise<false | userRecord> {
|
||||
export async function changeBalance(user: User, userRecord: UserRecord, amount: number): Promise<false | UserRecord> {
|
||||
userRecord.balance = userRecord.balance += amount;
|
||||
if (userRecord.balance < 0) return false;
|
||||
await updateUserRecord(user, userRecord);
|
||||
|
||||
@@ -14,4 +14,4 @@ export function buildTimeString(time1: number, time2: number): string {
|
||||
};
|
||||
const last = stringarray.pop();
|
||||
return stringarray.length === 0 ? last! : stringarray.join(', ') + " and " + last;
|
||||
};
|
||||
};
|
||||
@@ -17,7 +17,7 @@ export function parseCheerArgs(input: string) {
|
||||
const nice = input.toLowerCase().trim();
|
||||
|
||||
// This is for the test command. Remove the command prefix, the command, the whitespace after and the amount of fake bits
|
||||
if (nice.startsWith(commandPrefix + 'testcheer')) return nice.slice(commandPrefix.length + 'testcheer'.length + 1).replaceAll(/\W/g, '').split(' ').slice(1);
|
||||
if (nice.startsWith(commandPrefix + 'testcheer')) return nice.slice(commandPrefix.length + 'testcheer'.length + 1).replace(/[^\x00-\x7F]/g, '').split(' ').slice(1);
|
||||
|
||||
// This is for actual cheers. Remove all 'cheerx' parts of the message
|
||||
return nice.split(' ').filter(a => !/cheer[0-9]+/i.test(a));
|
||||
|
||||
Reference in New Issue
Block a user