Skip to content

Commit

Permalink
fix: 更新ws链接,解决信息丢失问题
Browse files Browse the repository at this point in the history
  • Loading branch information
orangelckc committed Jul 19, 2023
1 parent 11349f9 commit 25b8120
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
7 changes: 5 additions & 2 deletions src/api/bilibili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ const validateLoginInfoApi = async () =>

// 获取用户信息
const getUserInfoApi = async () =>
await getQueryData(`${BASE_URL_PREFIX}/x/space/wbi/acc/info`, {
query: { mid: (await getStore(LOGIN_INFO.uid)) }
await getQueryData(`${BASE_URL_PREFIX}/nav`, {
query: { mid: (await getStore(LOGIN_INFO.uid)) },
headers: {
cookie: await getStore(LOGIN_INFO.cookie)
},
});

export {
Expand Down
2 changes: 1 addition & 1 deletion src/constants/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ROOM_INFO_URL =
"https://link.bilibili.com/p/center/index#/my-room/start-live";

// 直播长链接地址
const WEBSOCKET_URL = "ws://broadcastlv.chat.bilibili.com:2244/sub";
const WEBSOCKET_URL = "wss://broadcastlv.chat.bilibili.com/sub";

export {
BASE_URL_PREFIX,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/initSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ const sign_sql = async (data: any) => {
};

const formatUname = (uname: string) => {
if(!uname) return ""

return uname.length > 6 ? uname.slice(0, 6) + "..." : uname;
};

Expand Down
10 changes: 6 additions & 4 deletions src/views/Robot/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ import { initSQL } from '@/utils/initSQL';
// 用户信息
const userInfo = reactive({
avatar: '',
uname: '',
uname: '未登录',
uid: await getStore(LOGIN_INFO.uid),
});
const getUserInfo = async () => {
const result = await getUserInfoApi();
if (!result) {
// getUserInfo();
return;
}
const { name, face } = result;
const { uname, face } = result;
userInfo.avatar = face;
userInfo.uname = name;
userInfo.uname = uname;
};
const logout = () => {
Expand All @@ -51,7 +52,8 @@ onMounted(() => {
<q-header elevated>
<q-toolbar>
<q-avatar>
<q-img :src="userInfo.avatar" spinner-color="white" />
<q-img :src="userInfo.avatar" spinner-color="white" v-if="userInfo.avatar"/>
<span class="i-carbon-user-avatar-filled-alt h-10 w-10" v-else></span>
</q-avatar>
<q-toolbar-title data-tauri-drag-region class="hover:cursor-move">
{{ userInfo.uname }}
Expand Down
53 changes: 23 additions & 30 deletions src/views/Robot/message/robot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const offline = `${manage.robotName}要下线了,感谢大家的陪伴~`;

const welcome = [
`欢迎新朋友们来到${manage.hostName}的直播间~`,
`${manage.hostName}有才有德,有点帅,快来关注他吧~`,
"发发弹幕,可以触发直播间好玩的互动功能哟~"
];

Expand All @@ -70,32 +69,16 @@ const intro = [
];

const bossList = [
{
uid: "349931835",
uname: "纯鱼子酱",
nickname: "小王同学",
text: ",作业写完了么?"
},
{
uid: "677100107",
uname: "犷吉",
nickname: "犷吉姐姐",
text: ",有没有给闹闹带糖啊?"
},
{
{
uid: "409672400",
uname: "cryingwatermelon",
nickname: "西瓜姐姐",
text: ",快来夸夸闹闹吧~"
text: ", 快来夸夸闹闹吧~"
},
{
uid: "79589619",
uname: "小co_hegk",
nickname: "",
text: "夸夸团上线啦,@{up}不要摸鱼啦~"
}
];

const masterList = [405579368 ]

const autoSlice = (str: string) => {
const arr: string[] = [];
if (str.length > 20) {
Expand Down Expand Up @@ -165,6 +148,7 @@ const init_listener = async () => {
data.forEach(async (item: any) => {
if (!active.value) return;


if (item.msg_type === "follow") {
// 关注事件
if (!manage.follow) return;
Expand All @@ -174,7 +158,7 @@ const init_listener = async () => {
// 大佬欢迎词
const boss = bossList.find(boss => boss.uid === "" + item.uid)
if (boss) {
const message = (boss.nickname + boss.text).replaceAll('{up}', formatUname(manage.hostName))
const message = `${boss.nickname}${boss.text}`.replaceAll('{up}', formatUname(manage.hostName))
messages.push(...autoSlice(message));
}

Expand All @@ -196,6 +180,7 @@ const init_listener = async () => {

const data = event.payload as Object[]
data.forEach(async (item: any) => {

const { uname, message, isEmoji, uid, emoji } = item.barrage;
message && !isEmoji && msgList.value.push({ uname, message });
isEmoji && emojiPopList.value.push(emoji);
Expand All @@ -208,11 +193,19 @@ const init_listener = async () => {
if (message && uid !== parseInt(await getStore(LOGIN_INFO.uid))) {
if (message.includes(`@${manage.robotName}`)) {
const question = message.replace(`@${manage.robotName}`, "").trim();
if (question.includes("粉丝数") || question.includes("今日目标")) {
const { by_room_ids } = await getLiveStatusApi(manage.roomid);
const curFans = by_room_ids[manage.roomid].attention;
messages.push(...autoSlice(`@${manage.hostName} 当前粉丝数${curFans},今日已增长${curFans - todayFans},冲~`));
return;

if (masterList.includes(uid)) {
if (question === "直播时间") {
messages.push(`@${manage.hostName}今日直播时长 ${liveTime}分钟`);
return;
}

if (question.includes("粉丝数") || question.includes("今日目标")) {
const { by_room_ids } = await getLiveStatusApi(manage.roomid);
const curFans = by_room_ids[manage.roomid].attention;
messages.push(...autoSlice(`@${manage.hostName} 当前粉丝数${curFans},今日已增长${curFans - todayFans},冲~`));
return;
}
}
// 主人命令
if (uid === 405579368) {
Expand Down Expand Up @@ -240,7 +233,7 @@ const init_listener = async () => {
if (item.barrageType === "like") {
// 点赞事件
if (!manage.like) return;
const message = manage.likeText.replaceAll('{user}', formatUname(item.uname)).replaceAll('{up}', manage.hostName);
const message = manage.likeText.replaceAll('{user}', formatUname(item.barrage.uname)).replaceAll('{up}', manage.hostName);
messages.push(...autoSlice(message));
} else {
!isEmoji && create_danmu_sql({ ...item, roomid: manage.roomid });
Expand Down Expand Up @@ -326,8 +319,8 @@ watch(active, async (value) => {
}
}, 1000 * 3);
} else {
// 计算今日直播时间,增长粉丝数量
messages.push(`@${manage.hostName}今日直播时长 ${liveTime}分钟`);
// 计算今日直播时间
messages.push(`@${manage.hostName}今日直播时长${liveTime}分钟`);
messages.push(offline);
clearInterval(clockInterval);
}
Expand Down

0 comments on commit 25b8120

Please sign in to comment.