Initialize Twilight project, set up basic framework, initialize DB module

This commit is contained in:
2025-08-07 04:32:34 -03:00
parent 00d61545eb
commit 24d2344f37
29 changed files with 4095 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
use std::sync::Arc;
use clap::Parser;
use twilight_gateway::{ConfigBuilder, EventTypeFlags, Intents, Shard, ShardId, StreamExt};
use twilight_http::Client;
use twilight_model::gateway::{
payload::outgoing::update_presence::UpdatePresencePayload,
presence::{ActivityType, MinimalActivity, Status},
};
use crate::{
cli::Args, commands::register_default_components, discord::events,
framework::{handlers::Handlers, interactions::registry::Registry},
};
mod cli;
mod commands;
mod constants;
mod database;
mod discord;
mod framework;
mod logging;
mod utils;
#[tokio::main]
async fn main() {
dotenvy::dotenv().ok();
let args = Args::parse();
logging::init();
let intents = Intents::GUILD_MESSAGES | Intents::MESSAGE_CONTENT;
let config = ConfigBuilder::new(args.token.clone(), intents)
.presence(
UpdatePresencePayload::new(
vec![
MinimalActivity {
kind: ActivityType::Listening,
name: "Hello Payphone!".into(),
url: None,
}
.into(),
],
false,
None,
Status::Online,
)
.expect("Could not set presence!"),
)
.build();
let mut shard = Shard::with_config(ShardId::new(0, 1), config);
let http = Client::new(args.token.clone());
let registry = Registry::new();
let app =
http.current_user_application()
.await
.expect("Could not get information about the current application")
.model()
.await
.expect("Could not get model of the information of the current application")
;
register_default_components(&registry);
log::info!("Welcome to Payphone, Nyeki!");
log::info!(
"Payphone is running on version v{}",
env!("CARGO_PKG_VERSION")
);
let db = database::init("127.0.0.1:9042")
.await
.expect("Could not connect to the database!");
let handlers = Arc::new(Handlers {
app,
db,
http,
registry
});
while let Some(event) = shard.next_event(EventTypeFlags::all()).await {
if let Ok(event) = event {
tokio::spawn(events::handle_event(
event,
handlers.clone(),
));
} else {
log::error!("Could not receive the next event.");
}
}
}