Skip to content

Commit 8f3e91c

Browse files
committed
[QQ] Allow custom notification text due to demand from a particular user
1 parent f493157 commit 8f3e91c

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

src/config/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ pub struct NotificationSwitchOverride {
277277
pub struct NotificationOption {
278278
#[serde(default = "helper::refl_bool::<false>")]
279279
pub author_name: bool,
280+
281+
// TODO: For temporary use on QQ platform, due to demand from a particular user. We eventually
282+
// want to support custom text via pattern templates (similar to spdlog-rs, but more generic).
283+
// And because they are temporary, we do not currently support their overriding.
284+
pub __live_text: Option<String>,
285+
pub __post_text: Option<String>,
280286
}
281287

282288
serde_impl_default_for!(NotificationOption);
@@ -290,6 +296,8 @@ impl Overridable for NotificationOption {
290296
{
291297
Self {
292298
author_name: new.author_name.unwrap_or(self.author_name),
299+
__live_text: self.__live_text,
300+
__post_text: self.__post_text,
293301
}
294302
}
295303
}
@@ -462,6 +470,8 @@ notify = ["meow", "woof", { ref = "woof", id = 123 }]
462470
},
463471
option: NotificationOption {
464472
author_name: false,
473+
__live_text: None,
474+
__post_text: None,
465475
}
466476
},
467477
chat: telegram::ConfigChat::Id(5678),

src/platform/qq/notify/mod.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ impl Notifier {
150150
}
151151

152152
if let LiveStatusKind::Online { start_time: _ } = live_status.kind {
153-
let message = lagrange::Message::builder()
154-
.image(&live_status.cover_image_url)
155-
.text(format!(
153+
let builder = lagrange::Message::builder().image(&live_status.cover_image_url);
154+
let message = if let Some(custom_live_text) = &self.params.base.option.__live_text {
155+
builder.text(format!("{custom_live_text}\n{}", live_status.live_url))
156+
} else {
157+
builder.text(format!(
156158
"[{}] 🟢 {}{}\n{}",
157159
source.platform.display_name,
158160
if self.params.base.option.author_name {
@@ -163,9 +165,9 @@ impl Notifier {
163165
live_status.title,
164166
live_status.live_url
165167
))
166-
.mention_all_if(self.params.mention_all, true)
167-
.build();
168-
168+
}
169+
.mention_all_if(self.params.mention_all, true)
170+
.build();
169171
self.backend
170172
.send_message(&self.params.chat, message)
171173
.await?;
@@ -227,7 +229,20 @@ impl Notifier {
227229

228230
async fn notify_post(&self, post: &Post, source: &StatusSource) -> anyhow::Result<()> {
229231
let mut builder = lagrange::Message::builder();
230-
builder.ref_text(format!("[{}] ", source.platform.display_name));
232+
233+
if let Some(custom_post_text) = &self.params.base.option.__post_text {
234+
builder.ref_text(custom_post_text);
235+
for url in post
236+
.urls_recursive()
237+
.into_iter()
238+
.filter_map(|url| url.as_clickable())
239+
{
240+
builder.ref_text(format!("{}: {}\n", url.display, url.url));
241+
}
242+
builder.ref_text("\n");
243+
} else {
244+
builder.ref_text(format!("[{}] ", source.platform.display_name));
245+
}
231246

232247
fn append_media<'a>(
233248
builder: &mut lagrange::MessageBuilder,
@@ -264,13 +279,15 @@ impl Notifier {
264279
builder.ref_text(post.content.fallback());
265280
}
266281
}
267-
builder.ref_text("\n");
268-
for url in post
269-
.urls_recursive()
270-
.into_iter()
271-
.filter_map(|url| url.as_clickable())
272-
{
273-
builder.ref_text(format!("\n{}: {}", url.display, url.url));
282+
if self.params.base.option.__post_text.is_none() {
283+
builder.ref_text("\n");
284+
for url in post
285+
.urls_recursive()
286+
.into_iter()
287+
.filter_map(|url| url.as_clickable())
288+
{
289+
builder.ref_text(format!("\n{}: {}", url.display, url.url));
290+
}
274291
}
275292

276293
self.backend

0 commit comments

Comments
 (0)