mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +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_ID=
|
||||||
CLIENT_SECRET=
|
CLIENT_SECRET=
|
||||||
OAUTH_CODE=
|
OAUTH_CODE=
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ services:
|
|||||||
- action: rebuild
|
- action: rebuild
|
||||||
path: ./src
|
path: ./src
|
||||||
environment:
|
environment:
|
||||||
|
- CHANNEL=$CHANNEL
|
||||||
# These env variables can be removed once the bot has sucessfully run once
|
# These env variables can be removed once the bot has sucessfully run once
|
||||||
- CLIENT_ID=$CLIENT_ID
|
- CLIENT_ID=$CLIENT_ID
|
||||||
- CLIENT_SECRET=$CLIENT_SECRET
|
- CLIENT_SECRET=$CLIENT_SECRET
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ import { Bot } from '@twurple/easy-bot'
|
|||||||
import authProvider from './lib/auth';
|
import authProvider from './lib/auth';
|
||||||
import commands from './commands'
|
import commands from './commands'
|
||||||
|
|
||||||
|
const channel = process.env.CHANNEL ?? ''
|
||||||
|
|
||||||
const bot = new Bot({
|
const bot = new Bot({
|
||||||
authProvider,
|
authProvider,
|
||||||
channel: "qwerinope",
|
channel,
|
||||||
commands
|
commands
|
||||||
})
|
})
|
||||||
|
|
||||||
bot.onConnect(async ()=> {
|
bot.onConnect(async () => {
|
||||||
// await authProvider.refreshAccessTokenForUser(238377856)
|
// await authProvider.refreshAccessTokenForUser(238377856)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('Bot is ready to accept commands!')
|
console.log('Bot is ready to accept commands!')
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ import getloot from "./getloot";
|
|||||||
import modme from "./modme";
|
import modme from "./modme";
|
||||||
import use from "./use";
|
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 api, { broadcasterApi } from "./api";
|
||||||
import pb from "./pocketbase";
|
import pb from "./pocketbase";
|
||||||
import { getDBID } from "./userHelper";
|
import { getDBID } from "./userHelper";
|
||||||
@@ -12,22 +12,15 @@ 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
|
||||||
// if (target.name === 'qwerinope') return { status: false, reason: 'unknown' }
|
// if (target.name === 'qwerinope') return { status: false, reason: 'unknown' }
|
||||||
if (broadcasterApi) {
|
if (await tmpapi.moderation.checkUserBan(broadcasterid, target)) return { status: false, reason: 'banned' }
|
||||||
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' }
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (broadcasterApi) {
|
if (await tmpapi.moderation.checkUserMod(broadcasterid, target)) {
|
||||||
if (await broadcasterApi.moderation.checkUserMod(broadcasterid, target)) {
|
await tmpapi.moderation.removeModerator(broadcasterid, target)
|
||||||
await broadcasterApi.moderation.removeModerator(broadcasterid, target)
|
remodMod(broadcasterid, target, duration, tmpapi)
|
||||||
remodMod(broadcasterid, target, duration)
|
await tmpapi.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
||||||
}
|
|
||||||
await broadcasterApi.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
|
||||||
} else {
|
|
||||||
await api.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
|
||||||
}
|
}
|
||||||
return { status: true, reason: '' }
|
return { status: true, reason: '' }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -51,8 +44,8 @@ export async function addTimeoutToDB(attacker: HelixUser, target: HelixUser, sou
|
|||||||
await pb.collection('timeouts').create(timeoutobj)
|
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 () => {
|
setTimeout(async () => {
|
||||||
await broadcasterApi?.moderation.addModerator(broadcasterid, target)
|
await api.moderation.addModerator(broadcasterid, target)
|
||||||
}, (duration + 3) * 1000)
|
}, (duration + 3) * 1000)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user