added team command, added game command, added about command
added request module, added nfl module, among other items
This commit is contained in:
82
src/main.rs
Normal file
82
src/main.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
mod commands;
|
||||
mod config;
|
||||
mod types;
|
||||
mod util;
|
||||
|
||||
use std::env;
|
||||
|
||||
use serenity::async_trait;
|
||||
use serenity::builder::{CreateInteractionResponse, CreateInteractionResponseMessage};
|
||||
use serenity::model::application::Interaction;
|
||||
use serenity::model::gateway::Ready;
|
||||
use serenity::model::id::GuildId;
|
||||
use serenity::prelude::*;
|
||||
|
||||
struct Handler;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||
if let Interaction::Command(command) = interaction {
|
||||
println!("Received command interaction: {command:#?}");
|
||||
|
||||
let content = match command.data.name.as_str() {
|
||||
"team" => Some(commands::team::run(&command.data.options()).await),
|
||||
"about" => Some(commands::about::run(&command.data.options()).await),
|
||||
"game" => Some(commands::game::run(&command.data.options()).await),
|
||||
_ => Some("not implemented :(".to_string()),
|
||||
};
|
||||
|
||||
if let Some(content) = content {
|
||||
let data = CreateInteractionResponseMessage::new().content(content);
|
||||
let builder = CreateInteractionResponse::Message(data);
|
||||
if let Err(why) = command.create_response(&ctx.http, builder).await {
|
||||
println!("Cannot respond to slash command: {why}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn ready(&self, ctx: Context, ready: Ready) {
|
||||
println!("{} is connected!", ready.user.name);
|
||||
|
||||
let guild_id = GuildId::new(
|
||||
env::var("GUILD_ID")
|
||||
.expect("Expected GUILD_ID in environment")
|
||||
.parse()
|
||||
.expect("GUILD_ID must be an integer"),
|
||||
);
|
||||
|
||||
let commands = guild_id
|
||||
.set_commands(
|
||||
&ctx.http,
|
||||
vec![
|
||||
commands::team::register(),
|
||||
commands::about::register(),
|
||||
commands::game::register(),
|
||||
], // TODO: register commands here
|
||||
)
|
||||
.await;
|
||||
|
||||
println!("Registered guild slash commands: {commands:#?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// setting up configuration
|
||||
let _ = config::config();
|
||||
|
||||
// setting up the discord bot
|
||||
let token = env::var("DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||
|
||||
// setting up the discord client
|
||||
let mut client = Client::builder(token, GatewayIntents::empty())
|
||||
.event_handler(Handler)
|
||||
.await
|
||||
.expect("Error creating client");
|
||||
|
||||
if let Err(why) = client.start().await {
|
||||
println!("Client error: {why:?}");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user