Merge pull request 'Fixing a problem with the return type of interaction_create
' (#1) from migueldamota/Rustendo:fix/add-missing-await into master
Reviewed-on: #1
This commit is contained in:
commit
a1a78d6598
1 changed files with 25 additions and 30 deletions
45
src/main.rs
45
src/main.rs
|
@ -1,12 +1,14 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
mod util;
|
|
||||||
mod handler;
|
mod handler;
|
||||||
|
mod util;
|
||||||
|
|
||||||
use std::thread::current;
|
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use serenity::all::{CommandInteraction, OnlineStatus};
|
use serenity::all::{CommandInteraction, OnlineStatus};
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::builder::{CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, CreateInteractionResponse, CreateInteractionResponseMessage};
|
use serenity::builder::{
|
||||||
|
CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, CreateInteractionResponse,
|
||||||
|
CreateInteractionResponseMessage,
|
||||||
|
};
|
||||||
use serenity::gateway::ActivityData;
|
use serenity::gateway::ActivityData;
|
||||||
use serenity::model::application::{Command, Interaction};
|
use serenity::model::application::{Command, Interaction};
|
||||||
use serenity::model::gateway::Ready;
|
use serenity::model::gateway::Ready;
|
||||||
|
@ -18,18 +20,9 @@ use util::config;
|
||||||
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
|
// The voice client can be retrieved in any command using `songbird::get(ctx).await`.
|
||||||
use songbird::SerenityInit;
|
use songbird::SerenityInit;
|
||||||
|
|
||||||
// Event related imports to detect track creation failures.
|
|
||||||
use songbird::events::{Event, EventContext, EventHandler as VoiceEventHandler, TrackEvent};
|
|
||||||
|
|
||||||
// To turn user URLs into playable audio, we'll use yt-dlp.
|
|
||||||
use songbird::input::YoutubeDl;
|
|
||||||
|
|
||||||
// YtDl requests need an HTTP client to operate -- we'll create and store our own.
|
// YtDl requests need an HTTP client to operate -- we'll create and store our own.
|
||||||
use reqwest::Client as HttpClient;
|
use reqwest::Client as HttpClient;
|
||||||
|
|
||||||
// Import the `Context` to handle commands.
|
|
||||||
use serenity::client::Context;
|
|
||||||
|
|
||||||
struct HttpKey;
|
struct HttpKey;
|
||||||
impl TypeMapKey for HttpKey {
|
impl TypeMapKey for HttpKey {
|
||||||
type Value = HttpClient;
|
type Value = HttpClient;
|
||||||
|
@ -41,12 +34,12 @@ struct Handler;
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||||
if let Interaction::Command(command) = interaction {
|
if let Interaction::Command(command) = interaction {
|
||||||
let content = match command.data.name.as_str() {
|
let content = Some(match command.data.name.as_str() {
|
||||||
"info" => Some(commands::info::run(&ctx, &command)),
|
"info" => commands::info::run(&ctx, &command).await,
|
||||||
"play" => Some(commands::play::run(&ctx, &command)),
|
"play" => commands::play::run(&ctx, &command).await,
|
||||||
"stop" => Some(commands::stop::run(&ctx, &command)),
|
"stop" => commands::stop::run(&ctx, &command).await,
|
||||||
_ => Some(respond_with_error(&ctx, &command)),
|
_ => respond_with_error(&ctx, &command).await,
|
||||||
};
|
});
|
||||||
|
|
||||||
if let Some(embed) = content {
|
if let Some(embed) = content {
|
||||||
let data = CreateInteractionResponseMessage::new().embed(embed);
|
let data = CreateInteractionResponseMessage::new().embed(embed);
|
||||||
|
@ -77,19 +70,23 @@ pub async fn respond_with_error(_ctx: &Context, command: &CommandInteraction) ->
|
||||||
.author(CreateEmbedAuthor::new("Rustendo"))
|
.author(CreateEmbedAuthor::new("Rustendo"))
|
||||||
.title("Command not found")
|
.title("Command not found")
|
||||||
.description("Cannot find the executed command")
|
.description("Cannot find the executed command")
|
||||||
.footer(CreateEmbedFooter::new(format!("> {} | {}", current_time, username)))
|
.footer(CreateEmbedFooter::new(format!(
|
||||||
|
"> {} | {}",
|
||||||
|
current_time, username
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
println!(r"__________ __ .___
|
println!(
|
||||||
|
r"__________ __ .___
|
||||||
\______ \__ __ _______/ |_ ____ ____ __| _/____
|
\______ \__ __ _______/ |_ ____ ____ __| _/____
|
||||||
| _/ | | ___/\ __\_/ __ \ / \ / __ |/ _ \
|
| _/ | | ___/\ __\_/ __ \ / \ / __ |/ _ \
|
||||||
| | \ | |___ \ | | \ ___/ | | | /_/ ( <_> )
|
| | \ | |___ \ | | \ ___/ | | | /_/ ( <_> )
|
||||||
|____|_ /____/____ > |__| \___ >|___| |____ |\____/
|
|____|_ /____/____ > |__| \___ >|___| |____ |\____/
|
||||||
\/ \/ \/ \/ \/
|
\/ \/ \/ \/ \/
|
||||||
");
|
"
|
||||||
|
);
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
let config = config::load().unwrap();
|
let config = config::load().unwrap();
|
||||||
|
@ -111,9 +108,7 @@ async fn main() {
|
||||||
//
|
//
|
||||||
// Shards will automatically attempt to reconnect, and will perform exponential backoff until
|
// Shards will automatically attempt to reconnect, and will perform exponential backoff until
|
||||||
// it reconnects.
|
// it reconnects.
|
||||||
if let Err(why) = client
|
if let Err(why) = client.start().await {
|
||||||
.start()
|
|
||||||
.await {
|
|
||||||
println!("Client error: {why:?}");
|
println!("Client error: {why:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue