Public Access
Add version command, implement Docker support, make sqlx offline work
Run cargo test / Run tests (push) Failing after 3m2s
Run cargo test / Run tests (push) Failing after 3m2s
This commit is contained in:
1 parent
6f5d66a0bc
commit
b06bb882a8
24 files changed
+405
-6
No files matched your search
@@ -2,8 +2,10 @@ pub mod ping;
|
||||
pub mod calc;
|
||||
pub mod manage_admins;
|
||||
pub mod manage_auto_role;
|
||||
pub mod version;
|
||||
|
||||
pub use ping::ping;
|
||||
pub use calc::calc;
|
||||
pub use manage_admins::manage_admins;
|
||||
pub use manage_auto_role::manage_auto_role;
|
||||
pub use version::version;
|
||||
+11
-1
@@ -1,14 +1,24 @@
|
||||
use crate::{Context, Error};
|
||||
use poise::serenity_prelude as sere;
|
||||
use tracing::{trace, debug};
|
||||
use crate::shared_functions::trace_message;
|
||||
|
||||
/// Get the bot's current ping (back and forth)
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
trace!("ping command called by user {} in guild {}", ctx.author().id.get(), ctx.guild_id().unwrap().get());
|
||||
trace!("Calculating ping");
|
||||
let command_time_in_microseconds = ctx.created_at().timestamp_micros();
|
||||
trace!("Saved command time in microseconds");
|
||||
let current_time_in_microseconds = sere::Timestamp::now().timestamp_micros();
|
||||
trace!("Saved current time in microseconds");
|
||||
let ping = (current_time_in_microseconds - command_time_in_microseconds) / 500;
|
||||
trace!("Calculated ping: {}", ping);
|
||||
// We divide by 1000 since we get the time in microseconds, and then multiply by 2 to get the roundtrip time
|
||||
// This is arguably not the best way to calculate ping, since it assumes perfect clock accuracy, but I'm lazy
|
||||
ctx.say(format!("Current ping: {} ms", ping)).await?;
|
||||
let msg = format!("Current ping: {} ms", ping);
|
||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||
ctx.say(msg).await?;
|
||||
debug!("Ping command performed for user {} with ping {}", ctx.author().name, ping);
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use crate::{Context, Error};
|
||||
use tracing::{trace, debug};
|
||||
use crate::shared_functions::trace_message;
|
||||
|
||||
/// Get the bot's current version
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
|
||||
trace!("version command called by user {} in guild {}", ctx.author().id.get(), ctx.guild_id().unwrap().get());
|
||||
trace!("Loading version from environment");
|
||||
let version = std::env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "Unknown".to_string());
|
||||
let msg = format!("Current version: {}", version);
|
||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||
ctx.say(msg).await?;
|
||||
debug!("Version command performed for user {} with version {}", ctx.author().name, version);
|
||||
Ok(())
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
use std::env;
|
||||
use poise::serenity_prelude as sere;
|
||||
use tracing::{info, warn, error, debug, trace};
|
||||
use tracing::{info, error, debug, trace};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
pub mod commands;
|
||||
pub mod event_handler;
|
||||
@@ -72,7 +72,7 @@ async fn main() {
|
||||
event_handler: |ctx, event, framework, user_data| {
|
||||
Box::pin(event_handler::event_handler(ctx, event, framework, user_data))
|
||||
},
|
||||
commands: vec![commands::ping(), commands::calc(), commands::manage_admins(), commands::manage_auto_role()],
|
||||
commands: vec![commands::ping(), commands::calc(), commands::manage_admins(), commands::manage_auto_role(), commands::version()],
|
||||
..Default::default()
|
||||
})
|
||||
.setup(|ctx, _ready, framework| {
|
||||
|
||||
Reference in new issue
Block a user