Skip to content

Commit

Permalink
feat: 增加粉丝牌更换功能
Browse files Browse the repository at this point in the history
  • Loading branch information
OToNaShiAKi committed Jun 28, 2022
1 parent a824485 commit b3b449b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
GetLoginInfo,
ClickRedPocket,
GetTrackLiveInfo,
MedalWall,
ChangeMedal,
} from "./plugins/axios";
import { writeFile, mkdir } from "fs/promises";
import { join } from "path";
Expand Down Expand Up @@ -228,3 +230,7 @@ ipcMain.on("Live", (event, roomid) => {
const win = AllWindows.other && BrowserWindow.fromId(AllWindows.other);
win && win.webContents.send("Live", roomid);
});

ipcMain.handle("MedalWall", MedalWall);

ipcMain.on("ChangeMedal", ChangeMedal);
3 changes: 2 additions & 1 deletion src/pages/main/views/Live.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default {
}),
created() {
Socket.plugin = this;
const uid = this.$store.state.cookie.match(/DedeUserID=([^;]+);/);
this.uid = uid[1];
},
methods: {
...mapMutations(["Notify"]),
Expand Down Expand Up @@ -94,7 +96,6 @@ export default {
} else sockets.splice(index, 1);
}
const result = await ipcRenderer.invoke("GetWebSocket", sockets);
this.uid = result[0] ? result[0].uid : "";
for (const item of result) {
const socket = new Socket(item);
this.sockets[item.roomid] = socket;
Expand Down
27 changes: 17 additions & 10 deletions src/pages/main/views/Room.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,8 @@
添加
</v-btn>
</section>
<v-subheader>弹幕颜色、模式</v-subheader>
<section class="d-flex align-center">
<v-select
class="mr-3"
:messages="message"
:items="rooms"
v-model="id"
label="房间"
/>
<v-select class="mr-3" :items="rooms" v-model="id" label="房间" />
<v-select
class="mr-3"
:items="modes[id].colors"
Expand All @@ -71,6 +64,16 @@
提交
</v-btn>
</section>
<v-chip-group
column
color="primary"
@change="change"
:value="medals[0] && medals[0].value"
>
<v-chip v-for="v of medals" outlined :value="v.value" :key="v.value">
{{ v.medal_name }}
</v-chip>
</v-chip-group>
</section>
</template>

Expand All @@ -88,7 +91,7 @@ export default {
name: "",
id: "",
modes: { "": { colors: [], modes: [] } },
message: "房间配置正在请求",
medals: [],
}),
computed: {
...mapState(["rooms"]),
Expand All @@ -104,7 +107,8 @@ export default {
)
);
for (const item of modes) this.modes[item.roomid] = item;
this.message = "";
const uid = this.$store.state.cookie.match(/DedeUserID=([^;]+);/);
this.medals = await ipcRenderer.invoke("MedalWall", uid[1]);
},
methods: {
...mapMutations(["ChangeSelect", "ChangeRooms", "Notify"]),
Expand Down Expand Up @@ -133,6 +137,9 @@ export default {
);
this.Notify(`房间${this.id}设置${result ? "成功" : "失败"}`);
},
change(value) {
value && ipcRenderer.send("ChangeMedal", value);
},
},
};
</script>
31 changes: 31 additions & 0 deletions src/plugins/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,34 @@ export const GetTrackLiveInfo = async (event, room_id) => {
return { room_id, live_status: 0 };
}
};

export const MedalWall = async (event, target_id) => {
try {
const { list } = await Bilibili.get("/xlive/web-ucenter/user/MedalWall", {
params: { target_id },
});
return list
.sort((a, b) => b.wearing_status - a.wearing_status)
.map(({ medal_info }) => ({
value: medal_info.medal_id,
medal_name: medal_info.medal_name,
}));
} catch (error) {
return [];
}
};

export const ChangeMedal = async (event, medal_id) => {
try {
return await Bilibili.post(
"/xlive/app-ucenter/v1/fansMedal/wear",
QS.stringify({
medal_id,
csrf: Bilibili.defaults.data.csrf,
csrf_token: Bilibili.defaults.data.csrf_token,
})
);
} catch (error) {
return false;
}
};
4 changes: 2 additions & 2 deletions src/plugins/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export default class Socket {
};
}
},
room_admin_entrance: ({ uid }, socket) => {
ROOM_ADMIN_ENTRANCE: ({ uid }, socket) => {
socket.admin = socket.uid === uid;
},
Live: ({ roomid }) => ipcRenderer.send("Live", roomid),
LIVE: ({ roomid }) => ipcRenderer.send("Live", roomid),
};
static AutoClickRedPocket = !AutoClickRedPocket;
static plugin = null;
Expand Down

0 comments on commit b3b449b

Please sign in to comment.