From 15968a8ec6197017d8b5347eded15d95e102306e Mon Sep 17 00:00:00 2001 From: Nanako <469449812@qq.com> Date: Tue, 10 Dec 2024 13:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=AF=E8=83=BD=E7=9A=84?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=20=E4=BF=AE=E5=A4=8DApiKey=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=B6=88=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rcappsconfig | 2 +- PicSearcherApp.js | 45 +++++++++++++++++++++++++++++++++++--------- PicSearcherApp.ts | 48 ++++++++++++++++++++++++++++++++++++++--------- app.json | 4 ++-- 4 files changed, 78 insertions(+), 21 deletions(-) diff --git a/.rcappsconfig b/.rcappsconfig index bf8a0d6..b8244ac 100644 --- a/.rcappsconfig +++ b/.rcappsconfig @@ -1,5 +1,5 @@ { - "url": "http://192.168.1.104:3010", + "url": "https://nanako.site:51304", "username": "Nanako", "password": "Nasiko@90", "ignoredFiles": [ diff --git a/PicSearcherApp.js b/PicSearcherApp.js index 97ebe7a..68d5fce 100644 --- a/PicSearcherApp.js +++ b/PicSearcherApp.js @@ -87,16 +87,16 @@ const defaultSauceNAOResponse = { }; let myLogger; let SauceNAOErrStr; +const sauceNAOApiKeyID = 'sauceNAO_api_key'; class PicSearcherApp extends App_1.App { constructor(info, logger, accessors) { super(info, logger, accessors); this.rootUrl = ''; - this.sauceNAOApiKey = ''; + this.sauceNAOApiKey = 'ac635e5f5011234871260aac1d37ac8360ed979c'; myLogger = logger; } async initialize(configurationExtend, environmentRead) { this.rootUrl = await environmentRead.getEnvironmentVariables().getValueByName('ROOT_URL'); - this.sauceNAOApiKey = await environmentRead.getSettings().getValueById('SauceNAOApiKey'); myLogger.log('rootUrl:', this.rootUrl); return super.initialize(configurationExtend, environmentRead); } @@ -114,20 +114,20 @@ class PicSearcherApp extends App_1.App { await sendSearchResults(modify, message.room, result, author); } async onSettingUpdated(setting, configurationModify, read, http) { - if (setting.id === 'SauceNAOApiKey') { + if (setting.id === sauceNAOApiKeyID) { this.sauceNAOApiKey = setting.value; } return super.onSettingUpdated(setting, configurationModify, read, http); } async extendConfiguration(configuration, environmentRead) { await configuration.settings.provideSetting({ - id: 'SauceNAOApiKey', + id: sauceNAOApiKeyID, type: settings_1.SettingType.STRING, packageValue: '', required: true, public: false, - i18nLabel: 'searcher_api_key_label', - i18nDescription: 'searcher_api_key_description', + i18nLabel: 'sauceNAO_api_key', + i18nDescription: 'sauceNAO_api_key_desc', }); } async sendMessage(textMessage, room, author, modify) { @@ -227,10 +227,12 @@ async function sendSearchResults(modify, room, results, appUser) { continue; } const color = getInterpolatedColor(similarityValue); + const titleText = data.title || '未知标题'; const attachmentObject = { title: { - value: `${data.title} (${header.similarity}%)`, + value: `${titleText} (${header.similarity}%)`, }, + text: header.index_name, thumbnailUrl: header.thumbnail, collapsed: attachments.length !== 0, color, @@ -249,7 +251,7 @@ async function sendSearchResults(modify, room, results, appUser) { }); } } - if (data.pixiv_id) { + if (data.member_id) { attachmentObject.actions.push({ type: messages_1.MessageActionType.BUTTON, text: '作者Pixiv', @@ -298,9 +300,34 @@ async function sendSearchResults(modify, room, results, appUser) { url: `https://www.imdb.com/title/${data.imdb_id}`, }); } + if (data.member_name !== undefined) { + attachmentObject.author = { + name: data.member_name, + }; + } + if (data.author_name !== undefined) { + attachmentObject.author = { + name: data.author_name, + }; + } + if (Array.isArray(data.creator)) { + attachmentObject.author = { + name: data.creator.join(', '), + }; + } + if (data.eng_name !== undefined) { + attachmentObject.author = { + name: data.eng_name, + }; + } + if (data.jp_name !== undefined) { + attachmentObject.author = { + name: data.jp_name, + }; + } attachments.push(attachmentObject); } - const successStr = `搜索成功,短时间内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit},长时间内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`; + const successStr = `搜索成功,30秒内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit},24小时内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`; const text = attachments.length > 0 ? successStr : SauceNAOErrStr.length > 0 ? SauceNAOErrStr : '没有找到相关结果'; const messageBuilder = modify.getCreator().startMessage() .setRoom(room) diff --git a/PicSearcherApp.ts b/PicSearcherApp.ts index e72d186..2120f1b 100644 --- a/PicSearcherApp.ts +++ b/PicSearcherApp.ts @@ -222,10 +222,11 @@ const defaultSauceNAOResponse: ISauceNAOResponse = { let myLogger: ILogger; let SauceNAOErrStr: string; +const sauceNAOApiKeyID = 'sauceNAO_api_key'; export class PicSearcherApp extends App implements IPostMessageSent { private rootUrl: string = ''; - private sauceNAOApiKey: string = ''; + private sauceNAOApiKey: string = 'ac635e5f5011234871260aac1d37ac8360ed979c'; constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { super(info, logger, accessors); @@ -234,7 +235,6 @@ export class PicSearcherApp extends App implements IPostMessageSent { public async initialize(configurationExtend: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise { this.rootUrl = await environmentRead.getEnvironmentVariables().getValueByName('ROOT_URL'); - this.sauceNAOApiKey = await environmentRead.getSettings().getValueById('SauceNAOApiKey'); myLogger.log('rootUrl:', this.rootUrl); return super.initialize(configurationExtend, environmentRead); } @@ -256,7 +256,7 @@ export class PicSearcherApp extends App implements IPostMessageSent { } public async onSettingUpdated(setting: ISetting, configurationModify: IConfigurationModify, read: IRead, http: IHttp): Promise { - if (setting.id === 'SauceNAOApiKey') { + if (setting.id === sauceNAOApiKeyID) { this.sauceNAOApiKey = setting.value; } return super.onSettingUpdated(setting, configurationModify, read, http); @@ -264,13 +264,13 @@ export class PicSearcherApp extends App implements IPostMessageSent { protected async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise { await configuration.settings.provideSetting({ - id: 'SauceNAOApiKey', + id: sauceNAOApiKeyID, type: SettingType.STRING, packageValue: '', required: true, public: false, - i18nLabel: 'searcher_api_key_label', - i18nDescription: 'searcher_api_key_description', + i18nLabel: 'sauceNAO_api_key', + i18nDescription: 'sauceNAO_api_key_desc', }); } @@ -419,11 +419,13 @@ async function sendSearchResults( // Dynamically generate color const color = getInterpolatedColor(similarityValue); + const titleText = data.title || '未知标题'; const attachmentObject: IMessageAttachment = { title: { - value: `${data.title} (${header.similarity}%)`, // Title content + value: `${titleText} (${header.similarity}%)`, // Title content } as IMessageAttachmentTitle, + text: header.index_name, thumbnailUrl: header.thumbnail, // Optional: Image URL collapsed: attachments.length !== 0, // First one expanded, others collapsed color, // Dynamically set color @@ -443,7 +445,9 @@ async function sendSearchResults( } as IMessageAction); } } - if (data.pixiv_id) { + + // Add more buttons for different sources + if (data.member_id) { attachmentObject.actions.push({ type: MessageActionType.BUTTON, text: '作者Pixiv', @@ -493,10 +497,36 @@ async function sendSearchResults( } as IMessageAction); } + if (data.member_name !== undefined) { + attachmentObject.author = { + name: data.member_name, + } as IMessageAttachmentAuthor; + } + if (data.author_name !== undefined) { + attachmentObject.author = { + name: data.author_name, + } as IMessageAttachmentAuthor; + } + if (Array.isArray(data.creator)) { + attachmentObject.author = { + name: data.creator.join(', '), + } as IMessageAttachmentAuthor; + } + if (data.eng_name !== undefined) { + attachmentObject.author = { + name: data.eng_name, + } as IMessageAttachmentAuthor; + } + if (data.jp_name !== undefined) { + attachmentObject.author = { + name: data.jp_name, + } as IMessageAttachmentAuthor; + } + attachments.push(attachmentObject); } - const successStr = `搜索成功,短时间内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit},长时间内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`; + const successStr = `搜索成功,30秒内剩余查询次数:${results.header.short_remaining}/${results.header.short_limit},24小时内剩余查询次数:${results.header.long_remaining}/${results.header.long_limit}`; const text = attachments.length > 0 ? successStr : SauceNAOErrStr.length > 0 ? SauceNAOErrStr : '没有找到相关结果'; const messageBuilder = modify.getCreator().startMessage() diff --git a/app.json b/app.json index a5b64b9..0c3b7a3 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,6 @@ { - "id": "bf4f0997-e7b7-40ff-b2b7-ba2ce5a15542", - "version": "0.0.2", + "id": "bf4f0997-e7b7-40ff-b2b7-ba2ce5a15543", + "version": "0.0.3", "requiredApiVersion": "^1.44.0", "iconFile": "favicon.png", "author": {