mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 11:06:59 +01:00
Compare commits
5 Commits
5b5886e3a1
...
784650b0dc
| Author | SHA1 | Date | |
|---|---|---|---|
| 784650b0dc | |||
| 6215d3ee80 | |||
| 9bba99dd53 | |||
| 2d43065a2a | |||
| 3bd2cb1038 |
@@ -12,8 +12,9 @@ COMMAND|FUNCTION|USER|ALIASES
|
|||||||
-|-|-|-
|
-|-|-|-
|
||||||
`!balance [target]`|List write the amount of money the user or the target user has.|anyone|`!bal, !qbucks, !qweribucks`
|
`!balance [target]`|List write the amount of money the user or the target user has.|anyone|`!bal, !qbucks, !qweribucks`
|
||||||
`!inventory [target]`|Show inventory contents of user or the target user.|anyone|`!inv`
|
`!inventory [target]`|Show inventory contents of user or the target user.|anyone|`!inv`
|
||||||
`!getloot`|Give user a lootbox. This command has a cooldown that can be changed in `lootbox.ts`. You can optionally require the user to subscribe.|anyone|`None`
|
`!getloot`|Give user a lootbox. This command has a cooldown that can be changed in `lootbox.ts`.|anyone|`None`
|
||||||
`!stats [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed.|anyone|`None`
|
`!stats [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed of the current month.|anyone|`None`
|
||||||
|
`!alltime [target]`|Show the stats of user or target user including users shot, TNT used and grenades lobbed of all time.|anyone|`None`
|
||||||
`!timeout {target}`|Give the target user a timeout of 60 seconds. This requires 100 qbucks.|anyone|`None`
|
`!timeout {target}`|Give the target user a timeout of 60 seconds. This requires 100 qbucks.|anyone|`None`
|
||||||
`!use {item}`|Use a specific item. The user needs the specific item in their inventory. For items please look at the table below|anyone|`None`
|
`!use {item}`|Use a specific item. The user needs the specific item in their inventory. For items please look at the table below|anyone|`None`
|
||||||
`!iteminfo {item}`|Gives a description of the requested item. Identical to [the item descriptions in this document](#items)|anyone|`!item`
|
`!iteminfo {item}`|Gives a description of the requested item. Identical to [the item descriptions in this document](#items)|anyone|`!item`
|
||||||
|
|||||||
@@ -14,6 +14,81 @@ migrate(app => {
|
|||||||
|
|
||||||
app.save(record)
|
app.save(record)
|
||||||
const data = [
|
const data = [
|
||||||
|
{
|
||||||
|
"id": "pbc_279239694",
|
||||||
|
"listRule": null,
|
||||||
|
"viewRule": null,
|
||||||
|
"createRule": null,
|
||||||
|
"updateRule": null,
|
||||||
|
"deleteRule": null,
|
||||||
|
"name": "itemuses",
|
||||||
|
"type": "base",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "[a-z0-9]{15}",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text3208210256",
|
||||||
|
"max": 15,
|
||||||
|
"min": 15,
|
||||||
|
"name": "id",
|
||||||
|
"pattern": "^[a-z0-9]+$",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": true,
|
||||||
|
"required": true,
|
||||||
|
"system": true,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autogeneratePattern": "",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "text1579384326",
|
||||||
|
"max": 0,
|
||||||
|
"min": 0,
|
||||||
|
"name": "name",
|
||||||
|
"pattern": "",
|
||||||
|
"presentable": false,
|
||||||
|
"primaryKey": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cascadeDelete": false,
|
||||||
|
"collectionId": "pbc_3754236674",
|
||||||
|
"hidden": false,
|
||||||
|
"id": "relation1542800728",
|
||||||
|
"maxSelect": 1,
|
||||||
|
"minSelect": 0,
|
||||||
|
"name": "field",
|
||||||
|
"presentable": false,
|
||||||
|
"required": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "relation"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate2990389176",
|
||||||
|
"name": "created",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": false,
|
||||||
|
"presentable": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "autodate"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hidden": false,
|
||||||
|
"id": "autodate3332085495",
|
||||||
|
"name": "updated",
|
||||||
|
"onCreate": true,
|
||||||
|
"onUpdate": true,
|
||||||
|
"presentable": false,
|
||||||
|
"system": false,
|
||||||
|
"type": "autodate"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"indexes": [],
|
||||||
|
"system": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "pbc_1170220047",
|
"id": "pbc_1170220047",
|
||||||
"listRule": "",
|
"listRule": "",
|
||||||
@@ -241,16 +316,6 @@ migrate(app => {
|
|||||||
"system": false,
|
"system": false,
|
||||||
"type": "json"
|
"type": "json"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"hidden": false,
|
|
||||||
"id": "json1357546519",
|
|
||||||
"maxSize": 0,
|
|
||||||
"name": "itemuses",
|
|
||||||
"presentable": false,
|
|
||||||
"required": false,
|
|
||||||
"system": false,
|
|
||||||
"type": "json"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"id": "number2901680126",
|
"id": "number2901680126",
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ function getTimeDifference(date1: number, date2: number) {
|
|||||||
return { days, hours, minutes, seconds };
|
return { days, hours, minutes, seconds };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default createBotCommand('getloot', async (_params, { reply, userId, broadcasterId }) => {
|
export default createBotCommand('getloot', async (_params, { reply, userId }) => {
|
||||||
const user = await api.users.getUserById(userId)
|
const user = await api.users.getUserById(userId)
|
||||||
// Remove the comment on the following line to only give lootboxes to subscribed users
|
|
||||||
//if (!user?.isSubscribedTo(broadcasterId)) { await reply('Subscribe to get loot :)'); return }
|
|
||||||
const data = await lootboxReady(user)
|
const data = await lootboxReady(user)
|
||||||
if (!data.result) {
|
if (!data.result) {
|
||||||
const { days, hours, minutes, seconds } = getTimeDifference(data.lastlootbox, Date.now() - COOLDOWN)
|
const { days, hours, minutes, seconds } = getTimeDifference(data.lastlootbox, Date.now() - COOLDOWN)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import timeout from "./timeout";
|
import timeout from "./timeout";
|
||||||
import inventory from "./inventory";
|
import inventory from "./inventory";
|
||||||
import stats from "./stats";
|
|
||||||
import qbucks from "./qbucks";
|
import qbucks from "./qbucks";
|
||||||
import getloot from "./getloot";
|
import getloot from "./getloot";
|
||||||
import modme from "./modme";
|
import modme from "./modme";
|
||||||
import use from "./use";
|
import use from "./use";
|
||||||
import iteminfo from "./iteminfo"
|
import iteminfo from "./iteminfo"
|
||||||
|
|
||||||
import aliases from './itemAliases'
|
import stats from "./stats"
|
||||||
import admin from './admin'
|
import aliases from "./itemAliases"
|
||||||
|
import admin from "./admin"
|
||||||
|
|
||||||
export default [timeout, inventory, stats, qbucks, getloot, modme, use, iteminfo, ...aliases, ...admin]
|
export default [timeout, inventory, qbucks, getloot, modme, use, iteminfo, ...aliases, ...admin, ...stats]
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default createBotCommand('inv', async (params, { userName, say }) => {
|
|||||||
messagedata.push(`${item.name + (item.amount === 1 ? '' : item.plural)}: ${item.amount}`)
|
messagedata.push(`${item.name + (item.amount === 1 ? '' : item.plural)}: ${item.amount}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messagedata.length === 0) {await say(`${data.me ? userName : params[0]} has no items mandoooYikes`); return}
|
if (messagedata.length === 0) {await say(`${data.me ? userName : params[0]} has no items!`); return}
|
||||||
|
|
||||||
await say(`
|
await say(`
|
||||||
inventory of ${data.me ? userName : params[0]}:
|
inventory of ${data.me ? userName : params[0]}:
|
||||||
|
|||||||
@@ -5,23 +5,23 @@ export default createBotCommand('iteminfo', async (params, { say }) => {
|
|||||||
let message = ''
|
let message = ''
|
||||||
switch (params[0].toLowerCase()) {
|
switch (params[0].toLowerCase()) {
|
||||||
case 'blaster':
|
case 'blaster':
|
||||||
message = "Item: blaster {target}, Function: Times the target user out for 60 seconds. Aliases: !blast, !blaster"
|
message = "Use: blaster {target}, Function: Times the target user out for 60 seconds. Aliases: !blast, !blaster"
|
||||||
break
|
break
|
||||||
case 'silver':
|
case 'silver':
|
||||||
case 'silverbullet':
|
case 'silverbullet':
|
||||||
message = "`Item: silverbullet {target}, Function: Times the target user out for 24 hours. Aliases: !execute, !silverbullet"
|
message = "Use: silverbullet {target}, Function: Times the target user out for 24 hours. Aliases: !execute, !silverbullet"
|
||||||
break
|
break
|
||||||
case 'grenade':
|
case 'grenade':
|
||||||
message = "Item: grenade, Function: Times a random chatter out for 60 seconds. Aliases: !grenade"
|
message = "Use: grenade, Function: Times a random chatter out for 60 seconds. Aliases: !grenade"
|
||||||
break
|
break
|
||||||
case 'tnt':
|
case 'tnt':
|
||||||
message = "Item: tnt, Function: Times out 1 to 10 chatters for 60 seconds. Aliases: !tnt"
|
message = "Use: tnt, Function: Times out 1 to 10 chatters for 60 seconds. Aliases: !tnt"
|
||||||
break
|
break
|
||||||
case 'lootbox':
|
case 'lootbox':
|
||||||
message = "Item: lootbox, Function: Gives the user some qbucks, and possibly some items. Aliases: !lootbox"
|
message = "Use: lootbox, Function: Gives the user some qbucks, and possibly some items. Aliases: !lootbox"
|
||||||
break
|
break
|
||||||
case 'clipboard':
|
case 'clipboard':
|
||||||
message = "Item: clipboard {message}, Function: Starts a two minute long poll with the user specified message. Aliases: !clipboard"
|
message = "Use: clipboard {message}, Function: Starts a two minute long poll with the user specified message. Aliases: !clipboard"
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
message = "Item not found"
|
message = "Item not found"
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ export default createBotCommand('balance', async (params, { userName, say }) =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await getBalance(user)
|
const data = await getBalance(user)
|
||||||
await say(`${user.name} has ${data.balance} qbucks ${data.balance === 0 ? 'mandoooYikes' : 'mandoooSmile'}`)
|
await say(`${user.name} has ${data.balance} qbucks`)
|
||||||
|
|
||||||
}, { aliases: ['qbucks', 'qweribucks', 'bal'] })
|
}, { aliases: ['qbucks', 'qweribucks', 'bal'] })
|
||||||
|
|||||||
@@ -3,7 +3,36 @@ import api from "../lib/api";
|
|||||||
import { getStats } from "../lib/userHelper";
|
import { getStats } from "../lib/userHelper";
|
||||||
import { HelixUser } from "@twurple/api";
|
import { HelixUser } from "@twurple/api";
|
||||||
|
|
||||||
export default createBotCommand('stats', async (params, { say, userName }) => {
|
const stats = createBotCommand('stats', async (params, { say, userName }) => {
|
||||||
|
let user: HelixUser | null
|
||||||
|
if (params.length !== 0) {
|
||||||
|
user = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
||||||
|
} else user = await api.users.getUserByName(userName)
|
||||||
|
if (!user) {
|
||||||
|
await say(`User ${params[0]} not found`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const monthdata = new Date().toISOString().slice(0, 7)
|
||||||
|
|
||||||
|
const data = params.length === 0 ? { me: true, stats: await getStats(user!, monthdata) } : { me: false, stats: await getStats(user!, monthdata) }
|
||||||
|
|
||||||
|
const KD = data.stats.shot.blaster / data.stats.hit.blaster
|
||||||
|
|
||||||
|
await say(
|
||||||
|
`
|
||||||
|
THIS MONTH: Stats of ${data.me ? userName : params[0]}:
|
||||||
|
Users blasted: ${data.stats.shot.blaster},
|
||||||
|
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(3)} K/D).
|
||||||
|
Grenades lobbed: ${data.stats.used.grenade}
|
||||||
|
TNTs lit: ${data.stats.used.tnt},
|
||||||
|
Silver bullets fired: ${data.stats.shot.silverbullet},
|
||||||
|
Silver bullets taken: ${data.stats.hit.silverbullet}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const alltime = createBotCommand('alltime', async (params, { say, userName }) => {
|
||||||
let user: HelixUser | null
|
let user: HelixUser | null
|
||||||
if (params.length !== 0) {
|
if (params.length !== 0) {
|
||||||
user = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
user = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
||||||
@@ -19,9 +48,9 @@ export default createBotCommand('stats', async (params, { say, userName }) => {
|
|||||||
|
|
||||||
await say(
|
await say(
|
||||||
`
|
`
|
||||||
Stats of ${data.me ? userName : params[0]}:
|
ALLTIME: Stats of ${data.me ? userName : params[0]}:
|
||||||
Users blasted: ${data.stats.shot.blaster},
|
Users blasted: ${data.stats.shot.blaster},
|
||||||
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD} K/D).
|
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(3)} K/D).
|
||||||
Grenades lobbed: ${data.stats.used.grenade}
|
Grenades lobbed: ${data.stats.used.grenade}
|
||||||
TNTs lit: ${data.stats.used.tnt},
|
TNTs lit: ${data.stats.used.tnt},
|
||||||
Silver bullets fired: ${data.stats.shot.silverbullet},
|
Silver bullets fired: ${data.stats.shot.silverbullet},
|
||||||
@@ -29,3 +58,5 @@ export default createBotCommand('stats', async (params, { say, userName }) => {
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default [stats, alltime]
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default createBotCommand('timeout', async (params, { say, broadcasterId,
|
|||||||
const target = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
const target = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
||||||
const status = await timeout(broadcasterId, target!, 60, `You got blasted by ${userName}`)
|
const status = await timeout(broadcasterId, target!, 60, `You got blasted by ${userName}`)
|
||||||
if (status.status) {
|
if (status.status) {
|
||||||
await say(`${params[0]} got blasted by ${userName}! mandoooGOTTEM ${userName} now has ${userbal.balance - 100} qbucks remaining`)
|
await say(`${params[0]} got blasted by ${userName}! ${userName} now has ${userbal.balance - 100} qbucks remaining`)
|
||||||
await changeBalance(attacker!, -100)
|
await changeBalance(attacker!, -100)
|
||||||
await addTimeoutToDB(attacker!, target!, 'blaster')
|
await addTimeoutToDB(attacker!, target!, 'blaster')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ export default createBotCommand('use', async (params, { say, broadcasterId, user
|
|||||||
await useClipboard(broadcasterId, user!, params.slice(1).join(' '), say)
|
await useClipboard(broadcasterId, user!, params.slice(1).join(' '), say)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
await say(`${params[0]} does not exist mandoooYikes`)
|
await say(`${params[0]} does not exist!`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { HelixUser } from "@twurple/api"
|
import { HelixUser } from "@twurple/api"
|
||||||
import { changeBalance, getInventory, updateInventory } from "../lib/userHelper"
|
import { addUsedItem, changeBalance, getInventory, inventory, updateInventory } from "../lib/userHelper"
|
||||||
import { timeout, addTimeoutToDB, vulnerableUsers } from "./timeoutHelper"
|
import { timeout, addTimeoutToDB, vulnerableUsers } from "./timeoutHelper"
|
||||||
import api, { broadcasterApi } from "./api"
|
import api, { broadcasterApi } from "./api"
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ interface itemChangeResult {
|
|||||||
result: boolean,
|
result: boolean,
|
||||||
reason: string
|
reason: string
|
||||||
count: number,
|
count: number,
|
||||||
|
inv?: inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changeItemCount(user: HelixUser, item: string, amount = -1): Promise<itemChangeResult> {
|
export async function changeItemCount(user: HelixUser, item: string, amount = -1): Promise<itemChangeResult> {
|
||||||
@@ -21,8 +22,10 @@ export async function changeItemCount(user: HelixUser, item: string, amount = -1
|
|||||||
Object.defineProperty(inv, item, {
|
Object.defineProperty(inv, item, {
|
||||||
value: newcount,
|
value: newcount,
|
||||||
})
|
})
|
||||||
await updateInventory(user, inv)
|
|
||||||
return { result: true, reason: '', count: inv[item] }
|
if (amount > 0) await updateInventory(user, inv)
|
||||||
|
|
||||||
|
return { result: true, reason: '', count: inv[item], inv }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function useBlaster(broadcasterId: string, attacker: HelixUser, targetname: string, say: (arg0: string) => Promise<void>) {
|
export async function useBlaster(broadcasterId: string, attacker: HelixUser, targetname: string, say: (arg0: string) => Promise<void>) {
|
||||||
@@ -30,12 +33,14 @@ export async function useBlaster(broadcasterId: string, attacker: HelixUser, tar
|
|||||||
|
|
||||||
const itemResult = await changeItemCount(attacker, 'blaster')
|
const itemResult = await changeItemCount(attacker, 'blaster')
|
||||||
|
|
||||||
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no blasters mandoooYikes'); return }
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no blasters!'); return }
|
||||||
|
|
||||||
const result = await timeout(broadcasterId, target!, 60, `You got blasted by ${attacker.name}`)
|
const result = await timeout(broadcasterId, target!, 60, `You got blasted by ${attacker.name}`)
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
await say(`${targetname} got blasted by ${attacker.name}! mandoooGOTTEM ${attacker.name} has ${itemResult.count} blaster${itemResult.count === 1 ? '' : 's'} remaining`)
|
await say(`${targetname} got blasted by ${attacker.name}! ${attacker.name} has ${itemResult.count} blaster${itemResult.count === 1 ? '' : 's'} remaining`)
|
||||||
await addTimeoutToDB(attacker, target!, 'blaster')
|
await addTimeoutToDB(attacker, target!, 'blaster')
|
||||||
|
await addUsedItem(attacker, 'blaster')
|
||||||
|
await updateInventory(attacker, itemResult.inv!)
|
||||||
} else {
|
} else {
|
||||||
switch (result.reason) {
|
switch (result.reason) {
|
||||||
case 'noexist':
|
case 'noexist':
|
||||||
@@ -56,12 +61,14 @@ export async function useSilverBullet(broadcasterId: string, attacker: HelixUser
|
|||||||
const target = await api.users.getUserByName(targetname)
|
const target = await api.users.getUserByName(targetname)
|
||||||
|
|
||||||
const itemResult = await changeItemCount(attacker, 'silverbullet')
|
const itemResult = await changeItemCount(attacker, 'silverbullet')
|
||||||
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no silver bullets mandoooYikes'); return }
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no silver bullets!'); return }
|
||||||
|
|
||||||
const result = await timeout(broadcasterId, target!, 60 * 60 * 24, `You got hit by a silver bullet fired by ${attacker.name}`)
|
const result = await timeout(broadcasterId, target!, 60 * 60 * 24, `You got hit by a silver bullet fired by ${attacker.name}`)
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
await say(`${target?.name} mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute mandoooSalute `)
|
await say(`${target?.name} got deleted.`)
|
||||||
await addTimeoutToDB(attacker, target!, 'silverbullet')
|
await addTimeoutToDB(attacker, target!, 'silverbullet')
|
||||||
|
await addUsedItem(attacker, 'silverbullet')
|
||||||
|
await updateInventory(attacker, itemResult.inv!)
|
||||||
} else {
|
} else {
|
||||||
switch (result.reason) {
|
switch (result.reason) {
|
||||||
case 'noexist':
|
case 'noexist':
|
||||||
@@ -82,25 +89,26 @@ export async function useGrenade(broadcasterId: string, attacker: HelixUser, say
|
|||||||
if (vulnerableUsers.length === 0) { await say('No chatters to blow up!'); return }
|
if (vulnerableUsers.length === 0) { await say('No chatters to blow up!'); return }
|
||||||
const itemResult = await changeItemCount(attacker, 'grenade')
|
const itemResult = await changeItemCount(attacker, 'grenade')
|
||||||
|
|
||||||
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no grenades mandoooYikes'); return }
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no grenades!'); return }
|
||||||
const target = await api.users.getUserById(vulnerableUsers[Math.floor(Math.random() * vulnerableUsers.length)])
|
const target = await api.users.getUserById(vulnerableUsers[Math.floor(Math.random() * vulnerableUsers.length)])
|
||||||
const result = await timeout(broadcasterId, target!, 60, `You got hit by ${attacker.name}'s grenade`)
|
const result = await timeout(broadcasterId, target!, 60, `You got hit by ${attacker.name}'s grenade`)
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
await say(`${target?.name} got blown up by ${attacker.name}'s grenade! mandoooGOTTEM`)
|
await say(`${target?.name} got blown up by ${attacker.name}'s grenade!`)
|
||||||
await addTimeoutToDB(attacker, target!, 'grenade')
|
await addTimeoutToDB(attacker, target!, 'grenade')
|
||||||
|
await addUsedItem(attacker, 'grenade')
|
||||||
|
await updateInventory(attacker, itemResult.inv!)
|
||||||
} else {
|
} else {
|
||||||
// Banned is not an option, and neither is noexist
|
// Banned is not an option, and neither is noexist
|
||||||
await say(`something went wrong mandoooYikes`)
|
await say(`something went wrong`)
|
||||||
console.error(result.reason)
|
console.error(result.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function useTNT(broadcasterId: string, attacker: HelixUser, say: (args0: string) => Promise<void>) {
|
export async function useTNT(broadcasterId: string, attacker: HelixUser, say: (args0: string) => Promise<void>) {
|
||||||
if (vulnerableUsers.length === 0) { await say('No chatters to blow up!'); return }
|
if (vulnerableUsers.length === 0) { await say('No chatters to blow up!'); return }
|
||||||
const itemResult = await changeItemCount(attacker, 'tnt')
|
const itemResult = await changeItemCount(attacker, 'tnt')
|
||||||
|
|
||||||
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no TNT mandoooYikes'); return }
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no TNT!'); return }
|
||||||
const min = vulnerableUsers.length < 3 ? vulnerableUsers.length : 3 //if less than 3 chatters, use that else 3
|
const min = vulnerableUsers.length < 3 ? vulnerableUsers.length : 3 //if less than 3 chatters, use that else 3
|
||||||
const max = vulnerableUsers.length > 10 ? 10 : vulnerableUsers.length //if more than 10 chatters do 10 else 10
|
const max = vulnerableUsers.length > 10 ? 10 : vulnerableUsers.length //if more than 10 chatters do 10 else 10
|
||||||
const blastedusers = Math.floor(Math.random() * (max - min + 1)) + min
|
const blastedusers = Math.floor(Math.random() * (max - min + 1)) + min
|
||||||
@@ -109,14 +117,17 @@ export async function useTNT(broadcasterId: string, attacker: HelixUser, say: (a
|
|||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
const result = await timeout(broadcasterId, target!, 60, `You got hit by ${attacker.name}'s TNT`)
|
const result = await timeout(broadcasterId, target!, 60, `You got hit by ${attacker.name}'s TNT`)
|
||||||
if (result.status) {
|
if (result.status) {
|
||||||
await say(`${target?.name} got blown up by TNT! mandoooTNT`)
|
await say(`${target?.name} got blown up by TNT!`)
|
||||||
await addTimeoutToDB(attacker, target!, 'tnt')
|
await addTimeoutToDB(attacker, target!, 'tnt')
|
||||||
|
await updateInventory(attacker, itemResult.inv!)
|
||||||
} else {
|
} else {
|
||||||
await say(`something went wrong mandoooYikes`)
|
await say(`something went wrong`)
|
||||||
console.error(result.reason)
|
console.error(result.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await say(`${attacker.name} blew up ${blastedusers} chatters with their TNT mandoooGOTTEM ${attacker.name} has ${itemResult.count} tnt${itemResult.count === 1 ? '' : 's'} remaining`)
|
|
||||||
|
await addUsedItem(attacker, 'tnt')
|
||||||
|
await say(`${attacker.name} blew up ${blastedusers} chatters with their TNT! ${attacker.name} has ${itemResult.count} tnt${itemResult.count === 1 ? '' : 's'} remaining`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandom(): number {
|
function getRandom(): number {
|
||||||
@@ -125,7 +136,7 @@ function getRandom(): number {
|
|||||||
|
|
||||||
export async function useLootbox(user: HelixUser, say: (arg0: string) => Promise<void>) {
|
export async function useLootbox(user: HelixUser, say: (arg0: string) => Promise<void>) {
|
||||||
const itemResult = await changeItemCount(user, 'lootbox')
|
const itemResult = await changeItemCount(user, 'lootbox')
|
||||||
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no lootboxes mandoooYikes'); return }
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no lootboxes!'); return }
|
||||||
// Lootbox logic will for now just be get 25 qbucks, with 50% chance to get a grenade 25% chance to get a blaster and 10% chance to get TNT
|
// Lootbox logic will for now just be get 25 qbucks, with 50% chance to get a grenade 25% chance to get a blaster and 10% chance to get TNT
|
||||||
let inventory = await getInventory(user)
|
let inventory = await getInventory(user)
|
||||||
let newitems: string[] = []
|
let newitems: string[] = []
|
||||||
@@ -134,7 +145,9 @@ export async function useLootbox(user: HelixUser, say: (arg0: string) => Promise
|
|||||||
if (getRandom() <= 50) { newitems.push('1 grenade'); inventory.grenade += 1 }
|
if (getRandom() <= 50) { newitems.push('1 grenade'); inventory.grenade += 1 }
|
||||||
if (getRandom() <= 25) { newitems.push('1 blaster'); inventory.blaster += 1 }
|
if (getRandom() <= 25) { newitems.push('1 blaster'); inventory.blaster += 1 }
|
||||||
if (getRandom() <= 10) { newitems.push('1 tnt'); inventory.tnt += 1 }
|
if (getRandom() <= 10) { newitems.push('1 tnt'); inventory.tnt += 1 }
|
||||||
|
inventory.lootbox = itemResult.inv!.lootbox
|
||||||
await updateInventory(user, inventory)
|
await updateInventory(user, inventory)
|
||||||
|
await addUsedItem(user, 'lootbox')
|
||||||
|
|
||||||
await say(`${user.name} got: ${newitems.join(' and ')}`)
|
await say(`${user.name} got: ${newitems.join(' and ')}`)
|
||||||
}
|
}
|
||||||
@@ -152,10 +165,17 @@ function shuffle(arrayold: any[]) {
|
|||||||
|
|
||||||
export async function useClipboard(broadcasterId: string, user: HelixUser, question: string, say: (arg0: string) => Promise<void>) {
|
export async function useClipboard(broadcasterId: string, user: HelixUser, question: string, say: (arg0: string) => Promise<void>) {
|
||||||
const tempapi = broadcasterApi ?? api
|
const tempapi = broadcasterApi ?? api
|
||||||
|
|
||||||
const polldata = await tempapi.polls.getPolls(broadcasterId)
|
const polldata = await tempapi.polls.getPolls(broadcasterId)
|
||||||
if (polldata.data.length > 0) {await say('Can\'t have two polls active at once.'); return}
|
const activepolldata = polldata.data.filter(poll => poll.status === "ACTIVE")
|
||||||
|
if (activepolldata.length > 0) { await say('Can\'t have two polls active at once.'); return }
|
||||||
|
|
||||||
const itemResult = await changeItemCount(user, 'clipboard')
|
const itemResult = await changeItemCount(user, 'clipboard')
|
||||||
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no clipboards mandoooYikes'); return }
|
await addUsedItem(user, 'clipboard')
|
||||||
|
await updateInventory(user, itemResult.inv!)
|
||||||
|
|
||||||
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no clipboards!'); return }
|
||||||
|
|
||||||
await tempapi.polls.createPoll(broadcasterId, { choices: ['Yes', 'No'], duration: 120, title: question })
|
await tempapi.polls.createPoll(broadcasterId, { choices: ['Yes', 'No'], duration: 120, title: question })
|
||||||
await say(`${user.name} used a clipboard! They have ${itemResult.count} clipboard${itemResult.count === 1 ? '' : 's'} remaining`)
|
await say(`${user.name} used a clipboard! They have ${itemResult.count} clipboard${itemResult.count === 1 ? '' : 's'} remaining`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,17 @@ export interface Timeout extends BaseModel {
|
|||||||
targetname: string
|
targetname: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UsedItem extends BaseModel {
|
||||||
|
name: string,
|
||||||
|
user: string
|
||||||
|
}
|
||||||
|
|
||||||
interface TypedPocketBase extends PocketBase {
|
interface TypedPocketBase extends PocketBase {
|
||||||
collection(idOrName: string): RecordService,
|
collection(idOrName: string): RecordService,
|
||||||
collection(idOrName: 'users'): RecordService<User>,
|
collection(idOrName: 'users'): RecordService<User>,
|
||||||
collection(idOrName: 'ttvauth'): RecordService<TTVAuth>
|
collection(idOrName: 'ttvauth'): RecordService<TTVAuth>
|
||||||
collection(idOrName: 'timeouts'): RecordService<Timeout>
|
collection(idOrName: 'timeouts'): RecordService<Timeout>
|
||||||
|
collection(idOrName: 'itemuses'): RecordService<UsedItem>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ interface statusmessage {
|
|||||||
export async function timeout(broadcasterid: string, target: HelixUser, duration: number, reason: string): Promise<statusmessage> {
|
export async function timeout(broadcasterid: string, target: HelixUser, duration: number, reason: string): Promise<statusmessage> {
|
||||||
if (!target) return { status: false, reason: 'noexist' }
|
if (!target) return { status: false, reason: 'noexist' }
|
||||||
const tmpapi = broadcasterApi ?? api
|
const tmpapi = broadcasterApi ?? api
|
||||||
// if (target.name === 'qwerinope') return { status: false, reason: 'unknown' }
|
if (target.name === process.env.BOT_NAME) return { status: false, reason: 'unknown' }
|
||||||
if (await tmpapi.moderation.checkUserBan(broadcasterid, target)) return { status: false, reason: 'banned' }
|
if (await tmpapi.moderation.checkUserBan(broadcasterid, target)) return { status: false, reason: 'banned' }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ export async function changeBalance(user: HelixUser, amount: number): Promise<ba
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface timeoutsGetResult {
|
interface timeoutsGetResult {
|
||||||
user: HelixUser,
|
|
||||||
hit: {
|
hit: {
|
||||||
blaster: number, // I'm going to combine blaster, grenade and tnt into one.
|
blaster: number, // I'm going to combine blaster, grenade and tnt into one.
|
||||||
silverbullet: number,
|
silverbullet: number,
|
||||||
@@ -63,11 +62,11 @@ interface timeoutsGetResult {
|
|||||||
|
|
||||||
const BLASTERS = ['blaster', 'grenade', 'tnt']
|
const BLASTERS = ['blaster', 'grenade', 'tnt']
|
||||||
|
|
||||||
async function getTimeouts(user: HelixUser): Promise<timeoutsGetResult> {
|
async function getTimeouts(userDBID: string, monthdata?: string): Promise<timeoutsGetResult> {
|
||||||
await DBValidation(user)
|
let monthquery = ''
|
||||||
const userDBID = await getDBID(user)
|
if (monthdata) monthquery = ` && created~"${monthdata}"`
|
||||||
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userDBID}"` })
|
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userDBID}"${monthquery}` })
|
||||||
const shot = await pb.collection('timeouts').getFullList({ filter: `attacker="${userDBID}"` })
|
const shot = await pb.collection('timeouts').getFullList({ filter: `attacker="${userDBID}"${monthquery}` })
|
||||||
|
|
||||||
const blasterhit = hit.filter((item) => BLASTERS.includes(item.source)).length
|
const blasterhit = hit.filter((item) => BLASTERS.includes(item.source)).length
|
||||||
const silverbullethit = hit.length - blasterhit
|
const silverbullethit = hit.length - blasterhit
|
||||||
@@ -75,7 +74,6 @@ async function getTimeouts(user: HelixUser): Promise<timeoutsGetResult> {
|
|||||||
const silverbulletshot = shot.length - blastershot
|
const silverbulletshot = shot.length - blastershot
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
|
||||||
hit: {
|
hit: {
|
||||||
blaster: blasterhit,
|
blaster: blasterhit,
|
||||||
silverbullet: silverbullethit
|
silverbullet: silverbullethit
|
||||||
@@ -87,6 +85,21 @@ async function getTimeouts(user: HelixUser): Promise<timeoutsGetResult> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getItemUses(userDBID: string, monthdata?: string): Promise<inventory> {
|
||||||
|
let monthquery = ''
|
||||||
|
if (monthdata) monthquery = ` && created~"${monthdata}"`
|
||||||
|
const items = await pb.collection('itemuses').getFullList({ filter: `user="${userDBID}"${monthquery}` })
|
||||||
|
return {
|
||||||
|
version: 1,
|
||||||
|
blaster: items.filter((item) => item.name === 'blaster').length,
|
||||||
|
grenade: items.filter((item) => item.name === 'grenade').length,
|
||||||
|
silverbullet: items.filter((item) => item.name === 'silverbullet').length,
|
||||||
|
tnt: items.filter((item) => item.name === 'tnt').length,
|
||||||
|
clipboard: items.filter((item) => item.name === 'clipboard').length,
|
||||||
|
lootbox: items.filter((item) => item.name === 'lootbox').length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface inventory {
|
export interface inventory {
|
||||||
version: number,
|
version: number,
|
||||||
|
|
||||||
@@ -109,10 +122,12 @@ interface statsGetResult extends timeoutsGetResult {
|
|||||||
used: inventory
|
used: inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStats(user: HelixUser): Promise<statsGetResult> {
|
export async function getStats(user: HelixUser, monthdata?: string): Promise<statsGetResult> {
|
||||||
const { hit, shot } = await getTimeouts(user)
|
await DBValidation(user)
|
||||||
const dbuser = await pb.collection('users').getFirstListItem(`twitchid="${user.id}"`)
|
const userDBID = await getDBID(user)
|
||||||
return { user, hit, shot, used: dbuser.itemuses }
|
const { hit, shot } = await getTimeouts(userDBID, monthdata)
|
||||||
|
const uses = await getItemUses(userDBID, monthdata)
|
||||||
|
return { hit, shot, used: uses }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateInventory(user: HelixUser, newinv: inventory) {
|
export async function updateInventory(user: HelixUser, newinv: inventory) {
|
||||||
@@ -122,6 +137,12 @@ export async function updateInventory(user: HelixUser, newinv: inventory) {
|
|||||||
await pb.collection('users').update(recordid, { inventory: newinv })
|
await pb.collection('users').update(recordid, { inventory: newinv })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function addUsedItem(user: HelixUser, item: string) {
|
||||||
|
await DBValidation(user)
|
||||||
|
const userDBID = await getDBID(user)
|
||||||
|
await pb.collection('itemuses').create({ user: userDBID, name: item })
|
||||||
|
}
|
||||||
|
|
||||||
async function DBValidation(user: HelixUser) {
|
async function DBValidation(user: HelixUser) {
|
||||||
try {
|
try {
|
||||||
await pb.collection('users').getFirstListItem(`twitchid="${user.id}"`)
|
await pb.collection('users').getFirstListItem(`twitchid="${user.id}"`)
|
||||||
|
|||||||
Reference in New Issue
Block a user