update url, improve queue and songrequest

This commit is contained in:
2023-12-15 16:29:08 +08:00
parent 82a0e72122
commit c530c3b126
36 changed files with 411 additions and 141 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { SaveAccountSettings, SaveEnableFunctions, useAccount } from '@/api/account'
import { AddBiliBlackList, SaveAccountSettings, SaveEnableFunctions, useAccount } from '@/api/account'
import {
EventDataTypes,
EventModel,
@@ -16,7 +16,18 @@ import {
import { QueryGetAPI, QueryPostAPI, QueryPostAPIWithParams } from '@/api/query'
import DanmakuClient, { AuthInfo, DanmakuInfo, RoomAuthInfo, SCInfo } from '@/data/DanmakuClient'
import { OPEN_LIVE_API_URL, SONG_API_URL, SONG_REQUEST_API_URL } from '@/data/constants'
import { Check24Filled, Checkmark12Regular, Delete24Filled, Dismiss12Filled, Dismiss16Filled, Info24Filled, Mic24Filled, PeopleQueue24Filled, Play24Filled } from '@vicons/fluent'
import {
Check24Filled,
Checkmark12Regular,
Delete24Filled,
Dismiss12Filled,
Dismiss16Filled,
Info24Filled,
Mic24Filled,
PeopleQueue24Filled,
Play24Filled,
PresenceBlocked16Regular,
} from '@vicons/fluent'
import { ReloadCircleSharp } from '@vicons/ionicons5'
import { useStorage } from '@vueuse/core'
import { format, isSameDay } from 'date-fns'
@@ -99,6 +110,7 @@ const notice = useNotification()
const isWarnMessageAutoClose = useStorage('SongRequest.Settings.WarnMessageAutoClose', false)
const volumn = useStorage('Settings.Volumn', 0.5)
const isReverse = useStorage('SongRequest.Settings.Reverse', false)
const isLoading = ref(false)
const showOBSModal = ref(false)
@@ -128,7 +140,7 @@ const props = defineProps<{
const localActiveSongs = useStorage('SongRequest.ActiveSongs', [] as SongRequestInfo[])
const originSongs = ref<SongRequestInfo[]>(await getAllSong())
const songs = computed(() => {
return originSongs.value.filter((s) => {
const result = originSongs.value.filter((s) => {
if (filterName.value) {
if (filterNameContains.value) {
if (!s.user?.name.toLowerCase().includes(filterName.value.toLowerCase())) {
@@ -148,6 +160,11 @@ const songs = computed(() => {
}
return true
})
if (isReverse.value) {
return result.reverse()
} else {
return result
}
})
const activeSongs = computed(() => {
return (accountInfo ? songs.value : localActiveSongs.value)
@@ -180,7 +197,7 @@ const table = ref()
async function getAllSong() {
if (accountInfo.value) {
try {
const data = await QueryGetAPI<SongRequestInfo[]>(SONG_REQUEST_API_URL() + 'get-all', {
const data = await QueryGetAPI<SongRequestInfo[]>(SONG_REQUEST_API_URL + 'get-all', {
id: accountInfo.value.id,
})
if (data.code == 200) {
@@ -200,8 +217,12 @@ async function getAllSong() {
}
async function addSong(danmaku: EventModel) {
console.log(`[OPEN-LIVE-Song-Request] 收到 [${danmaku.name}] 的点歌${danmaku.type == EventDataTypes.SC ? 'SC' : '弹幕'}: ${danmaku.msg}`)
if (settings.value.enableOnStreaming && accountInfo.value?.streamerInfo?.isStreaming != true) {
message.info('当前未在直播中, 无法添加点歌请求. 或者关闭设置中的仅允许直播时加入')
return
}
if (accountInfo.value) {
await QueryPostAPI<SongRequestInfo>(SONG_REQUEST_API_URL() + 'try-add', danmaku).then((data) => {
await QueryPostAPI<SongRequestInfo>(SONG_REQUEST_API_URL + 'try-add', danmaku).then((data) => {
if (data.code == 200) {
message.success(`[${danmaku.name}] 添加曲目: ${data.data.songName}`)
if (data.message != 'EventFetcher') originSongs.value.unshift(data.data)
@@ -246,7 +267,7 @@ async function addSongManual() {
return
}
if (accountInfo.value) {
await QueryPostAPIWithParams<SongRequestInfo>(SONG_REQUEST_API_URL() + 'add', {
await QueryPostAPIWithParams<SongRequestInfo>(SONG_REQUEST_API_URL + 'add', {
name: newSongName.value,
}).then((data) => {
if (data.code == 200) {
@@ -300,7 +321,7 @@ async function updateSongStatus(song: SongRequestInfo, status: SongRequestStatus
statusString2 = '演唱中'
break
}
await QueryGetAPI(SONG_REQUEST_API_URL() + statusString, {
await QueryGetAPI(SONG_REQUEST_API_URL + statusString, {
id: song.id,
})
.then((data) => {
@@ -397,7 +418,7 @@ async function onUpdateFunctionEnable() {
async function updateSettings() {
if (accountInfo.value) {
isLoading.value = true
await QueryPostAPI(SONG_REQUEST_API_URL() + 'update-setting', settings.value)
await QueryPostAPI(SONG_REQUEST_API_URL + 'update-setting', settings.value)
.then((data) => {
if (data.code == 200) {
message.success('已保存')
@@ -433,7 +454,7 @@ async function deleteSongs(values: SongRequestInfo[]) {
})
}
async function deactiveAllSongs() {
await QueryGetAPI(SONG_REQUEST_API_URL() + 'deactive')
await QueryGetAPI(SONG_REQUEST_API_URL + 'deactive')
.then((data) => {
if (data.code == 200) {
message.success('已全部取消')
@@ -651,7 +672,7 @@ function GetGuardColor(level: number | null | undefined): string {
async function updateActive() {
if (!accountInfo.value) return
try {
const data = await QueryGetAPI<SongRequestInfo[]>(SONG_REQUEST_API_URL() + 'get-active', {
const data = await QueryGetAPI<SongRequestInfo[]>(SONG_REQUEST_API_URL + 'get-active', {
id: accountInfo.value?.id,
})
if (data.code == 200) {
@@ -672,6 +693,26 @@ async function updateActive() {
}
} catch (err) {}
}
function blockUser(item: SongRequestInfo) {
if (item.from != SongRequestFrom.Danmaku) {
message.error(`[${item.user?.name}] 不是来自弹幕的用户`)
return
}
if (item.user) {
AddBiliBlackList(item.user.uid, item.user.name)
.then((data) => {
if (data.code == 200) {
message.success(`[${item.user?.name}] 已添加到黑名单`)
updateSongStatus(item, SongRequestStatus.Cancel)
} else {
message.error(data.message)
}
})
.catch((err) => {
message.error(err)
})
}
}
const isLrcLoading = ref('')
let timer: any
@@ -681,6 +722,8 @@ onMounted(() => {
if (accountInfo.value) {
settings.value = accountInfo.value.settings.songRequest
}
props.client.on('danmaku', onGetDanmaku)
props.client.on('sc', onGetSC)
init()
})
onActivated(() => {
@@ -688,8 +731,6 @@ onActivated(() => {
})
function init() {
dispose()
props.client.on('danmaku', onGetDanmaku)
props.client.on('sc', onGetSC)
timer = setInterval(() => {
updateKey.value++
}, 1000)
@@ -698,8 +739,6 @@ function init() {
}, 2000)
}
function dispose() {
props.client.off('danmaku', onGetDanmaku)
props.client.off('sc', onGetSC)
clearInterval(timer)
clearInterval(updateActiveTimer)
}
@@ -707,6 +746,8 @@ onDeactivated(() => {
dispose()
})
onUnmounted(() => {
props.client.off('danmaku', onGetDanmaku)
props.client.off('sc', onGetSC)
dispose()
})
</script>
@@ -759,6 +800,7 @@ onUnmounted(() => {
<NInput placeholder="手动添加" v-model:value="newSongName" />
<NButton type="primary" @click="addSongManual"> 添加 </NButton>
</NInputGroup>
<NCheckbox v-model:checked="isReverse"> 倒序 </NCheckbox>
<NPopconfirm @positive-click="deactiveAllSongs">
<template #trigger>
<NButton type="error"> 全部取消 </NButton>
@@ -869,6 +911,21 @@ onUnmounted(() => {
</template>
已完成演唱
</NTooltip>
<NTooltip v-if="song.from == SongRequestFrom.Danmaku">
<template #trigger>
<NPopconfirm @positive-click="blockUser(song)">
<template #trigger>
<NButton circle type="warning" style="height: 30px; width: 30px" :loading="isLoading">
<template #icon>
<NIcon :component="PresenceBlocked16Regular" />
</template>
</NButton>
</template>
确定拉黑 {{ song.user?.name }}
</NPopconfirm>
</template>
拉黑用户
</NTooltip>
<NTooltip>
<template #trigger>
<NButton circle type="error" style="height: 30px; width: 30px" :loading="isLoading" @click="updateSongStatus(song, SongRequestStatus.Cancel)">
@@ -941,6 +998,7 @@ onUnmounted(() => {
<NButton @click="updateSettings" type="info" :disabled="!configCanEdit">确定</NButton>
</NInputGroup>
<NSpace align="center">
<NCheckbox v-model:checked="settings.enableOnStreaming" @update:checked="updateSettings" :disabled="!configCanEdit"> 仅在直播时才允许加入 </NCheckbox>
<NCheckbox v-model:checked="settings.allowAllDanmaku" @update:checked="updateSettings" :disabled="!configCanEdit"> 允许所有弹幕点歌 </NCheckbox>
<template v-if="!settings.allowAllDanmaku">
<NCheckbox v-model:checked="settings.needWearFanMedal" @update:checked="updateSettings" :disabled="!configCanEdit"> 需要拥有粉丝牌 </NCheckbox>
@@ -1003,6 +1061,8 @@ onUnmounted(() => {
<NButton @click="updateSettings" type="info" :disabled="!configCanEdit">确定</NButton>
</NInputGroup>
</NSpace>
<NDivider> OBS </NDivider>
<NCheckbox v-model:checked="settings.showRequireInfo" :disabled="!configCanEdit" @update:checked="updateSettings"> 显示底部的需求信息 </NCheckbox>
<NDivider> 其他 </NDivider>
<NCheckbox v-model:checked="isWarnMessageAutoClose"> 自动关闭点歌失败时的提示消息 </NCheckbox>
</NSpace>

View File

@@ -104,7 +104,7 @@ const props = defineProps<{
async function getUsers() {
try {
const data = await QueryGetAPI<UpdateLiveLotteryUsersModel>(LOTTERY_API_URL() + 'live/get-users', {
const data = await QueryGetAPI<UpdateLiveLotteryUsersModel>(LOTTERY_API_URL + 'live/get-users', {
code: props.code,
})
if (data.code == 200) {
@@ -114,7 +114,7 @@ async function getUsers() {
return null
}
function updateUsers() {
QueryPostAPI(LOTTERY_API_URL() + 'live/update-users', {
QueryPostAPI(LOTTERY_API_URL + 'live/update-users', {
code: props.code,
users: originUsers.value,
resultUsers: resultUsers.value,

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { SaveEnableFunctions, useAccount } from '@/api/account'
import { AddBiliBlackList, SaveEnableFunctions, useAccount } from '@/api/account'
import {
EventDataTypes,
EventModel,
@@ -31,6 +31,7 @@ import {
Mic24Filled,
PeopleQueue24Filled,
Play24Filled,
PresenceBlocked16Regular,
} from '@vicons/fluent'
import { ReloadCircleSharp } from '@vicons/ionicons5'
import { useStorage } from '@vueuse/core'
@@ -82,6 +83,7 @@ import QueueOBS from '../obs/QueueOBS.vue'
const defaultSettings = {
keyword: '排队',
enableOnStreaming: false,
queueMaxSize: 10,
allowAllDanmaku: true,
allowFromWeb: true,
@@ -90,7 +92,7 @@ const defaultSettings = {
needTidu: false,
needZongdu: false,
allowGift: true,
giftNames: ['小花花'],
giftNames: [],
minGiftPrice: 0.1,
allowIncreaseByAnyPayment: true,
allowIncreasePaymentBySendGift: true,
@@ -103,6 +105,7 @@ const defaultSettings = {
matchType: KeywordMatchType.Contains,
sortType: QueueSortType.TimeFirst,
giftFilterType: QueueGiftFilterType.Or,
showRequireInfo: true,
} as Setting_Queue
const STATUS_MAP = {
[QueueStatus.Waiting]: '等待中',
@@ -117,6 +120,7 @@ const message = useMessage()
const notice = useNotification()
const isWarnMessageAutoClose = useStorage('Queue.Settings.WarnMessageAutoClose', false)
const isReverse = useStorage('Queue.Settings.Reverse', false)
const volumn = useStorage('Settings.Volumn', 0.5)
const isLoading = ref(false)
@@ -169,6 +173,9 @@ const queue = computed(() => {
list = list.OrderByDescending((q) => q.giftPrice ?? 0).ThenByDescending((q) => q.createAt)
}
}
if (isReverse.value) {
list = list.Reverse()
}
return list.ToArray()
})
const historySongs = computed(() => {
@@ -191,7 +198,7 @@ const table = ref()
async function getAll() {
if (accountInfo.value) {
try {
const data = await QueryGetAPI<ResponseQueueModel[]>(QUEUE_API_URL() + 'get-all', {
const data = await QueryGetAPI<ResponseQueueModel[]>(QUEUE_API_URL + 'get-all', {
id: accountInfo.value.id,
})
if (data.code == 200) {
@@ -214,8 +221,12 @@ async function add(danmaku: EventModel) {
return
}
console.log(`[OPEN-LIVE-QUEUE] 收到 [${danmaku.name}] 的排队请求`)
if (settings.value.enableOnStreaming && accountInfo.value?.streamerInfo?.isStreaming != true) {
message.info('当前未在直播中, 无法添加排队请求. 或者关闭设置中的仅允许直播时加入')
return
}
if (accountInfo.value) {
await QueryPostAPI<ResponseQueueModel>(QUEUE_API_URL() + 'try-add', danmaku).then((data) => {
await QueryPostAPI<ResponseQueueModel>(QUEUE_API_URL + 'try-add', danmaku).then((data) => {
if (data.code == 200) {
if (data.message != 'EventFetcher') {
//如果存在则替换, 否则插入最后
@@ -269,7 +280,7 @@ async function addManual() {
return
}
if (accountInfo.value) {
await QueryPostAPIWithParams<ResponseQueueModel>(QUEUE_API_URL() + 'add', {
await QueryPostAPIWithParams<ResponseQueueModel>(QUEUE_API_URL + 'add', {
name: newQueueName.value,
}).then((data) => {
if (data.code == 200) {
@@ -302,7 +313,7 @@ async function updateStatus(queueData: ResponseQueueModel, status: QueueStatus)
return
}
isLoading.value = true
await QueryGetAPI(QUEUE_API_URL() + 'set-status', {
await QueryGetAPI(QUEUE_API_URL + 'set-status', {
id: queueData.id,
status: status,
})
@@ -313,7 +324,7 @@ async function updateStatus(queueData: ResponseQueueModel, status: QueueStatus)
if (status > QueueStatus.Progressing) {
queueData.finishAt = Date.now()
}
message.success(`已更新队列状态为: ${STATUS_MAP[status]}`)
message.success(`已更新 [${queueData.user?.name}] 队列状态为: ${STATUS_MAP[status]}`)
} else {
console.log(`[OPEN-LIVE-QUEUE] 更新队列状态失败: ${data.message}`)
message.error(`更新队列状态失败: ${data.message}`)
@@ -424,7 +435,7 @@ async function onUpdateFunctionEnable() {
async function updateSettings() {
if (accountInfo.value) {
isLoading.value = true
await QueryPostAPI(QUEUE_API_URL() + 'update-setting', settings.value)
await QueryPostAPI(QUEUE_API_URL + 'update-setting', settings.value)
.then((data) => {
if (data.code == 200) {
message.success('已保存')
@@ -461,7 +472,7 @@ async function deleteQueue(values: ResponseQueueModel[]) {
})
}
async function deactiveAllSongs() {
await QueryGetAPI(QUEUE_API_URL() + 'deactive')
await QueryGetAPI(QUEUE_API_URL + 'deactive')
.then((data) => {
if (data.code == 200) {
message.success('已全部取消')
@@ -663,7 +674,7 @@ function GetGuardColor(level: number | null | undefined): string {
async function updateActive() {
if (!accountInfo.value) return
try {
const data = await QueryGetAPI<ResponseQueueModel[]>(QUEUE_API_URL() + 'get-active', {
const data = await QueryGetAPI<ResponseQueueModel[]>(QUEUE_API_URL + 'get-active', {
id: accountInfo.value?.id,
})
if (data.code == 200) {
@@ -688,6 +699,26 @@ async function updateActive() {
}
} catch (err) {}
}
function blockUser(item: ResponseQueueModel) {
if (item.from != QueueFrom.Danmaku) {
message.error(`[${item.user?.name}] 不是来自弹幕的用户`)
return
}
if (item.user) {
AddBiliBlackList(item.user.uid, item.user.name)
.then((data) => {
if (data.code == 200) {
message.success(`[${item.user?.name}] 已添加到黑名单`)
updateStatus(item, QueueStatus.Cancel)
} else {
message.error(data.message)
}
})
.catch((err) => {
message.error(err)
})
}
}
let timer: any
let updateActiveTimer: any
const updateKey = ref(0)
@@ -695,6 +726,8 @@ onMounted(() => {
if (accountInfo.value) {
settings.value = accountInfo.value.settings.queue
}
props.client.on('danmaku', onGetDanmaku)
props.client.on('gift', onGetGift)
init()
})
onActivated(() => {
@@ -702,8 +735,6 @@ onActivated(() => {
})
function init() {
dispose()
props.client.on('danmaku', onGetDanmaku)
props.client.on('gift', onGetGift)
timer = setInterval(() => {
updateKey.value++
}, 1000)
@@ -712,8 +743,6 @@ function init() {
}, 2000)
}
function dispose() {
props.client.off('danmaku', onGetDanmaku)
props.client.off('gift', onGetGift)
clearInterval(timer)
clearInterval(updateActiveTimer)
}
@@ -721,6 +750,8 @@ onDeactivated(() => {
dispose()
})
onUnmounted(() => {
props.client.off('danmaku', onGetDanmaku)
props.client.off('gift', onGetGift)
dispose()
})
</script>
@@ -784,6 +815,7 @@ onUnmounted(() => {
<NRadioButton :value="QueueSortType.PaymentFist"> 付费价格优先 </NRadioButton>
<NRadioButton :value="QueueSortType.GuardFirst"> 舰长优先 (按等级) </NRadioButton>
</NRadioGroup>
<NCheckbox v-model:checked="isReverse"> 倒序 </NCheckbox>
</NSpace>
</NCard>
<NDivider> {{ queue.length }} </NDivider>
@@ -867,6 +899,21 @@ onUnmounted(() => {
</template>
已完成
</NTooltip>
<NTooltip v-if="queueData.from == QueueFrom.Danmaku">
<template #trigger>
<NPopconfirm @positive-click="blockUser(queueData)">
<template #trigger>
<NButton circle type="warning" style="height: 30px; width: 30px" :loading="isLoading">
<template #icon>
<NIcon :component="PresenceBlocked16Regular" />
</template>
</NButton>
</template>
确定拉黑 {{ queueData.user?.name }}
</NPopconfirm>
</template>
拉黑用户
</NTooltip>
<NTooltip>
<template #trigger>
<NButton circle type="error" style="height: 30px; width: 30px" :loading="isLoading" @click="updateStatus(queueData, QueueStatus.Cancel)">
@@ -937,6 +984,7 @@ onUnmounted(() => {
<NButton @click="updateSettings" type="info" :disabled="!configCanEdit">确定</NButton>
</NInputGroup>
<NSpace align="center">
<NCheckbox v-model:checked="settings.enableOnStreaming" @update:checked="updateSettings" :disabled="!configCanEdit"> 仅在直播时才允许加入 </NCheckbox>
<NCheckbox v-model:checked="settings.allowAllDanmaku" @update:checked="updateSettings" :disabled="!configCanEdit"> 允许所有用户加入 </NCheckbox>
<template v-if="!settings.allowAllDanmaku">
<NInputGroup style="width: 270px">
@@ -979,7 +1027,9 @@ onUnmounted(() => {
</NRadioGroup>
</span>
</template>
<NCheckbox v-model:checked="settings.allowIncreasePaymentBySendGift" @update:checked="updateSettings" :disabled="!configCanEdit"> 在队列中时允许继续发送礼物累计付费量 (仅限上方设定的礼物) </NCheckbox>
<NCheckbox v-model:checked="settings.allowIncreasePaymentBySendGift" @update:checked="updateSettings" :disabled="!configCanEdit">
在队列中时允许继续发送礼物累计付费量 (仅限上方设定的礼物)
</NCheckbox>
<NCheckbox v-model:checked="settings.allowIncreasePaymentBySendGift" @update:checked="updateSettings" :disabled="!configCanEdit"> 允许发送任意礼物来叠加付费量 </NCheckbox>
</NSpace>
<NDivider> 冷却 (单位: ) </NDivider>
@@ -1006,6 +1056,8 @@ onUnmounted(() => {
<NButton @click="updateSettings" type="info" :disabled="!configCanEdit">确定</NButton>
</NInputGroup>
</NSpace>
<NDivider> OBS </NDivider>
<NCheckbox v-model:checked="settings.showRequireInfo" :disabled="!configCanEdit" @update:checked="updateSettings"> 显示底部的需求信息 </NCheckbox>
<NDivider> 其他 </NDivider>
<NCheckbox v-model:checked="isWarnMessageAutoClose"> 自动关闭加入队列失败时的提示消息 </NCheckbox>
</NSpace>