-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(discord): #62 created basic bot usage
- updated dependencies to build slash commands - made command for `ping` endpoint - loaded config from environment
- Loading branch information
Showing
12 changed files
with
119 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# aura/api/endpoints/basic.py | ||
|
||
from fastapi import ( | ||
APIRouter, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/") | ||
def read_root(): | ||
return {"message": "Welcome to AURA"} | ||
|
||
|
||
@router.get("/ping") | ||
def ping(): | ||
return {"message": "pong"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
[package] | ||
name = "discord" | ||
name = "aura-discord" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
clap = "4.5.18" | ||
dotenv = "0.15.0" | ||
once_cell = "1.19.0" | ||
reqwest = "0.12.7" | ||
serenity = "0.12.2" | ||
tokio = "1.40.0" | ||
dotenv = "0.15" | ||
reqwest = { version = "0.11", features = ["json"] } | ||
clap = { version = "4.0", features = ["derive"] } | ||
poise = "0.6.1" | ||
tracing = "0.1.40" | ||
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } | ||
anyhow = "1.0.89" | ||
once_cell = "1.20.1" | ||
serde = "1.0.210" | ||
serde_json = "1.0.128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// cli/mod.rs | ||
|
||
pub mod bot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// commands/mod.rs | ||
|
||
pub mod ping; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// commands/ping.rs | ||
|
||
use crate::services::api_client; | ||
use crate::types::{Context, Error}; | ||
use anyhow::Result; | ||
|
||
// Fetch data from the `/ping` endpoint | ||
#[poise::command(slash_command, prefix_command)] | ||
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> { | ||
// Call the API client to make a GET request to `/ping` | ||
match api_client::get("ping").await { | ||
Ok(data) => { | ||
ctx.say(data.to_string()).await?; | ||
} | ||
Err(e) => { | ||
ctx.say(format!("Error: {}", e)).await?; | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// discord/src/config/mod.rs | ||
|
||
pub mod settings; | ||
pub mod settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// events/mod.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
// main.rs | ||
|
||
mod types; | ||
mod commands; | ||
mod config; | ||
mod services; | ||
|
||
use config::settings; | ||
use services::api_client; | ||
use types::Data; | ||
use poise::serenity_prelude as serenity; | ||
use crate::config::settings::{load_config, get_config}; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
// Load the configuration | ||
settings::load_config(); | ||
load_config(); | ||
let config = get_config(); | ||
let token = &config.discord_token; | ||
|
||
// Get the configuration | ||
let config = settings::get_config(); | ||
// Set up intents | ||
let intents = serenity::GatewayIntents::non_privileged(); | ||
|
||
// Print the configuration | ||
println!("API URL: {}", config.api_url); | ||
println!("Discord Token: {}", config.discord_token); | ||
// Define the bot framework | ||
let framework = poise::Framework::builder() | ||
.options(poise::FrameworkOptions { | ||
commands: vec![ | ||
commands::ping::ping(), | ||
], | ||
..Default::default() | ||
}) | ||
.setup(|ctx, _ready, framework| { | ||
Box::pin(async move { | ||
poise::builtins::register_globally(ctx, &framework.options().commands).await?; | ||
Ok(Data {}) | ||
}) | ||
}) | ||
.build(); | ||
|
||
// Get data from the API | ||
match api_client::get("").await { | ||
Ok(response) => println!("Response: {}", response), | ||
Err(err) => eprintln!("Error: {}", err), | ||
} | ||
let client = serenity::ClientBuilder::new(token, intents) | ||
.framework(framework) | ||
.await; | ||
client.unwrap().start().await.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// types.rs | ||
|
||
pub struct Data {} | ||
|
||
pub type Error = Box<dyn std::error::Error + Send + Sync>; | ||
pub type Context<'a> = poise::Context<'a, Data, Error>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// utils/mod.rs | ||
|