mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 12:36:59 +01:00
add grenades, move give command and add vulnchatters command
This commit is contained in:
21
src/bot.ts
21
src/bot.ts
@@ -4,7 +4,10 @@ import authProvider from './lib/auth';
|
|||||||
import commands from './commands'
|
import commands from './commands'
|
||||||
import api, { broadcasterAuthProvider } from './lib/api';
|
import api, { broadcasterAuthProvider } from './lib/api';
|
||||||
|
|
||||||
|
import { removeVulnChatter, vulnerableUsers } from './lib/timeoutHelper';
|
||||||
|
|
||||||
const channel = process.env.CHANNEL ?? ''
|
const channel = process.env.CHANNEL ?? ''
|
||||||
|
const user = process.env.BOT_NAME ?? ''
|
||||||
|
|
||||||
const bot = new Bot({
|
const bot = new Bot({
|
||||||
authProvider,
|
authProvider,
|
||||||
@@ -13,7 +16,7 @@ const bot = new Bot({
|
|||||||
})
|
})
|
||||||
|
|
||||||
bot.onConnect(async () => {
|
bot.onConnect(async () => {
|
||||||
const name = await api.users.getUserByName(process.env.BOT_NAME!)
|
const name = await api.users.getUserByName(user)
|
||||||
await authProvider.refreshAccessTokenForUser(name?.id!)
|
await authProvider.refreshAccessTokenForUser(name?.id!)
|
||||||
if (broadcasterAuthProvider) {
|
if (broadcasterAuthProvider) {
|
||||||
const broadcastername = await api.users.getUserByName(channel)
|
const broadcastername = await api.users.getUserByName(channel)
|
||||||
@@ -24,3 +27,19 @@ bot.onConnect(async () => {
|
|||||||
console.log('Bot is ready to accept commands!')
|
console.log('Bot is ready to accept commands!')
|
||||||
}, 1000 * 5)
|
}, 1000 * 5)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const ILLEGALBANS = [user, channel]
|
||||||
|
|
||||||
|
bot.onMessage((msg) => {
|
||||||
|
if (vulnerableUsers.includes(msg.userId)) return
|
||||||
|
if (ILLEGALBANS.includes(msg.userName)) return
|
||||||
|
vulnerableUsers.push(msg.userId)
|
||||||
|
})
|
||||||
|
|
||||||
|
bot.onBan((ban) => {
|
||||||
|
removeVulnChatter(ban.userId)
|
||||||
|
})
|
||||||
|
|
||||||
|
bot.onTimeout(timeout => {
|
||||||
|
removeVulnChatter(timeout.userId)
|
||||||
|
})
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import { createBotCommand } from "@twurple/easy-bot";
|
|||||||
import api from "../lib/api";
|
import api from "../lib/api";
|
||||||
import { changeItemCount } from "../lib/items";
|
import { changeItemCount } from "../lib/items";
|
||||||
import { changeBalance } from "../lib/userHelper";
|
import { changeBalance } from "../lib/userHelper";
|
||||||
|
import { vulnerableUsers } from "../lib/timeoutHelper";
|
||||||
|
|
||||||
export default createBotCommand('give', async (params, { say, broadcasterId, userId }) => {
|
const give = createBotCommand('give', async (params, { say, broadcasterId, userId }) => {
|
||||||
if (userId !== broadcasterId) return
|
if (userId !== broadcasterId) return
|
||||||
|
|
||||||
const target = await api.users.getUserByName(params[0])
|
const target = await api.users.getUserByName(params[0])
|
||||||
@@ -18,3 +19,11 @@ export default createBotCommand('give', async (params, { say, broadcasterId, use
|
|||||||
|
|
||||||
await say(`${target.name} now has ${data.count} ${params[1]}`)
|
await say(`${target.name} now has ${data.count} ${params[1]}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const vulnChatters = createBotCommand('vulnchatters', async (_params, { say, userId, broadcasterId }) => {
|
||||||
|
if (userId !== broadcasterId) return
|
||||||
|
|
||||||
|
await say(`There are ${vulnerableUsers.length} vulnerable chatters`)
|
||||||
|
})
|
||||||
|
|
||||||
|
export default [give, vulnChatters]
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import timeout from "./timeout";
|
import timeout from "./timeout";
|
||||||
import thank from "./thank"
|
import thank from "./thank"
|
||||||
import give from "./give"
|
|
||||||
import inventory from "./inventory";
|
import inventory from "./inventory";
|
||||||
import stats from "./stats";
|
import stats from "./stats";
|
||||||
import mbucks from "./mbucks";
|
import mbucks from "./mbucks";
|
||||||
@@ -9,5 +8,6 @@ import modme from "./modme";
|
|||||||
import use from "./use";
|
import use from "./use";
|
||||||
|
|
||||||
import aliases from './itemAliases'
|
import aliases from './itemAliases'
|
||||||
|
import admin from './admin'
|
||||||
|
|
||||||
export default [timeout, thank, give, inventory, stats, mbucks, getloot, modme, use, ...aliases]
|
export default [timeout, thank, inventory, stats, mbucks, getloot, modme, use, ...aliases, ...admin]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createBotCommand } from "@twurple/easy-bot";
|
import { createBotCommand } from "@twurple/easy-bot";
|
||||||
|
|
||||||
import { useBlaster, useSilverBullet } from "../lib/items";
|
import { useBlaster, useGrenade, useSilverBullet } from "../lib/items";
|
||||||
import api from "../lib/api";
|
import api from "../lib/api";
|
||||||
|
|
||||||
const blaster = createBotCommand('blaster', async (params, { say, broadcasterId, userId }) => {
|
const blaster = createBotCommand('blaster', async (params, { say, broadcasterId, userId }) => {
|
||||||
@@ -13,6 +13,11 @@ const silverbullet = createBotCommand('execute', async (params, { say, broadcast
|
|||||||
const user = await api.users.getUserById(userId)
|
const user = await api.users.getUserById(userId)
|
||||||
if (params[0] === undefined) return
|
if (params[0] === undefined) return
|
||||||
await useSilverBullet(broadcasterId, user!, params[0], say)
|
await useSilverBullet(broadcasterId, user!, params[0], say)
|
||||||
}, {aliases: ['silverbullet']})
|
}, { aliases: ['silverbullet'] })
|
||||||
|
|
||||||
export default [blaster, silverbullet]
|
const grenade = createBotCommand('grenade', async (_params, { say, broadcasterId, userId }) => {
|
||||||
|
const user = await api.users.getUserById(userId)
|
||||||
|
await useGrenade(broadcasterId, user!, say)
|
||||||
|
})
|
||||||
|
|
||||||
|
export default [blaster, silverbullet, grenade]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createBotCommand } from "@twurple/easy-bot";
|
import { createBotCommand } from "@twurple/easy-bot";
|
||||||
import { useBlaster, useSilverBullet } from "../lib/items";
|
import { useBlaster, useGrenade, useSilverBullet } from "../lib/items";
|
||||||
import api from "../lib/api";
|
import api from "../lib/api";
|
||||||
|
|
||||||
export default createBotCommand('use', async (params, { say, broadcasterId, userId }) => {
|
export default createBotCommand('use', async (params, { say, broadcasterId, userId }) => {
|
||||||
@@ -17,6 +17,9 @@ export default createBotCommand('use', async (params, { say, broadcasterId, user
|
|||||||
if (params[1] === undefined) return
|
if (params[1] === undefined) return
|
||||||
await useSilverBullet(broadcasterId, user!, params[1], say)
|
await useSilverBullet(broadcasterId, user!, params[1], say)
|
||||||
break
|
break
|
||||||
|
case 'grenade':
|
||||||
|
await useGrenade(broadcasterId, user!, say)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
await say(`${params[0]} does not exist mandoooYikes`)
|
await say(`${params[0]} does not exist mandoooYikes`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { HelixUser } from "@twurple/api"
|
import { HelixUser } from "@twurple/api"
|
||||||
import { getInventory, updateInventory, changeBalance } from "../lib/userHelper"
|
import { getInventory, updateInventory } from "../lib/userHelper"
|
||||||
import { timeout, addTimeoutToDB } from "./timeoutHelper"
|
import { timeout, addTimeoutToDB, vulnerableUsers } from "./timeoutHelper"
|
||||||
import api from "./api"
|
import api from "./api"
|
||||||
|
|
||||||
export const ITEMS = ['blaster', 'silverbullet', 'grenade', 'tnt', 'watergun', 'clipboard', 'lootbox']
|
export const ITEMS = ['blaster', 'silverbullet', 'grenade', 'tnt', 'watergun', 'clipboard', 'lootbox']
|
||||||
@@ -78,3 +78,20 @@ export async function useSilverBullet(broadcasterId: string, attacker: HelixUser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function useGrenade(broadcasterId: string, attacker: HelixUser, say: (arg0: string) => Promise<void>) {
|
||||||
|
if (vulnerableUsers.length === 0) { await say('No chatters to blow up!'); return }
|
||||||
|
const itemResult = await changeItemCount(attacker, 'grenade')
|
||||||
|
|
||||||
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no grenades mandoooYikes'); return }
|
||||||
|
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`)
|
||||||
|
if (result.status) {
|
||||||
|
await say(`${target?.name} got blown up by ${attacker.name}'s grenade! mandoooGOTTEM`)
|
||||||
|
await addTimeoutToDB(attacker, target!, 'grenade')
|
||||||
|
} else {
|
||||||
|
// Banned is not an option, and neither is noexist
|
||||||
|
await say(`something went wrong mandoooYikes`)
|
||||||
|
console.error(result.reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,3 +49,9 @@ function remodMod(broadcasterid: string, target: HelixUser, duration: number, ap
|
|||||||
await api.moderation.addModerator(broadcasterid, target)
|
await api.moderation.addModerator(broadcasterid, target)
|
||||||
}, (duration + 3) * 1000)
|
}, (duration + 3) * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let vulnerableUsers: string[] = []
|
||||||
|
|
||||||
|
export function removeVulnChatter(chatterid: string) {
|
||||||
|
vulnerableUsers = vulnerableUsers.filter(chatter => chatter !== chatterid)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user