mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
major refactor, docker support. Check if there's a better way to do commands/index.ts
This commit is contained in:
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
FROM oven/bun AS base
|
||||
WORKDIR /app
|
||||
|
||||
FROM base AS install
|
||||
RUN mkdir -p /temp/dev
|
||||
COPY package.json bun.lock /temp/dev/
|
||||
RUN cd /temp/dev && bun install --frozen-lockfile
|
||||
|
||||
RUN mkdir -p /temp/prod
|
||||
COPY package.json bun.lock /temp/prod/
|
||||
RUN cd /temp/prod && bun install --frozen-lockfile --production
|
||||
|
||||
FROM base AS prerelease
|
||||
COPY --from=install /temp/dev/node_modules node_modules
|
||||
COPY . .
|
||||
|
||||
FROM base AS release
|
||||
COPY --from=install /temp/prod/node_modules node_modules
|
||||
COPY --from=prerelease /app/src ./src
|
||||
COPY --from=prerelease /app/auth.json .
|
||||
COPY --from=prerelease /app/package.json .
|
||||
|
||||
CMD [ "bun", "." ]
|
||||
10
compose.yml
10
compose.yml
@@ -9,3 +9,13 @@ services:
|
||||
volumes:
|
||||
- ./pb:/pb/pb_data
|
||||
restart: no
|
||||
bot:
|
||||
container_name: bot
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
restart: no
|
||||
develop:
|
||||
watch:
|
||||
- action: rebuild
|
||||
path: ./src
|
||||
|
||||
52
index.ts
52
index.ts
@@ -1,52 +0,0 @@
|
||||
import { Bot, createBotCommand } from '@twurple/easy-bot'
|
||||
import { ApiClient } from '@twurple/api'
|
||||
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!")
|
||||
})
|
||||
|
||||
await authProvider.refreshAccessTokenForUser(238377856)
|
||||
|
||||
const api = new ApiClient({ authProvider })
|
||||
|
||||
const bot = new Bot({
|
||||
authProvider,
|
||||
channel: "qwerinope",
|
||||
commands: [
|
||||
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")
|
||||
}),
|
||||
createBotCommand("thank", async (params, {say, msg}) => {
|
||||
if (params.length === 0) {await say(`fuck you ${msg.userInfo.userName}`); return}
|
||||
await say(`fuck you ${params.join(' ')}`)
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
bot.onConnect(()=> {
|
||||
console.log("Ready!")
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"main": "src/bot.ts",
|
||||
"dependencies": {
|
||||
"@twurple/api": "^7.2.1",
|
||||
"@twurple/chat": "^7.2.1",
|
||||
|
||||
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