Release 0.2.0
This commit is contained in:
1 parent
97407f7eed
commit
48408cba61
44 files changed
+1874
-514
No files matched your search
@@ -1,7 +1,9 @@
|
||||
pub mod git;
|
||||
pub mod ping;
|
||||
pub mod stats;
|
||||
pub mod version;
|
||||
|
||||
pub use git::git;
|
||||
pub use ping::ping;
|
||||
pub use stats::stats;
|
||||
pub use version::version;
|
||||
@@ -0,0 +1,33 @@
|
||||
use crate::messaging::trace_message;
|
||||
use crate::{Context, Error, web};
|
||||
use tracing::{debug, trace};
|
||||
|
||||
#[doc = "Show archive statistics"]
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
pub async fn stats(ctx: Context<'_>) -> Result<(), Error> {
|
||||
trace!(
|
||||
"stats command called by user {} in guild {}",
|
||||
ctx.author().id.get(),
|
||||
ctx.guild_id().unwrap().get()
|
||||
);
|
||||
let stats = web::archive_stats(&ctx.data().pool).await?;
|
||||
let msg = format!(
|
||||
"# Archive Statistics\n## Messages\nArchived messages: {}\nArchived users: {}\nChannels: {}\nServers: {}\n## Storage usage\nTotal archive: {}\nMessages and metadata: {}\nAttachments: {}",
|
||||
stats.messages,
|
||||
stats.users,
|
||||
stats.channels,
|
||||
stats.servers,
|
||||
web::format_bytes(stats.total_storage),
|
||||
web::format_bytes(stats.message_storage),
|
||||
web::format_bytes(stats.attachment_storage),
|
||||
);
|
||||
trace_message(
|
||||
&msg,
|
||||
ctx.channel_id().to_string(),
|
||||
ctx.guild_id().unwrap().to_string(),
|
||||
)
|
||||
.await;
|
||||
ctx.say(msg).await?;
|
||||
debug!("Stats command performed for user {}", ctx.author().name);
|
||||
Ok(())
|
||||
}
|
||||
+29
-6
@@ -12,7 +12,6 @@ pub struct Data {
|
||||
pub pool: sqlx::PgPool,
|
||||
}
|
||||
|
||||
// Define standard types for Poise context, commands, and errors.
|
||||
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
pub type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
@@ -37,7 +36,6 @@ async fn main() {
|
||||
|
||||
trace!("Env loaded");
|
||||
|
||||
// Grab envs
|
||||
trace!("Loading database url");
|
||||
let database_url =
|
||||
env::var("TG_BOT_DATABASE_URL").expect("Expected a database url in the environment");
|
||||
@@ -51,9 +49,15 @@ async fn main() {
|
||||
let web_address = env::var("TG_BOT_WEB_ADDRESS").unwrap_or_else(|_| "0.0.0.0:3000".to_string());
|
||||
trace!("Web address loaded");
|
||||
|
||||
let discord_client_id = env::var("TG_BOT_DISCORD_CLIENT_ID")
|
||||
.expect("Expected a Discord client ID in the environment");
|
||||
let discord_client_secret = env::var("TG_BOT_DISCORD_CLIENT_SECRET")
|
||||
.expect("Expected a Discord client secret in the environment");
|
||||
let discord_redirect_uri = env::var("TG_BOT_DISCORD_REDIRECT_URI")
|
||||
.expect("Expected a Discord redirect URI in the environment");
|
||||
|
||||
info!("Starting bot...");
|
||||
|
||||
// Initialize database
|
||||
debug!("Initalizing database");
|
||||
let pool = connect_database(&database_url)
|
||||
.await
|
||||
@@ -71,7 +75,14 @@ async fn main() {
|
||||
let web_listener = tokio::net::TcpListener::bind(&web_address)
|
||||
.await
|
||||
.expect("Failed to bind web server");
|
||||
tokio::spawn(web::run(web_listener, pool.clone()));
|
||||
tokio::spawn(web::run(
|
||||
web_listener,
|
||||
pool.clone(),
|
||||
token.clone(),
|
||||
discord_client_id,
|
||||
discord_client_secret,
|
||||
discord_redirect_uri,
|
||||
));
|
||||
debug!("Web server started");
|
||||
|
||||
trace!("Loading intents");
|
||||
@@ -102,7 +113,12 @@ async fn main() {
|
||||
}
|
||||
})
|
||||
},
|
||||
commands: vec![commands::ping(), commands::version(), commands::git()],
|
||||
commands: vec![
|
||||
commands::ping(),
|
||||
commands::version(),
|
||||
commands::git(),
|
||||
commands::stats(),
|
||||
],
|
||||
..Default::default()
|
||||
})
|
||||
.setup(|ctx, _ready, framework| {
|
||||
@@ -171,5 +187,12 @@ async fn connect_database(database_url: &str) -> Result<sqlx::PgPool, Error> {
|
||||
}
|
||||
|
||||
fn quote_identifier(identifier: &str) -> String {
|
||||
format!("\"{}\"", identifier.replace('"', "\"\""))
|
||||
let mut escaped = String::with_capacity(identifier.len());
|
||||
for character in identifier.chars() {
|
||||
escaped.push(character);
|
||||
if character == '"' {
|
||||
escaped.push(character);
|
||||
}
|
||||
}
|
||||
format!("\"{}\"", escaped)
|
||||
}
|
||||
+1449
-395
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user