197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
+
|
for row in queue {
if let Some(next_fetch) = row.next_fetch {
if next_fetch < now {
if let (Some(owner), Some(source_id)) = (row.owner, row.source_id) {
let clone = Core {
owner_chat: ChatPeerId::from(owner),
..self.clone()
};
let source = {
let mut conn = self.db.begin().await?;
match conn.get_one(owner, source_id).await {
Ok(Some(source)) => source.to_string(),
Ok(None) => "Source not found in database?".to_string(),
Err(err) => format!("Failed to fetch source data:\n{err}"),
}
};
task::spawn(async move {
if let Err(err) = clone.check(source_id, true).await {
if let Err(err) = clone.send(&format!("š {err:?}"), None, None).await {
if let Err(err) = clone.send(&format!("{source}\nš {err:?}"), None, None).await {
eprintln!("Check error: {err:?}");
// clone.disable(&source_id, owner).await.unwrap();
};
};
});
}
} else if next_fetch - now < delay {
delay = next_fetch - now;
}
}
};
Ok(delay.to_std()?)
}
pub async fn list (&self, owner: UserPeerId) -> Result<String> {
let mut reply: Vec<Cow<str>> = vec![];
let mut reply: Vec<String> = vec![];
reply.push("Channels:".into());
let mut conn = self.db.begin().await?;
for row in conn.get_list(owner).await? {
reply.push(format!("\n\\#ļøā£ {} \\*ļøā£ `{}` {}\nš `{}`", row.source_id, row.channel,
match row.enabled {
true => "š enabled",
false => "ā disabled",
}, row.url).into());
if let Some(hash) = &row.iv_hash {
reply.push(format!("IV: `{hash}`").into());
}
if let Some(re) = &row.url_re {
reply.push(format!("RE: `{re}`").into());
reply.push(row.to_string());
}
};
Ok(reply.join("\n"))
Ok(reply.join("\n\n"))
}
}
impl UpdateHandler for Core {
async fn handle (&self, update: Update) {
if let UpdateType::Message(msg) = update.update_type {
if let Ok(cmd) = Command::try_from(msg) {
|