feat: Enable Docker deployment and CD
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 8m1s
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 8m1s
Closes #8, partially addresses #6
This commit is contained in:
@@ -4,7 +4,7 @@ use std::env;
|
||||
|
||||
use poise::serenity_prelude::{ChannelId, GuildId};
|
||||
use sqlx::SqlitePool;
|
||||
use tracing::error;
|
||||
use tracing::{error, info};
|
||||
|
||||
pub type Result<T> = ::std::result::Result<T, sqlx::Error>;
|
||||
|
||||
@@ -24,14 +24,12 @@ impl Database {
|
||||
///
|
||||
/// This function will return an error if the Sqlite pool fails to
|
||||
/// create.
|
||||
// TODO: Create the database if it doesn’t exist already and run migrations
|
||||
pub async fn new() -> Result<Self> {
|
||||
Ok(Self(
|
||||
SqlitePool::connect(
|
||||
&env::var("DATABASE_URL")
|
||||
.expect("Missing enviroment variable DATABASE_URL"),
|
||||
)
|
||||
.await?,
|
||||
))
|
||||
let db_url = env::var("DATABASE_URL")
|
||||
.expect("Missing enviroment variable DATABASE_URL");
|
||||
info!("Connecting to database located at {db_url}");
|
||||
Ok(Self(SqlitePool::connect(&db_url).await?))
|
||||
}
|
||||
|
||||
/// Return from database all channels registered as loggers for a
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
mod commands;
|
||||
pub mod error;
|
||||
mod events;
|
||||
pub mod utils;
|
||||
pub mod error;
|
||||
|
||||
use poise::FrameworkBuilder;
|
||||
use tracing::info;
|
||||
use utils::serenity;
|
||||
|
||||
use commands::logging;
|
||||
@@ -19,24 +20,30 @@ pub type Result = ::std::result::Result<(), Error>;
|
||||
///
|
||||
/// Panics if the environment `DISCORD_TOKEN` is unavailable.
|
||||
pub fn make_bot() -> FrameworkBuilder<BotData, Error> {
|
||||
poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![logging()],
|
||||
event_handler: |ctx, event, framework, data| {
|
||||
Box::pin(event_handler(ctx, event, framework, data))
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.token(std::env::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN"))
|
||||
.intents(serenity::GatewayIntents::non_privileged())
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(
|
||||
ctx,
|
||||
&framework.options().commands,
|
||||
)
|
||||
.await?;
|
||||
Ok(BotData::new().await?)
|
||||
})
|
||||
})
|
||||
match std::env::var("DISCORD_TOKEN") {
|
||||
Ok(token) => {
|
||||
info!("Launching bot with token {token}");
|
||||
poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![logging()],
|
||||
event_handler: |ctx, event, framework, data| {
|
||||
Box::pin(event_handler(ctx, event, framework, data))
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.token(token)
|
||||
.intents(serenity::GatewayIntents::non_privileged())
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(
|
||||
ctx,
|
||||
&framework.options().commands,
|
||||
)
|
||||
.await?;
|
||||
Ok(BotData::new().await?)
|
||||
})
|
||||
})
|
||||
}
|
||||
Err(_) => panic!("DISCORD_TOKEN environment variable is missing."),
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main.rs
14
src/main.rs
@@ -1,17 +1,23 @@
|
||||
#![warn(clippy::style, clippy::pedantic)]
|
||||
|
||||
mod utils;
|
||||
mod db;
|
||||
mod discord;
|
||||
mod utils;
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
use tracing::info;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
dotenvy::dotenv()?;
|
||||
color_eyre::install()?;
|
||||
println!("Setting logging up");
|
||||
utils::setup_logging();
|
||||
|
||||
info!("Setting up color_eyre");
|
||||
color_eyre::install()?;
|
||||
info!("Reading from dotenv");
|
||||
let _ =
|
||||
dotenvy::dotenv().map_err(|_| info!("No .env file found, skipping"));
|
||||
info!("Launching bot");
|
||||
let bot = discord::make_bot();
|
||||
bot.run().await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user