添加免费礼物感谢开关

This commit is contained in:
xys20071111 2022-10-10 16:22:18 +08:00
parent 7cf982baec
commit dcb617f43d
No known key found for this signature in database
GPG Key ID: 29CB7FFE349CFD03
5 changed files with 12 additions and 10 deletions

View File

@ -8,7 +8,7 @@ interface Message {
data: any; data: any;
} }
const server = new WebSocketServer(config.api.port); const server: WebSocketServer = new WebSocketServer(config.api.port);
const authedClientSet: Set<WebSocketClient> = new Set(); const authedClientSet: Set<WebSocketClient> = new Set();
class APIMsgHandler extends EventEmitter { class APIMsgHandler extends EventEmitter {

View File

@ -27,6 +27,7 @@ interface ConfigStruct {
cold_down_time: number cold_down_time: number
advertiseing_cold_down: number advertiseing_cold_down: number
api: api_config api: api_config
free_gift_action: boolean
} }
const decoder = new TextDecoder('utf-8') const decoder = new TextDecoder('utf-8')

View File

@ -17,11 +17,13 @@ export function receiveGift(data: any) {
return return
} }
logFile.writeSync(Encoding.UTF8.getBytes(`${getTimeString()} ${data.uname} 投喂了${data.super_gift_num}${data.giftName} 价值${data.price / 1000 * data.super_gift_num}\n`)) logFile.writeSync(Encoding.UTF8.getBytes(`${getTimeString()} ${data.uname} 投喂了${data.super_gift_num}${data.giftName} 价值${data.price / 1000 * data.super_gift_num}\n`))
sendDanmaku({ if (config.free_gift_action || data.super_gift_num > 0) {
msg: FormatString(config.danmakus.gift, { name: data.uname, gift: data.giftName }) sendDanmaku({
}) msg: FormatString(config.danmakus.gift, { name: data.uname, gift: data.giftName })
thanksColdDownSet.add(data.uname) })
setTimeout(() => {thanksColdDownSet.delete(data.uname)}, config.cold_down_time) thanksColdDownSet.add(data.uname)
setTimeout(() => { thanksColdDownSet.delete(data.uname) }, config.cold_down_time)
}
} }
export function onTotalGift(data: any) { export function onTotalGift(data: any) {

View File

@ -1,4 +1,4 @@
import { brotli, EventEmitter } from "./Deps.ts"; import { brotli, EventEmitter, WebSocketClient } from "./Deps.ts";
import config from "./Config.ts"; import config from "./Config.ts";
import { printLog } from "./utils/mod.ts"; import { printLog } from "./utils/mod.ts";
import { server as apiServer } from './APIServer.ts' import { server as apiServer } from './APIServer.ts'
@ -125,7 +125,7 @@ export class DanmakuReceiver extends EventEmitter {
const data = JSON.parse(decoder.decode(packetData)); const data = JSON.parse(decoder.decode(packetData));
const cmd = data.cmd.split(":")[0]; const cmd = data.cmd.split(":")[0];
this.emit(cmd, data.info || data.data); this.emit(cmd, data.info || data.data);
apiServer.clients.forEach((client) => { apiServer.clients.forEach((client: WebSocketClient) => {
client.send(JSON.stringify({ cmd, data: data.info || data.data })) client.send(JSON.stringify({ cmd, data: data.info || data.data }))
}) })
offset += length; offset += length;

View File

@ -3,5 +3,4 @@ import * as events from 'https://deno.land/x/events@v1.0.0/mod.ts'
const EventEmitter = events.default const EventEmitter = events.default
export { EventEmitter } export { EventEmitter }
export * as brotli from 'https://deno.land/x/brotli@v0.1.4/mod.ts' export * as brotli from 'https://deno.land/x/brotli@v0.1.4/mod.ts'
export { WebSocketServer } from "https://deno.land/x/websocket@v0.1.4/mod.ts"; export { WebSocketServer, type WebSocketClient } from 'https://deno.land/x/websocket@v0.1.4/mod.ts';
export type { WebSocketClient } from "https://deno.land/x/websocket@v0.1.4/mod.ts";