mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 11:06:59 +01:00
major refactor, docker support. Check if there's a better way to do commands/index.ts
This commit is contained in:
15
src/bot.ts
Normal file
15
src/bot.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Bot } from '@twurple/easy-bot'
|
||||
|
||||
import authProvider from './lib/auth';
|
||||
import commands from './commands'
|
||||
|
||||
const bot = new Bot({
|
||||
authProvider,
|
||||
channel: "qwerinope",
|
||||
commands
|
||||
})
|
||||
|
||||
bot.onConnect(async ()=> {
|
||||
console.log("Ready to accept commands!")
|
||||
await authProvider.refreshAccessTokenForUser(238377856)
|
||||
})
|
||||
4
src/commands/index.ts
Normal file
4
src/commands/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import timeout from "./timeout";
|
||||
import thank from "./thank"
|
||||
|
||||
export default [timeout, thank]
|
||||
6
src/commands/thank.ts
Normal file
6
src/commands/thank.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { createBotCommand } from "@twurple/easy-bot";
|
||||
|
||||
export default createBotCommand("thank", async (params, {say, msg}) => {
|
||||
if (params.length === 0) {await say(`fuck you ${msg.userInfo.userName}`); return}
|
||||
await say(`fuck you ${params.join(' ')}`)
|
||||
})
|
||||
13
src/commands/timeout.ts
Normal file
13
src/commands/timeout.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createBotCommand } from "@twurple/easy-bot";
|
||||
|
||||
import authProvider from "../lib/auth";
|
||||
import { ApiClient } from "@twurple/api";
|
||||
const api = new ApiClient({ authProvider })
|
||||
|
||||
export default createBotCommand('timeout', async (params, { say, broadcasterId }) => {
|
||||
if (params.length === 0) {await say("nice miss bro"); return}
|
||||
const user = await api.users.getUserByName(params[0])
|
||||
if (!user) { await say("bro doesn't exist"); return }
|
||||
await api.moderation.banUser(broadcasterId, { duration: 60, reason: "lmao", user: user.id })
|
||||
await say("mandoooGOTTEM")
|
||||
})
|
||||
26
src/lib/auth.ts
Normal file
26
src/lib/auth.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { RefreshingAuthProvider } from '@twurple/auth'
|
||||
|
||||
let auth = await Bun.file('auth.json').json()
|
||||
|
||||
const authProvider = new RefreshingAuthProvider({
|
||||
clientId: auth.CLIENT_ID,
|
||||
clientSecret: auth.CLIENT_SECRET
|
||||
})
|
||||
|
||||
await authProvider.addUserForToken({
|
||||
accessToken: auth.ACCESS_TOKEN,
|
||||
refreshToken: auth.REFRESH_TOKEN,
|
||||
expiresIn: auth.EXPIRESIN,
|
||||
obtainmentTimestamp: auth.OBTAINMENTTIMESTAMP
|
||||
}, ['chat', 'moderator:manage:banned_users'])
|
||||
|
||||
authProvider.onRefresh(async (_id, newTokenData) => {
|
||||
auth.ACCESS_TOKEN = newTokenData.accessToken
|
||||
auth.REFRESH_TOKEN = newTokenData.refreshToken!
|
||||
auth.EXPIRESIN = newTokenData.expiresIn!
|
||||
auth.OBTAINMENTTIMESTAMP = newTokenData.obtainmentTimestamp
|
||||
await Bun.file('auth.json').write(JSON.stringify(auth))
|
||||
console.log("Refreshed OAuth tokens.")
|
||||
})
|
||||
|
||||
export default authProvider
|
||||
Reference in New Issue
Block a user