Skip to content
Open
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
119 changes: 119 additions & 0 deletions internal/standup-bot/Cargo.lock

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

2 changes: 2 additions & 0 deletions internal/standup-bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
chrono = "0.4.43"
chrono-tz = "0.10.4"
bb8-redis = "0.26.0"
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["json", "env-filter"] }
3 changes: 3 additions & 0 deletions internal/standup-bot/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ DISCORD_GUILD_ID=
DISCORD_CHANNEL_ID=

REDIS_URI=

# Leave unset locally.
ENVIRONMENT=
2 changes: 2 additions & 0 deletions internal/standup-bot/example.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ DISCORD_GUILD_ID=
DISCORD_CHANNEL_ID=

REDIS_URI=

ENVIRONMENT=production
19 changes: 12 additions & 7 deletions internal/standup-bot/src/discord/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ use serenity::{
},
async_trait,
};
use tracing::{
error,
info,
warn,
};

use crate::{
common::latch::CountdownLatch,
Expand All @@ -44,12 +49,12 @@ impl Handler {
return Ok(());
};

println!("Received command interaction: {command:#?}");
info!("Received command interaction: {command:#?}");

let content = match command.data.name.as_str() {
"hello" => Some(commands::hello::run(&command.data.options())),
cmd => {
eprintln!("Command {cmd} not supported");
warn!("Command {cmd} not supported");
None
}
};
Expand Down Expand Up @@ -86,7 +91,7 @@ impl Handler {

async fn on_ready(&self, ctx: Context) -> anyhow::Result<()> {
let commands = get_commands(self.guild_id, ctx).await?;
println!("I now have the following guild slash commands: {commands:#?}");
info!("I now have the following guild slash commands: {commands:#?}");

Ok(())
}
Expand All @@ -96,21 +101,21 @@ impl Handler {
impl EventHandler for Handler {
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
if let Err(e) = self.on_interaction(ctx, interaction).await {
eprintln!("interaction handler failed: {e:#?}");
error!("interaction handler failed: {e:#?}");
}
}

async fn message(&self, _ctx: Context, new_message: Message) {
if let Err(e) = self.on_message(new_message).await {
eprintln!("message handler failed: {e:#?}");
error!("message handler failed: {e:#?}");
}
}

async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
info!("{} is connected!", ready.user.name);

if let Err(e) = self.on_ready(ctx).await {
eprintln!("ready handler failed: {e:#?}");
error!("ready handler failed: {e:#?}");
}

self.latch.count_down();
Expand Down
12 changes: 8 additions & 4 deletions internal/standup-bot/src/discord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use serenity::{
},
http::Http,
};
use tracing::{
error,
info,
};

use crate::{
common::latch::CountdownLatch,
Expand Down Expand Up @@ -64,7 +68,7 @@ impl DiscordClient {

tokio::spawn(async move {
if let Err(e) = client.start().await {
eprintln!("Client error: {e:?}");
error!("Client error: {e:?}");
}
});

Expand All @@ -79,7 +83,7 @@ impl DiscordClient {
}

pub async fn send_standup_message(&self) -> Result<u64, DiscordClientError> {
println!("Sending standup message!");
info!("Sending standup message!");

let embed = CreateEmbed::new()
.title("Codebloom Standup")
Expand All @@ -99,14 +103,14 @@ impl DiscordClient {
let msg = channel
.send_message(self.http.as_ref(), create_msg)
.await
.inspect_err(|e| eprintln!("Error sending message: {e:#?}"))?;
.inspect_err(|e| error!("Error sending message: {e:#?}"))?;

let thread_builder = CreateThread::new("Daily Standup Thread");

let thread = channel
.create_thread_from_message(self.http.as_ref(), msg.id, thread_builder)
.await
.inspect_err(|e| eprintln!("Error creating thread: {e:#?}"))?;
.inspect_err(|e| error!("Error creating thread: {e:#?}"))?;

Ok(thread.id.get())
}
Expand Down
Loading
Loading