Diff
Logged in as anonymous

Differences From Artifact [a89bbcb26a]:

To Artifact [8a3bc181d9]:


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
98
99
100
101
102
103
104




105

106
107
108
109
110
111
112







-
-
-
-

-







				.bind(*id)
				.bind(owner)
				.fetch_one(&mut conn).await
				.with_context(|| format!("Query source:\n{:?}", &self.pool))?;
			drop(conn);
			let channel_id: i64 = row.try_get("channel_id")?;
			let url: &str = row.try_get("url")?;
			/*let url: Cow<'a, str> = match row.try_get("url") {
				Ok(x) => String::from(x).to_owned().into(),
				Err(err) => bail!("Test"),
			};*/
			let iv_hash: Option<&str> = row.try_get("iv_hash")?;
			//let url_re: Option<sedregex::ReplaceCommand> = match row.try_get("url_re")? {
			let url_re = match row.try_get("url_re")? {
				Some(x) => Some(sedregex::ReplaceCommand::new(x)?),
				None => None,
			};
			let destination = match real {
				true => telegram_bot::UserId::new(channel_id),
				false => telegram_bot::UserId::new(row.try_get("owner")?),
160
161
162
163
164
165
166
167
168

169
170
171

172
173
174
175
176
177
178
155
156
157
158
159
160
161


162



163
164
165
166
167
168
169
170







-
-
+
-
-
-
+







				let exists: bool = row.try_get("exists")?;
				if ! exists {
					if this_fetch == None || *date > this_fetch.unwrap() {
						this_fetch = Some(*date);
					};
					self.tg.send( match iv_hash {
							Some(hash) => telegram_bot::SendMessage::new(destination, format!("<a href=\"https://t.me/iv?url={}&rhash={}\"> </a>{0}", match url_re {
								Some(x) => {
									bail!("Regex hit, result:\n{:#?}", x.execute(url));
								Some(ref x) => x.execute(url).to_string(),
									url
								},
								None => url,
								None => url.to_string(),
							}, hash)),
							None => telegram_bot::SendMessage::new(destination, format!("{}", url)),
						}.parse_mode(telegram_bot::types::ParseMode::Html)).await
						.context("Can't post message:")?;
					sqlx::query("insert into rsstg_post (source_id, posted, url) values ($1, $2, $3);")
						.bind(*id)
						.bind(date)
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
307
308
309
310
311
312
313


314
315
316
317
318
319
320







-
-







			let mut queue = sqlx::query("select source_id, next_fetch, owner from rsstg_order natural left join rsstg_source where next_fetch < now() + interval '1 minute';")
				.fetch_all(&mut conn).await?;
			for row in queue.iter() {
				let source_id: i32 = row.try_get("source_id")?;
				let owner: i64 = row.try_get("owner")?;
				let next_fetch: DateTime<chrono::Local> = row.try_get("next_fetch")?;
				if next_fetch < now {
					//let clone = self.clone();
					//clone.owner_chat(UserId::new(owner));
					let clone = Core {
						owner_chat: telegram_bot::UserId::new(owner),
						..self.clone()
					};
					tokio::spawn(async move {
						if let Err(err) = clone.check(&source_id, owner, true).await {
							if let Err(err) = clone.send(&format!("🛑 {:?}", err), None, None) {