Skip to content

Commit

Permalink
🚧 Prepping to extract Telegram listener from Bot
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed Nov 4, 2024
1 parent ce710ab commit 650df6a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
20 changes: 1 addition & 19 deletions src/bot.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::{
collections::HashSet,
sync::atomic::{AtomicU64, Ordering},
time::Duration,
};

use bon::bon;
use maud::Render;
use tokio::{time::sleep, try_join};

use crate::{
db::{
Expand Down Expand Up @@ -36,9 +34,7 @@ use crate::{

pub struct Bot {
db: Db,

marktplaats: Marktplaats,
crawl_interval: Duration,

telegram: Telegram,
offset: AtomicU64,
Expand All @@ -54,7 +50,6 @@ impl Bot {
pub async fn new(
db: Db,
marktplaats: Marktplaats,
crawl_interval_secs: u64,
telegram: Telegram,
offset: u64,
telegram_poll_timeout_secs: u64,
Expand All @@ -75,7 +70,6 @@ impl Bot {
let this = Self {
db,
marktplaats,
crawl_interval: Duration::from_secs(crawl_interval_secs),
telegram,
offset: AtomicU64::new(offset),
telegram_poll_timeout_secs,
Expand All @@ -88,19 +82,7 @@ impl Bot {

impl Bot {
/// Run the bot indefinitely.
pub async fn try_run(self) -> Result {
try_join!(self.try_run_telegram(), self.try_run_crawler())?;
Ok(())
}

async fn try_run_crawler(&self) -> Result {
info!("Running crawler…");
loop {
sleep(self.crawl_interval).await;
}
}

async fn try_run_telegram(&self) -> Result {
pub async fn try_run(&self) -> Result {
info!("Running Telegram bot…");
loop {
let updates = GetUpdates::builder()
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ async fn async_main(cli: Cli) -> Result {
Bot::builder()
.db(db)
.marktplaats(marktplaats)
.crawl_interval_secs(cli.crawl_interval_secs)
.telegram(telegram)
.offset(0)
.telegram_poll_timeout_secs(cli.telegram_poll_timeout_secs)
Expand Down
1 change: 1 addition & 0 deletions src/telegram/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{db::query_hash::QueryHash, prelude::*, telegram::render::Link};
/// Builder of `/start` commands with [deep linking][1].
///
/// [1]: https://core.telegram.org/bots/features#deep-linking
#[derive(Clone)]
pub struct CommandBuilder(Url);

#[bon]
Expand Down

0 comments on commit 650df6a

Please sign in to comment.