Skip to content

Commit

Permalink
optimize tips & add bilib sub
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Sep 4, 2024
1 parent 31d1288 commit 9ebdd1c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.0.3
* 优化提示信息

# 2.0.2
* fix DYNAMIC_TYPE_ARTICLE
* 优化Next npm包插件 Task加载
Expand Down
35 changes: 32 additions & 3 deletions apps/bilibili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,50 @@ export default class YukiBili extends Plugin {
const { code, data } = res.data || {};

if (code === -352) {
this.e.reply(`遭遇风控,订阅校验失败~\n请检查Cookie配置后再试~`);
this.e.reply(`遭遇风控,该uid的主页空间动态内容检查失败~\n请检查Cookie配置后再试~\n将跳过校验并保存订阅,请自行检查uid是否正确。`);
logger.mark(`yuki-plugin addDynamicSub Failed:${JSON.stringify(res.data)}`);
return true;
}
const { has_more, items } = data || {};

let infoName: string
if ((code === 0) && (has_more === false)) {
this.e.reply(`订阅校验失败~\nup主uid:${uid} 无效,请核对uid后再试~`);
return;
this.e.reply(`检测到该uid的主页空间动态内容为空,\n执行uid:${uid} 校验...`);

const resp = await new BiliGetWebData(this.e).getBilibiUserInfoByUid(uid);

if (resp.statusText !== 'OK') {
this.e.reply("出了点网络问题,发起uid校验失败,等会再试试吧~");
return false;
}

const { code, data } = resp.data || {};

if (code === -400) {
this.e.reply("发起uid检验请求错误~\n将跳过校验并保存订阅,请自行检查uid是否正确。");
return true;
} else if (code === -403) {
this.e.reply("可能是Cookie过期或api参数错误,\n访问权限不足,发起uid检验失败。\n将跳过校验并保存订阅,请自行检查uid是否正确。");
return true;
} else if (code === -404) {
this.e.reply(`经过校验,该用户不存在,\n输入的uid: ${uid} 无效。订阅失败。`);
return false;
} else {
infoName = data?.name;
this.e.reply(`昵称:${infoName} \nuid:${uid} 校验成功!`);
return true;
}
} else if (code === 0 && (has_more === true)) {
return true;
}

let name: string | number
if (Array.isArray(items)) {
if (items.length > 0) {
name = items[0].modules?.module_author?.name || uid
}
} else if (infoName) {
name = infoName;
} else {
name = uid;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yuki-plugin",
"version": "2.0.2",
"version": "2.0.3-2",
"author": "snowtafir",
"description": "优纪插件,yunzai-V4 关于 微博推送、B站推送 等功能的拓展插件",
"main": "./index",
Expand Down
14 changes: 7 additions & 7 deletions utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ declare const logger: any;
* Config 类用于管理配置文件的读取和监听
*/
class Config {
readonly versionPath: string;
readonly packageJsonPath: string;
readonly defaultConfigPath: string;
readonly userConfigPath: string;
defaultConfig: Record<string, any>;
userConfig: Record<string, any>;
watcher: Record<string, chokidar.FSWatcher>;

constructor() {
this.versionPath = path.join(_paths.pluginPath, 'CHANGELOG.md');
this.packageJsonPath = path.join(_paths.pluginPath, 'package.json');
/** 默认设置 */
this.defaultConfigPath = path.join(_paths.pluginPath, 'defaultConfig');
this.defaultConfig = {};
Expand Down Expand Up @@ -177,14 +177,14 @@ class Config {
this.saveConfig("config", appDir, functionName, config); // 保存更新后的配置
}

/** 读取CHANGELOG.md文件,获取最新版本号*/
/** 读取package.json文件,获取最新版本号*/
getLatestVersion(): string | null {
const content = fs.readFileSync(this.versionPath, 'utf-8');
const versionPattern = /#\s(\d+\.\d+\.\d+)/g;
const match = versionPattern.exec(content);
const content = fs.readFileSync(this.packageJsonPath, 'utf-8');
const packageJson: { [key: string]: any } = JSON.parse(content);
const match: string | null = packageJson.version;

if (match) {
return match[1];
return match;
} else {
return null;
}
Expand Down

0 comments on commit 9ebdd1c

Please sign in to comment.