aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-14 13:06:54 -0400
committerCara Salter <cara@devcara.com>2022-04-18 23:05:25 -0400
commitffacf1c8fc820de3890ba6231b644e9e4a65ce28 (patch)
tree475537cef44f8eb0e7ed1269fd8c76e700c62918 /src/main.rs
parent9b4707192557cdd64dd82c5883e54758d0d66512 (diff)
downloadglitch-ng-ffacf1c8fc820de3890ba6231b644e9e4a65ce28.tar.gz
glitch-ng-ffacf1c8fc820de3890ba6231b644e9e4a65ce28.zip
FLAKE
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 8693381..88d612e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,10 @@
+#![forbid(missing_docs)]
+/*!
+ * Full rewrite of the [Glitch](https://glitchbot.net) bot in Poise with slash commands
+ *
+ * This iteration will focus on code correctness and durability. The major goal is to avoid what
+ * happened to the Campmaster by avoiding code rot and forcing documentation on _everything_
+ */
use std::{sync::Mutex, time::Duration};
use dotenv::dotenv;
@@ -11,6 +18,7 @@ mod commands;
mod handler;
mod models;
+/// Contains data shared between all commands
pub struct Data {
pg: Mutex<PgPool>,
}
@@ -60,6 +68,7 @@ async fn register(ctx: Context<'_>, #[flag] global: bool) -> Result<(), Error> {
#[tokio::main]
#[instrument]
async fn main() {
+ // Initialize environment and logging
dotenv().unwrap();
tracing_subscriber::fmt::init();
info!("Initialized logging");
@@ -86,7 +95,9 @@ async fn main() {
..commands::reactionroles::rroles()
},
],
+ // This requires a closure, for some reason
on_error: |error| Box::pin(on_error(error)),
+ // Honestly could probably be removed, but it's kept in for ~reasons~
pre_command: |ctx| {
Box::pin(async move {
println!("Executing command {}...", ctx.command().name);
@@ -101,12 +112,15 @@ async fn main() {
prefix_options: poise::PrefixFrameworkOptions {
prefix: Some("~".into()),
edit_tracker: Some(poise::EditTracker::for_timespan(Duration::from_secs(3600))),
+ // These don't work, I thought they might but -\_()_/-
additional_prefixes: vec![
poise::Prefix::Literal("hey glitch"),
poise::Prefix::Literal("hey glitch,"),
],
..Default::default()
},
+ // For once, we abstracted the handler *out* of main.rs so we can actually read the damn
+ // file
listener: |ctx, event, _, data| Box::pin(handler::event_handler(ctx, event, data)),
..Default::default()
};
@@ -115,6 +129,18 @@ async fn main() {
.token(std::env::var("DISCORD_TOKEN").unwrap_or("BAD-TOKEN".into()))
.user_data_setup(move |_ctx, _ready, _framework| {
Box::pin(async move {
+ /*
+ * Hoo boy okay
+ *
+ * This sets up the postgres pool and adds it to the Data struct we defined
+ * earlier. Once that's done, it runs the migrations that have been embeded within
+ * the completed binary
+ *
+ * A sane default was chosen if DATABASE_URL doesn't exist
+ *
+ * If migrations fail, we panic and exit because then we're in an incorrect DB
+ * state and something needs to be fixed before any further work can be done.
+ */
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(