mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
minor fixes and stats implemented
next will be !mbucks (easy), !getloot (medium) and !use (+ aliases) (hard)
This commit is contained in:
@@ -2,5 +2,6 @@ import timeout from "./timeout";
|
|||||||
import thank from "./thank"
|
import thank from "./thank"
|
||||||
import give from "./give"
|
import give from "./give"
|
||||||
import inventory from "./inventory";
|
import inventory from "./inventory";
|
||||||
|
import stats from "./stats";
|
||||||
|
|
||||||
export default [timeout, thank, give, inventory]
|
export default [timeout, thank, give, inventory, stats]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default createBotCommand('inv', async (params, { userName, say }) => {
|
|||||||
user = await api.users.getUserByName(params[0])
|
user = await api.users.getUserByName(params[0])
|
||||||
} else user = await api.users.getUserByName(userName)
|
} else user = await api.users.getUserByName(userName)
|
||||||
if (!user) {
|
if (!user) {
|
||||||
say(`User ${params[0]} not found`)
|
await say(`User ${params[0]} not found`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
src/commands/stats.ts
Normal file
31
src/commands/stats.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { createBotCommand } from "@twurple/easy-bot";
|
||||||
|
import api from "../lib/api";
|
||||||
|
import { getStats } from "../lib/userHelper";
|
||||||
|
import { HelixUser } from "@twurple/api";
|
||||||
|
|
||||||
|
export default createBotCommand('stats', async (params, { say, userName }) => {
|
||||||
|
let user: HelixUser | null
|
||||||
|
if (params.length !== 0) {
|
||||||
|
user = await api.users.getUserByName(params[0])
|
||||||
|
} else user = await api.users.getUserByName(userName)
|
||||||
|
if (!user) {
|
||||||
|
await say(`User ${params[0]} not found`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = params.length === 0 ? { me: true, stats: await getStats(user!) } : { me: false, stats: await getStats(user!) }
|
||||||
|
|
||||||
|
const KD = data.stats.shot.blaster / data.stats.hit.blaster
|
||||||
|
|
||||||
|
await say(
|
||||||
|
`
|
||||||
|
Stats of ${data.me ? userName : params[0]}:
|
||||||
|
Users blasted: ${data.stats.shot.blaster},
|
||||||
|
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD} 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}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -66,7 +66,7 @@ interface timeoutsGetResult {
|
|||||||
|
|
||||||
const BLASTERS = ['blaster', 'grenade', 'tnt']
|
const BLASTERS = ['blaster', 'grenade', 'tnt']
|
||||||
|
|
||||||
export async function getTimeouts(user: HelixUser): Promise<timeoutsGetResult> {
|
async function getTimeouts(user: HelixUser): Promise<timeoutsGetResult> {
|
||||||
await DBValidation(user)
|
await DBValidation(user)
|
||||||
const userDBID = await getDBID(user)
|
const userDBID = await getDBID(user)
|
||||||
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userDBID}"` })
|
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userDBID}"` })
|
||||||
@@ -110,7 +110,9 @@ export async function getInventory(user: HelixUser): Promise<inventory> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getStats(user: HelixUser) {
|
export async function getStats(user: HelixUser) {
|
||||||
|
const { hit, shot } = await getTimeouts(user)
|
||||||
|
const dbuser = await pb.collection('users').getFirstListItem(`twitchid="${user.id}"`)
|
||||||
|
return { hit, shot, used: dbuser.itemuses }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateInventory(user: HelixUser, newinv: inventory) {
|
export async function updateInventory(user: HelixUser, newinv: inventory) {
|
||||||
@@ -133,6 +135,7 @@ async function createUser(user: HelixUser) {
|
|||||||
twitchid: user.id,
|
twitchid: user.id,
|
||||||
firstname: user.name,
|
firstname: user.name,
|
||||||
inventory: EMPTYINV,
|
inventory: EMPTYINV,
|
||||||
|
itemuses: EMPTYINV,
|
||||||
balance: 0
|
balance: 0
|
||||||
}
|
}
|
||||||
await pb.collection('users').create(data)
|
await pb.collection('users').create(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user