Skip to content

Commit 413c2f6

Browse files
authored
chore: add new option with_torrent. (#28)
1 parent be7d772 commit 413c2f6

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

examples/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ api = "http://localhost:8000"
2020
dms = [114514, 1919810]
2121
groups = [114514, 1919810]
2222
delay = 200
23+
with_torrent = true

src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub struct QQBotConfig {
3434
pub groups: Vec<u64>,
3535
/// The delay between two messages. (ms)
3636
pub delay: u64,
37+
/// If the message contains torrents' URLs.
38+
pub with_torrent: bool,
3739
}
3840

3941
#[derive(Debug, Default, Serialize, Deserialize)]

src/notifier/qq.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,25 @@ impl QQNotifier {
116116
}
117117

118118
fn wrap_item(notifier: &Notifier, source: &str, item: &Item) -> Vec<Message> {
119-
vec![
120-
Message {
121-
msg_type: "node".to_string(),
122-
data: Data {
123-
sender_name: notifier.conf.name.clone(),
124-
sender_uin: notifier.conf.uin.clone(),
125-
content: format!("{}:\n{} ({})", source, item.title, item.pub_date),
126-
},
119+
let mut messages = vec![Message {
120+
msg_type: "node".to_string(),
121+
data: Data {
122+
sender_name: notifier.conf.name.clone(),
123+
sender_uin: notifier.conf.uin.clone(),
124+
content: format!("{}:\n{} ({})", source, item.title, item.pub_date),
127125
},
128-
Message {
126+
}];
127+
if notifier.conf.with_torrent {
128+
messages.push(Message {
129129
msg_type: "node".to_string(),
130130
data: Data {
131131
sender_name: notifier.conf.name.clone(),
132132
sender_uin: notifier.conf.uin.clone(),
133133
content: item.url.clone(),
134134
},
135-
},
136-
]
135+
});
136+
}
137+
messages
137138
}
138139

139140
async fn send_private_msg(notifier: &Notifier, msg: Vec<Message>) -> Result<()> {

0 commit comments

Comments
 (0)