Preliminary Notes
Since I've set up a blog, I thought I could put some of the miscellaneous simple code I've written here. They are all quite simple, so I don't plan to create a separate repository for each one on Github.
Here I'll first update one about "Bilibili Comics Check-in and Welfare Coupon Exchange", and I might write more in the future when I have time.
Motivation
Bilibili Comics allows you to earn points by checking in daily, and these points can be exchanged for welfare coupons that can be used to purchase comics.
However, the most favorable 100-point coupon is only released in limited quantities at midnight each day.
For this purpose, I wrote two plugins based on NoneBot2 and bilibili-api, and referenced SocialSisterYi/bilibili-API-collect. One is for daily check-in to earn points, and the other is for snatching welfare coupons at midnight. They have been extremely stable so far.
NoneBot2 is fairly easy to use, and I've developed some plugins on it as well. I might share them when I have time.
The effect is as follows:
It seems the success rate is so high that notifications are completely unnecessary
Just in case, I'll still push a notification.
Code
get_sessdata.py
Used to obtain and refresh login information
Where cookie_path is a json file containing the following 5 keys:
- sessdata
- buvid3
- bili_jct
- actimevalue
- dedeuserid
You can obtain them from the cookie after logging in using the browser's InPrivate mode. For details, see bilibili-api documentation
checkin.py
A simple NoneBot2 plugin that can be manually executed by sending /漫画签到 to the QQ bot, and also runs at a scheduled time each day and reports the result.
I haven't made it generic for all QQ bot friends to use, so it only supports sending to the QQ bot administrator.
Of course, if you want to use it, you could consider changing it to run directly with cron and find another way to push notifications or not push at all.
exchange.py
A NoneBot2 plugin for redeeming at midnight each day. It actually starts running at 23:59 and performs preprocessing, then checks the system time and redeems exactly at midnight. Therefore, ensure the system time is accurate and synchronize it periodically:
The NoneBot2 logic is similar to the check-in plugin above. Just look at the exchange_func function to understand the redemption logic. The code is as follows: