mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 00:51:37 +01:00
add !execute and !blaster aliases, load channelname from environment vars, cleanup api selection timeoutHelper
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
CHANNEL=
|
||||
CLIENT_ID=
|
||||
CLIENT_SECRET=
|
||||
OAUTH_CODE=
|
||||
|
||||
@@ -28,6 +28,7 @@ services:
|
||||
- action: rebuild
|
||||
path: ./src
|
||||
environment:
|
||||
- CHANNEL=$CHANNEL
|
||||
# These env variables can be removed once the bot has sucessfully run once
|
||||
- CLIENT_ID=$CLIENT_ID
|
||||
- CLIENT_SECRET=$CLIENT_SECRET
|
||||
|
||||
@@ -3,13 +3,15 @@ import { Bot } from '@twurple/easy-bot'
|
||||
import authProvider from './lib/auth';
|
||||
import commands from './commands'
|
||||
|
||||
const channel = process.env.CHANNEL ?? ''
|
||||
|
||||
const bot = new Bot({
|
||||
authProvider,
|
||||
channel: "qwerinope",
|
||||
channel,
|
||||
commands
|
||||
})
|
||||
|
||||
bot.onConnect(async ()=> {
|
||||
bot.onConnect(async () => {
|
||||
// await authProvider.refreshAccessTokenForUser(238377856)
|
||||
setTimeout(() => {
|
||||
console.log('Bot is ready to accept commands!')
|
||||
|
||||
@@ -8,4 +8,6 @@ import getloot from "./getloot";
|
||||
import modme from "./modme";
|
||||
import use from "./use";
|
||||
|
||||
export default [timeout, thank, give, inventory, stats, mbucks, getloot, modme, use]
|
||||
import aliases from './itemAliases'
|
||||
|
||||
export default [timeout, thank, give, inventory, stats, mbucks, getloot, modme, use, ...aliases]
|
||||
|
||||
18
src/commands/itemAliases.ts
Normal file
18
src/commands/itemAliases.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createBotCommand } from "@twurple/easy-bot";
|
||||
|
||||
import { useBlaster, useSilverBullet } from "../lib/items";
|
||||
import api from "../lib/api";
|
||||
|
||||
const blaster = createBotCommand('blaster', async (params, { say, broadcasterId, userId }) => {
|
||||
const user = await api.users.getUserById(userId)
|
||||
if (params[0] === undefined) return
|
||||
await useBlaster(broadcasterId, user!, params[0], say)
|
||||
}, { aliases: ['blast'] })
|
||||
|
||||
const silverbullet = createBotCommand('execute', async (params, { say, broadcasterId, userId }) => {
|
||||
const user = await api.users.getUserById(userId)
|
||||
if (params[0] === undefined) return
|
||||
await useSilverBullet(broadcasterId, user!, params[0], say)
|
||||
}, {aliases: ['silverbullet']})
|
||||
|
||||
export default [blaster, silverbullet]
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HelixUser } from "@twurple/api";
|
||||
import { ApiClient, HelixUser } from "@twurple/api";
|
||||
import api, { broadcasterApi } from "./api";
|
||||
import pb from "./pocketbase";
|
||||
import { getDBID } from "./userHelper";
|
||||
@@ -12,22 +12,15 @@ interface statusmessage {
|
||||
|
||||
export async function timeout(broadcasterid: string, target: HelixUser, duration: number, reason: string): Promise<statusmessage> {
|
||||
if (!target) return { status: false, reason: 'noexist' }
|
||||
const tmpapi = broadcasterApi ?? api
|
||||
// if (target.name === 'qwerinope') return { status: false, reason: 'unknown' }
|
||||
if (broadcasterApi) {
|
||||
if (await broadcasterApi.moderation.checkUserBan(broadcasterid, target)) return { status: false, reason: 'banned' }
|
||||
} else {
|
||||
if (await api.moderation.checkUserBan(broadcasterid, target)) return { status: false, reason: 'banned' }
|
||||
}
|
||||
if (await tmpapi.moderation.checkUserBan(broadcasterid, target)) return { status: false, reason: 'banned' }
|
||||
|
||||
try {
|
||||
if (broadcasterApi) {
|
||||
if (await broadcasterApi.moderation.checkUserMod(broadcasterid, target)) {
|
||||
await broadcasterApi.moderation.removeModerator(broadcasterid, target)
|
||||
remodMod(broadcasterid, target, duration)
|
||||
}
|
||||
await broadcasterApi.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
||||
} else {
|
||||
await api.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
||||
if (await tmpapi.moderation.checkUserMod(broadcasterid, target)) {
|
||||
await tmpapi.moderation.removeModerator(broadcasterid, target)
|
||||
remodMod(broadcasterid, target, duration, tmpapi)
|
||||
await tmpapi.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
||||
}
|
||||
return { status: true, reason: '' }
|
||||
} catch (err) {
|
||||
@@ -51,8 +44,8 @@ export async function addTimeoutToDB(attacker: HelixUser, target: HelixUser, sou
|
||||
await pb.collection('timeouts').create(timeoutobj)
|
||||
}
|
||||
|
||||
function remodMod(broadcasterid: string, target: HelixUser, duration: number) {
|
||||
function remodMod(broadcasterid: string, target: HelixUser, duration: number, api: ApiClient) {
|
||||
setTimeout(async () => {
|
||||
await broadcasterApi?.moderation.addModerator(broadcasterid, target)
|
||||
await api.moderation.addModerator(broadcasterid, target)
|
||||
}, (duration + 3) * 1000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user