Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
[workspace]
members = ["bot", "entity", "migration"]
resolver = "2"
members = ["bot", "entity", "migration"]

[workspace.dependencies]
anyhow = "1"
chrono = "0.4"
chrono-tz = "0.10"
culpa = "1.0"
dotenv = "0.15"
entity = { version = "0.4", path = "./entity" }
entity = { path = "./entity", version = "0.4" }
fern = { version = "0.7", features = ["colored"] }
futures = "0.3"
include_dir = { version = "0.7.4", features = ["glob", "nightly"] }
itertools = "0.14"
kameo = "0.17"
kameo = "0.18"
libbot = { path = "./lib" }
log = "0.4"
migration = { version = "0.4", path = "./migration" }
migration = { path = "./migration", version = "0.4" }
paste = "1"
# plurals = "0.3"
regex = "1"
sea-orm = { version = "1.1", features = [
"macros",
"runtime-tokio-rustls",
"sqlx-postgres",
"with-chrono",
"macros",
"runtime-tokio-rustls",
"sqlx-postgres",
"with-chrono",
] }
sea-orm-migration = { version = "1.1", features = [
"runtime-tokio-rustls",
"sqlx-postgres",
"with-chrono",
"runtime-tokio-rustls",
"sqlx-postgres",
"with-chrono",
] }
serde = { version = "1.0", features = ["derive"] }
teloxide = { version = "0.17", features = ["macros"] }
tera = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
two_timer = { version = "2.2", git = "https://github.com/berkus/two-timer.git", branch = "updated" }
two_timer = { git = "https://github.com/berkus/two-timer.git", branch = "updated", version = "2.2" }

3 changes: 3 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@default:
just --list

deploy: build
cp target/release/bot ../aegl-bot/
build:
Expand Down
2 changes: 1 addition & 1 deletion bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ publish = false

[dependencies]
anyhow.workspace = true
chrono-tz.workspace = true
chrono.workspace = true
chrono-tz.workspace = true
culpa.workspace = true
dotenv.workspace = true
entity.workspace = true
Expand Down
31 changes: 27 additions & 4 deletions bot/src/actors/bot_actor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
crate::{
actors::reminder_actor::{
ReminderActor, ScheduleNextDay, ScheduleNextMinute, ScheduleNextWeek,
},
actors::reminder_actor::{ReminderActor, Reminders, ScheduleNextDay, ScheduleNextWeek},
commands::*,
BotCommand,
},
culpa::throws,
kameo::{
actor::ActorRef,
error::Infallible,
Expand All @@ -28,6 +27,7 @@ pub struct BotActor {
update_sender: broadcast::Sender<ActorUpdateMessage>,
connection_pool: DatabaseConnection,
commands_list: Vec<(String, String)>,
reminders: Option<ActorRef<ReminderActor>>, // we must keep a ref, but late init
}

unsafe impl Send for BotActor {}
Expand Down Expand Up @@ -67,6 +67,7 @@ impl BotActor {
update_sender,
connection_pool,
commands_list: vec![],
reminders: None,
}
}

Expand Down Expand Up @@ -134,6 +135,8 @@ impl Actor for BotActor {
new_command!(ChatIdCommand, bot_actor);
new_command!(D1weekCommand, bot_actor);
new_command!(D2weekCommand, bot_actor);
#[cfg(debug_assertions)]
new_command!(DebugCommand, bot_actor);
new_command!(EditCommand, bot_actor);
new_command!(EditGuardianCommand, bot_actor);
new_command!(HelpCommand, bot_actor);
Expand All @@ -153,10 +156,13 @@ impl Actor for BotActor {
));

// Schedule first run, the actor handler will reschedule.
let _ = reminders.tell(ScheduleNextMinute).await;
log::trace!("Scheduling first tick to {reminders:?}");
let _ = reminders.tell(Reminders).await;
let _ = reminders.tell(ScheduleNextDay).await;
let _ = reminders.tell(ScheduleNextWeek).await;

bot_actor.reminders = Some(reminders);

Ok(bot_actor)
}
}
Expand Down Expand Up @@ -185,6 +191,9 @@ pub enum Notify {
On,
}

#[derive(Clone, Debug)]
pub struct Debug;

#[derive(Clone, Debug)]
pub struct SendMessage(pub String, pub ChatId, pub Format, pub Notify);

Expand Down Expand Up @@ -289,3 +298,17 @@ impl Message<ListCommands> for BotActor {
.try_send(); // @todo use unbounded mailbox for bot_actor? prolly not
}
}

impl Message<Debug> for BotActor {
type Reply = anyhow::Result<String>;

#[throws(anyhow::Error)]
async fn handle(&mut self, _msg: Debug, _ctx: &mut Context<Self, Self::Reply>) -> String {
log::debug!("Debug");

self.reminders.as_ref().unwrap().kill();

let res = self.reminders.as_ref().is_some_and(|r| r.is_alive());
format!("{res}")
}
}
Loading