mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 12:36:59 +01:00
add clipboards
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { createBotCommand } from "@twurple/easy-bot";
|
import { createBotCommand } from "@twurple/easy-bot";
|
||||||
|
|
||||||
import { useBlaster, useGrenade, useLootbox, useSilverBullet, useTNT } from "../lib/items";
|
import { useBlaster, useClipboard, useGrenade, useLootbox, useSilverBullet, useTNT } 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 }) => {
|
||||||
@@ -30,4 +30,10 @@ const lootbox = createBotCommand('lootbox', async (_params, { say, userId }) =>
|
|||||||
await useLootbox(user!, say)
|
await useLootbox(user!, say)
|
||||||
})
|
})
|
||||||
|
|
||||||
export default [blaster, silverbullet, grenade, tnt, lootbox]
|
const clipboard = createBotCommand('clipboard', async (params, { say, broadcasterId, userId }) => {
|
||||||
|
const user = await api.users.getUserById(userId)
|
||||||
|
if (params[0] === undefined) return
|
||||||
|
await useClipboard(broadcasterId, user!, params.join(' '), say)
|
||||||
|
})
|
||||||
|
|
||||||
|
export default [blaster, silverbullet, grenade, tnt, lootbox, clipboard]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createBotCommand } from "@twurple/easy-bot";
|
import { createBotCommand } from "@twurple/easy-bot";
|
||||||
import { useBlaster, useGrenade, useLootbox, useSilverBullet, useTNT } from "../lib/items";
|
import { useBlaster, useClipboard, useGrenade, useLootbox, useSilverBullet, useTNT } 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 }) => {
|
||||||
@@ -27,6 +27,10 @@ export default createBotCommand('use', async (params, { say, broadcasterId, user
|
|||||||
case 'loot':
|
case 'loot':
|
||||||
await useLootbox(user!, say)
|
await useLootbox(user!, say)
|
||||||
break
|
break
|
||||||
|
case 'clipboard':
|
||||||
|
if (params[1] === undefined) return
|
||||||
|
await useClipboard(broadcasterId, user!, params.slice(1).join(' '), say)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
await say(`${params[0]} does not exist mandoooYikes`)
|
await say(`${params[0]} does not exist mandoooYikes`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DIFFERENT_BROADCASTER = process.env.DIFFERENT_BROADCASTER
|
const DIFFERENT_BROADCASTER = process.env.DIFFERENT_BROADCASTER
|
||||||
broadcasterAuthData = !broadcasterAuthData && DIFFERENT_BROADCASTER === 'true' ? await firstAccess(false) : broadcasterAuthData ? broadcasterAuthData.auth : undefined
|
broadcasterAuthData = !broadcasterAuthData && DIFFERENT_BROADCASTER === 'true' ? await firstAccess(false) : broadcasterAuthData && DIFFERENT_BROADCASTER === 'true' ? broadcasterAuthData.auth : undefined
|
||||||
|
|
||||||
async function firstAccess(main = true) {
|
async function firstAccess(main = true) {
|
||||||
// This function gets the required auth codes, and stores it in pocketbase
|
// This function gets the required auth codes, and stores it in pocketbase
|
||||||
@@ -35,10 +35,10 @@ async function firstAccess(main = true) {
|
|||||||
if ((main && !OAUTH_CODE) || (!main && !BROADCASTER_OAUTH_CODE)) {
|
if ((main && !OAUTH_CODE) || (!main && !BROADCASTER_OAUTH_CODE)) {
|
||||||
if (main) {
|
if (main) {
|
||||||
console.error("No 'OAUTH_CODE' provided. To get the code, please visit this URL, authorize the bot and copy the 'code' from the return URL.")
|
console.error("No 'OAUTH_CODE' provided. To get the code, please visit this URL, authorize the bot and copy the 'code' from the return URL.")
|
||||||
console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=chat:read+chat:edit+moderator:manage:banned_users+moderation:read`)
|
console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=chat:read+chat:edit+moderator:manage:banned_users+moderation:read+channel:manage:polls`)
|
||||||
} else {
|
} else {
|
||||||
console.error("No 'BROADCASTER_OAUTH_CODE' provided. To get the code, please make the broadcaster visit the following URL, and get them to return the 'code' from the return URL.")
|
console.error("No 'BROADCASTER_OAUTH_CODE' provided. To get the code, please make the broadcaster visit the following URL, and get them to return the 'code' from the return URL.")
|
||||||
console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=moderator:manage:banned_users+moderation:read+channel:manage:moderators`)
|
console.error(`https://id.twitch.tv/oauth2/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=moderator:manage:banned_users+moderation:read+channel:manage:moderators+channel:manage:polls`)
|
||||||
}
|
}
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ await authProvider.addUserForToken({
|
|||||||
refreshToken: auth.REFRESH_TOKEN,
|
refreshToken: auth.REFRESH_TOKEN,
|
||||||
expiresIn: auth.EXPIRESIN,
|
expiresIn: auth.EXPIRESIN,
|
||||||
obtainmentTimestamp: auth.OBTAINMENTTIMESTAMP
|
obtainmentTimestamp: auth.OBTAINMENTTIMESTAMP
|
||||||
}, ['chat', 'moderator:manage:banned_users'])
|
}, ['chat', 'moderator:manage:banned_users', 'channel:manage:polls', 'channel:manage:moderators'])
|
||||||
|
|
||||||
authProvider.onRefresh(async (_id, newTokenData) => {
|
authProvider.onRefresh(async (_id, newTokenData) => {
|
||||||
auth.ACCESS_TOKEN = newTokenData.accessToken
|
auth.ACCESS_TOKEN = newTokenData.accessToken
|
||||||
@@ -95,7 +95,7 @@ const broadcasterAuthProvider = broadcasterAuthData === undefined ? undefined :
|
|||||||
refreshToken: broadcasterAuthData.REFRESH_TOKEN,
|
refreshToken: broadcasterAuthData.REFRESH_TOKEN,
|
||||||
expiresIn: broadcasterAuthData.EXPIRESIN,
|
expiresIn: broadcasterAuthData.EXPIRESIN,
|
||||||
obtainmentTimestamp: broadcasterAuthData.OBTAINMENTTIMESTAMP
|
obtainmentTimestamp: broadcasterAuthData.OBTAINMENTTIMESTAMP
|
||||||
}, ['moderator:manage:banned_users', 'moderation:read', 'channel:manage:moderators'])
|
}, ['moderator:manage:banned_users', 'moderation:read', 'channel:manage:moderators', 'channel:manage:polls'])
|
||||||
|
|
||||||
broadcasterAuthProvider.onRefresh(async (_id, newTokenData) => {
|
broadcasterAuthProvider.onRefresh(async (_id, newTokenData) => {
|
||||||
broadcasterAuthData.ACCESS_TOKEN = newTokenData.accessToken
|
broadcasterAuthData.ACCESS_TOKEN = newTokenData.accessToken
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HelixUser } from "@twurple/api"
|
import { HelixUser } from "@twurple/api"
|
||||||
import { changeBalance, getInventory, updateInventory } from "../lib/userHelper"
|
import { changeBalance, getInventory, updateInventory } from "../lib/userHelper"
|
||||||
import { timeout, addTimeoutToDB, vulnerableUsers } from "./timeoutHelper"
|
import { timeout, addTimeoutToDB, vulnerableUsers } from "./timeoutHelper"
|
||||||
import api from "./api"
|
import api, { broadcasterApi } from "./api"
|
||||||
|
|
||||||
export const ITEMS = ['blaster', 'silverbullet', 'grenade', 'tnt', 'clipboard', 'lootbox']
|
export const ITEMS = ['blaster', 'silverbullet', 'grenade', 'tnt', 'clipboard', 'lootbox']
|
||||||
|
|
||||||
@@ -149,3 +149,13 @@ function shuffle(arrayold: any[]) {
|
|||||||
}
|
}
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function useClipboard(broadcasterId: string, user: HelixUser, question: string, say: (arg0: string) => Promise<void>) {
|
||||||
|
const tempapi = broadcasterApi ?? api
|
||||||
|
const polldata = await tempapi.polls.getPolls(broadcasterId)
|
||||||
|
if (polldata.data.length > 0) {await say('Can\'t have two polls active at once.'); return}
|
||||||
|
const itemResult = await changeItemCount(user, 'clipboard')
|
||||||
|
if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no clipboards mandoooYikes'); return }
|
||||||
|
await tempapi.polls.createPoll(broadcasterId, { choices: ['Yes', 'No'], duration: 120, title: question })
|
||||||
|
await say(`${user.name} used a clipboard! They have ${itemResult.count} clipboard${itemResult.count === 1 ? '' : 's'} remaining`)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user