diff --git a/src/db/push_task.rs b/src/db/push_task.rs index 4694a03..fe19f41 100644 --- a/src/db/push_task.rs +++ b/src/db/push_task.rs @@ -265,6 +265,9 @@ pub struct TelegramPushConfig { pub allow_failed: bool, /// Download media first and send media to telegram server directly. pub download_media: Option, + /// Add pixiv tag link to tag + #[serde(default = "default_false")] + pub add_link_to_tag: bool, } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/src/server/push/task/pixiv_send_message.rs b/src/server/push/task/pixiv_send_message.rs index 588aecf..1d8fb4f 100644 --- a/src/server/push/task/pixiv_send_message.rs +++ b/src/server/push/task/pixiv_send_message.rs @@ -389,6 +389,78 @@ impl RunContext { } } + pub fn add_tags_tg(&self, text: &mut String, cfg: &TelegramPushConfig) { + if cfg.add_ai_tag && self.is_ai() { + text.push_str("#"); + text.push_str(&gettext("AI generated").replace(' ', "_")); + text.push_str(" "); + } + if let Some(i) = self.illust.as_ref() { + for tag in i.tags() { + if let Some(name) = tag.name() { + if cfg.add_link_to_tag { + text.push_str(&format!( + "#{} ", + name, name + )); + } else { + text.push('#'); + text.push_str(&name.replace(' ', "_")); + text.push(' '); + } + if cfg.add_translated_tag { + if let Some(t) = tag.translated_name() { + if cfg.add_link_to_tag { + text.push_str(&format!( + "#{} ", + name, t + )); + } else { + text.push('#'); + text.push_str(&t.replace(' ', "_")); + text.push(' '); + } + } + } + } + } + text.push_str("\n"); + return; + } + if let Some(d) = self.data.as_ref() { + for tag in d["tags"]["tags"].members() { + if let Some(name) = &tag["tag"].as_str() { + if cfg.add_link_to_tag { + text.push_str(&format!( + "#{} ", + name, name + )); + } else { + text.push('#'); + text.push_str(&name.replace(' ', "_")); + text.push(' '); + } + if self.add_translated_tag() { + if let Some(t) = &tag["translation"]["en"].as_str() { + if cfg.add_link_to_tag { + text.push_str(&format!( + "#{} ", + name, t + )); + } else { + text.push('#'); + text.push_str(&t.replace(' ', "_")); + text.push(' '); + } + } + } + } + } + text.push_str("\n"); + return; + } + } + pub async fn send_every_push(&self, cfg: &EveryPushConfig) -> Result<(), PixivDownloaderError> { let client = EveryPushClient::new(&cfg.push_server); match cfg.typ { @@ -737,6 +809,9 @@ impl RunContext { } text += &convert_description_to_tg_html(self.desc().unwrap_or(""))?; text.push('\n'); + if cfg.add_tags { + self.add_tags_tg(&mut text, cfg); + } if cfg.author_locations.contains(&AuthorLocation::Bottom) { if let Some(a) = &author { text.push_str(gettext("by "));