From 67e4081aa69f489ad88ee064402d68a5969069c2 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Wed, 12 Jan 2022 15:45:20 -0500 Subject: rroles: Implement Reaction Roles now requires postgresql. --- src/main.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index bb686d2..021886f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,17 @@ -use std::time::Duration; +use std::{time::Duration, sync::Mutex}; use dotenv::dotenv; +use sqlx::{PgPool, postgres::PgPoolOptions}; type Error = Box; type Context<'a> = poise::Context<'a, Data, Error>; mod commands; +mod handler; +mod models; pub struct Data { - + pg: Mutex, } /// Show help menu @@ -63,6 +66,13 @@ async fn main() { commands::osu::osup(), commands::osu::osubm(), + + poise::Command { + subcommands: vec![ + commands::reactionroles::init(), + ], + ..commands::reactionroles::rroles() + }, ], on_error: |error| Box::pin(on_error(error)), pre_command: |ctx| { @@ -85,6 +95,7 @@ async fn main() { ], ..Default::default() }, + listener: |ctx, event, _, data| Box::pin(handler::event_handler(ctx, event, data)), ..Default::default() }; @@ -92,7 +103,14 @@ 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 { - Ok(Data {}) + let pool = PgPoolOptions::new() + .max_connections(5) + .connect(&std::env::var("DATABASE_URL").unwrap_or("postgres://postgres@localhost/glitch".to_string())) + .await + .expect("Couldn't connect to postgresql"); + Ok(Data { + pg: Mutex::new(pool) + }) }) }) .options(options) -- cgit v1.2.3