mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
added item shop, nerf lootbox, fix bugs
This commit is contained in:
@@ -17,7 +17,7 @@ export default new Command({
|
||||
if (!args[1]) { await sendMessage('Please specify the amount qweribucks you want to give', msg.messageId); return; };
|
||||
const amount = parseInt(args[1]);
|
||||
if (isNaN(amount)) { await sendMessage(`'${args[1]}' is not a valid amount`); return; };
|
||||
if (await target.itemLock()) { await sendMessage('Cannot give qweribucks: item lock is set', msg.messageId); return; };
|
||||
if (await target.itemLock()) { await sendMessage('Cannot give qweribucks (itemlock)', msg.messageId); return; };
|
||||
await target.setLock();
|
||||
const data = await changeBalance(target, userRecord, amount);
|
||||
if (!data) {
|
||||
|
||||
@@ -20,7 +20,7 @@ export default new Command({
|
||||
if (!args[2]) { await sendMessage('Please specify the amount of the item you want to give', msg.messageId); return; };
|
||||
const amount = parseInt(args[2]);
|
||||
if (isNaN(amount)) { await sendMessage(`'${args[2]}' is not a valid amount`); return; };
|
||||
if (await target.itemLock()) { await sendMessage('Cannot give item: item lock is set', msg.messageId); return; };
|
||||
if (await target.itemLock()) { await sendMessage('Cannot give item (itemlock)', msg.messageId); return; };
|
||||
await target.setLock();
|
||||
const data = await changeItemCount(target, userRecord, item.name, amount);
|
||||
if (data) {
|
||||
|
||||
37
src/commands/buyitem.ts
Normal file
37
src/commands/buyitem.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import items from "items";
|
||||
import { getUserRecord, updateUserRecord } from "db/dbUser";
|
||||
|
||||
export default new Command({
|
||||
name: 'buyitem',
|
||||
aliases: ['buyitem', 'buy', 'purchase'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const args = parseCommandArgs(msg.messageText);
|
||||
if (!args[0]) { await sendMessage(`Specify the item you'd like to buy`, msg.messageId); return; };
|
||||
const selecteditem = items.get(args[0].toLowerCase());
|
||||
if (!selecteditem) { await sendMessage(`'${args[0]}' is not a valid item`, msg.messageId); return; };
|
||||
const amount = args[1] ? parseInt(args[1]) : 1;
|
||||
if (isNaN(amount) || amount < 1) { await sendMessage(`'${args[1]}' is not a valid amount to buy`, msg.messageId); return; };
|
||||
const totalcost = amount * selecteditem.price;
|
||||
|
||||
if (await user.itemLock()) { await sendMessage('Cannot buy item (itemlock)', msg.messageId); return; };
|
||||
await user.setLock();
|
||||
|
||||
const userRecord = await getUserRecord(user);
|
||||
if (userRecord.balance < totalcost) { await sendMessage(`You don't have enough qbucks to buy ${amount} ${selecteditem.prettyName}${amount === 1 ? '' : selecteditem.plural}! You have ${userRecord.balance}, need ${totalcost}`); await user.clearLock(); return; };
|
||||
|
||||
if (userRecord.inventory[selecteditem.name]) userRecord.inventory[selecteditem.name]! += amount
|
||||
else userRecord.inventory[selecteditem.name] = amount;
|
||||
|
||||
userRecord.balance -= totalcost;
|
||||
|
||||
await Promise.all([
|
||||
updateUserRecord(user, userRecord),
|
||||
sendMessage(`${user.displayName} bought ${amount} ${selecteditem.prettyName}${amount === 1 ? '' : selecteditem.plural} for ${totalcost} qbucks. They now have ${userRecord.inventory[selecteditem.name]} ${selecteditem.prettyName}${userRecord.inventory[selecteditem.name] === 1 ? '' : selecteditem.plural} and ${userRecord.balance} qbucks`, msg.messageId)
|
||||
]);
|
||||
|
||||
await user.clearLock();
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import type { userRecord } from "db/connection";
|
||||
import { getUserRecord } from "db/dbUser";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import { changeBalance } from "lib/changeBalance";
|
||||
@@ -24,7 +23,7 @@ export default new Command({
|
||||
const userRecord = await getUserRecord(user);
|
||||
if (userRecord.balance < amount) { await sendMessage(`You can't give qweribucks you don't have!`, msg.messageId); return; };
|
||||
|
||||
if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give qweribucks', msg.messageId); return; };
|
||||
if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give qweribucks (itemlock)', msg.messageId); return; };
|
||||
|
||||
await Promise.all([
|
||||
user.setLock(),
|
||||
@@ -37,7 +36,7 @@ export default new Command({
|
||||
]);
|
||||
|
||||
if (!data.includes(false)) {
|
||||
const { balance: newamount } = data[0] as userRecord;
|
||||
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 {
|
||||
// TODO: Rewrite this section
|
||||
|
||||
@@ -49,14 +49,13 @@ export default new Command({
|
||||
grenade: 0,
|
||||
blaster: 0,
|
||||
tnt: 0,
|
||||
silverbullet: 0
|
||||
};
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.grenade! += 1;
|
||||
if (Math.floor(Math.random() * 5) === 0) itemDiff.blaster! += 1;
|
||||
if (Math.floor(Math.random() * 25) === 0) itemDiff.tnt! += 1;
|
||||
if (Math.floor(Math.random() * 250) === 0) itemDiff.silverbullet! += 1;
|
||||
if (Math.floor(Math.random() * 1000) === 0) itemDiff.silverbullet! += 1;
|
||||
};
|
||||
|
||||
for (const [item, amount] of Object.entries(itemDiff) as [items, number][]) {
|
||||
|
||||
12
src/commands/getprices.ts
Normal file
12
src/commands/getprices.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import { itemObjectArray } from "items";
|
||||
|
||||
export default new Command({
|
||||
name: 'getprices',
|
||||
aliases: ['getprices', 'prices', 'shop'],
|
||||
usertype: 'chatter',
|
||||
execution: async msg => {
|
||||
const txt = itemObjectArray.toSorted((a, b) => a.price - b.price).map(item => `${item.prettyName}: ${item.price}`);
|
||||
await sendMessage(`Prices: ${txt.join(' | ')}`, msg.messageId);
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import type { userRecord } from "db/connection";
|
||||
import { getUserRecord } from "db/dbUser";
|
||||
import items, { changeItemCount } from "items";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
@@ -26,7 +25,7 @@ export default new Command({
|
||||
const userRecord = await getUserRecord(user);
|
||||
if (userRecord.inventory[item.name]! < amount) { await sendMessage(`You can't give items you don't have!`, msg.messageId); return; };
|
||||
|
||||
if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give item', msg.messageId); return; };
|
||||
if (await user.itemLock() || await target.itemLock()) { await sendMessage('Cannot give item (itemlock)', msg.messageId); return; };
|
||||
|
||||
await Promise.all([
|
||||
user.setLock(),
|
||||
@@ -38,14 +37,14 @@ export default new Command({
|
||||
await changeItemCount(user, userRecord, item.name, -amount)
|
||||
]);
|
||||
|
||||
if (!data.includes(false)) {
|
||||
const tempdata = data[0] as userRecord;
|
||||
if (data[0] !== false && data[1] !== false) {
|
||||
const tempdata = data[0];
|
||||
const newamount = tempdata.inventory[item.name]!;
|
||||
await sendMessage(`${user.displayName} gave ${amount} ${item.prettyName + (amount === 1 ? '' : item.plural)} to ${target.displayName}. They now have ${newamount} ${item.prettyName + (newamount === 1 ? '' : item.plural)}`, msg.messageId);
|
||||
} else {
|
||||
// TODO: Rewrite this section
|
||||
await sendMessage(`Failed to give ${target.displayName} ${amount} ${item.prettyName + (amount === 1 ? '' : item.plural)}`, msg.messageId);
|
||||
logger.warn(`WARNING: Item donation failed: target success: ${data[0] !== false}, donator success: ${data[1] !== false}`);
|
||||
logger.warn(`WARNING: Item donation failed: target success: ${data[0] !== false ? "yes" : "no"}, donator success: ${data[1] !== false ? "yes" : "no"}`);
|
||||
};
|
||||
await user.clearLock();
|
||||
await target.clearLock();
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import { Command, sendMessage } from "commands";
|
||||
import { getUserRecord } from "db/dbUser";
|
||||
import parseCommandArgs from "lib/parseCommandArgs";
|
||||
import User from "user";
|
||||
import { timeout } from "lib/timeout";
|
||||
import { changeBalance } from "lib/changeBalance";
|
||||
import { createTimeoutRecord } from "db/dbTimeouts";
|
||||
|
||||
export default new Command({
|
||||
name: 'timeout',
|
||||
aliases: ['timeout'],
|
||||
usertype: 'chatter',
|
||||
execution: async (msg, user) => {
|
||||
const userObj = await getUserRecord(user);
|
||||
if (userObj.balance < 100) { await sendMessage(`You don't have enough qweribucks (need 100, have ${userObj.balance})`, msg.messageId); return; };
|
||||
const messagequery = parseCommandArgs(msg.messageText);
|
||||
if (!messagequery[0]) { await sendMessage('Please specify a target'); return; };
|
||||
const target = await User.initUsername(messagequery[0].toLowerCase());
|
||||
if (!target) { await sendMessage(`${messagequery[0]} doesn't exist`); return; };
|
||||
await getUserRecord(target); // make sure the user record exist in the database
|
||||
|
||||
const result = await timeout(target, `You got BLASTED by ${user.displayName}`, 60);
|
||||
if (result.status) {
|
||||
await Promise.all([
|
||||
sendMessage(`GOTTEM ${target.displayName} got BLASTED by ${user.displayName} GOTTEM`),
|
||||
changeBalance(user, userObj, -100),
|
||||
createTimeoutRecord(user, target, 'blaster')
|
||||
]);
|
||||
} else {
|
||||
switch (result.reason) {
|
||||
case "banned":
|
||||
await sendMessage(`${target.displayName} is already timed out/banned`, msg.messageId);
|
||||
break;
|
||||
case "illegal":
|
||||
await Promise.all([
|
||||
sendMessage(`${user.displayName} Nou Nou Nou`),
|
||||
timeout(user, 'nah', 60)
|
||||
]);
|
||||
break;
|
||||
case "unknown":
|
||||
await sendMessage('Something went wrong...', msg.messageId);
|
||||
break;
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user