Added ephemeral responses
This commit is contained in:
@@ -8,10 +8,10 @@ name: siren
|
|||||||
services:
|
services:
|
||||||
bot:
|
bot:
|
||||||
image: siren:${SIREN_VERSION:-latest}
|
image: siren:${SIREN_VERSION:-latest}
|
||||||
container_name: siren
|
container_name: siren-bot
|
||||||
env_file: *env
|
env_file: *env
|
||||||
environment:
|
environment:
|
||||||
DATABASE_HOST: postgres
|
DATABASE_HOST: siren-postgres
|
||||||
DATABASE_PORT: 5432
|
DATABASE_PORT: 5432
|
||||||
REDIS_HOST: redis
|
REDIS_HOST: redis
|
||||||
REDIS_PORT: 6379
|
REDIS_PORT: 6379
|
||||||
@@ -29,7 +29,7 @@ services:
|
|||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
container_name: postgres
|
container_name: siren-postgres
|
||||||
env_file: *env
|
env_file: *env
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${DATABASE_USER}
|
POSTGRES_USER: ${DATABASE_USER}
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serenity::all::{
|
|
||||||
CommandInteraction, CreateInteractionResponse, CreateInteractionResponseMessage,
|
|
||||||
EditInteractionResponse,
|
|
||||||
};
|
|
||||||
use serenity::client::Cache;
|
use serenity::client::Cache;
|
||||||
use serenity::model::prelude::{GuildId, ChannelId};
|
use serenity::model::prelude::{GuildId, ChannelId};
|
||||||
use serenity::model::user::User;
|
use serenity::model::user::User;
|
||||||
@@ -55,31 +51,6 @@ pub async fn leave_voice_channel(manager: &Arc<Songbird>, guild_id: &GuildId) ->
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn process_message(ctx: &Context, command: &CommandInteraction) {
|
|
||||||
create_response(&ctx, &command, format!("Processing...")).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn create_response(ctx: &Context, command: &CommandInteraction, content: String) {
|
|
||||||
let data = CreateInteractionResponseMessage::new().content(content.to_owned());
|
|
||||||
let builder = CreateInteractionResponse::Message(data);
|
|
||||||
match command.create_response(&ctx.http, builder).await {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => {
|
|
||||||
log::error!("Failed to create response for {content}\n{err}");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn edit_response(ctx: &Context, command: &CommandInteraction, content: String) {
|
|
||||||
let builder = EditInteractionResponse::new().content(content.to_owned());
|
|
||||||
match command.edit_response(&ctx.http, builder).await {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => {
|
|
||||||
log::error!("Failed to create response for {content}\n{err}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a URL is valid and if it is a playlist.
|
* Checks if a URL is valid and if it is a playlist.
|
||||||
* 1st tuple value is if the URL is valid.
|
* 1st tuple value is if the URL is valid.
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ use serenity::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{edit_response, get_songbird, process_message};
|
use crate::bot::commands::{edit_response, process_message};
|
||||||
|
|
||||||
|
use super::get_songbird;
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ use serenity::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{edit_response, get_songbird, process_message};
|
use crate::bot::commands::{edit_response, process_message};
|
||||||
|
|
||||||
|
use super::get_songbird;
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ use crate::bot::ytdlp::{PlaylistItem, YtDlp};
|
|||||||
use crate::error::{SirenResult, Error as SirenError};
|
use crate::error::{SirenResult, Error as SirenError};
|
||||||
use crate::HttpKey;
|
use crate::HttpKey;
|
||||||
|
|
||||||
use super::{
|
use super::{get_songbird, is_valid_url, join_voice_channel};
|
||||||
create_response, edit_response, get_songbird, is_valid_url, join_voice_channel, process_message,
|
|
||||||
};
|
use crate::bot::commands::{create_response, edit_response, process_message};
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Process the command options
|
// Process the command options
|
||||||
@@ -26,13 +26,13 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
|||||||
"{} attempted to play a track without a track option",
|
"{} attempted to play a track without a track option",
|
||||||
command.user.id.get()
|
command.user.id.get()
|
||||||
);
|
);
|
||||||
create_response(&ctx, &command, format!("Track option is missing")).await;
|
create_response(&ctx, &command, format!("Track option is missing"), false).await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ use serenity::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{edit_response, get_songbird, process_message};
|
use crate::bot::commands::{edit_response, process_message};
|
||||||
|
|
||||||
|
use super::get_songbird;
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ use serenity::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{edit_response, get_songbird, process_message};
|
use crate::bot::commands::{edit_response, process_message};
|
||||||
|
|
||||||
|
use super::get_songbird;
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ use serenity::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{edit_response, get_songbird, process_message};
|
use crate::bot::commands::{edit_response, process_message};
|
||||||
|
|
||||||
|
use super::get_songbird;
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ use songbird::Songbird;
|
|||||||
|
|
||||||
use crate::data::guilds::GuildCache;
|
use crate::data::guilds::GuildCache;
|
||||||
|
|
||||||
use super::{create_response, edit_response, get_songbird, process_message};
|
use crate::bot::commands::{create_response, edit_response, process_message};
|
||||||
|
|
||||||
|
use super::get_songbird;
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Process the command options
|
// Process the command options
|
||||||
@@ -20,13 +22,13 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
|||||||
"{} attempted to change the volume without a volume option",
|
"{} attempted to change the volume without a volume option",
|
||||||
command.user.id.get()
|
command.user.id.get()
|
||||||
);
|
);
|
||||||
create_response(&ctx, &command, format!("Volume option is missing")).await;
|
create_response(&ctx, &command, format!("Volume option is missing"), false).await;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
process_message(&ctx, &command).await;
|
process_message(&ctx, &command, false).await;
|
||||||
|
|
||||||
// Get the songbird manager
|
// Get the songbird manager
|
||||||
let manager = get_songbird(ctx).await;
|
let manager = get_songbird(ctx).await;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ use serenity::all::{
|
|||||||
CreateEmbed, CreateEmbedFooter, EditInteractionResponse, Timestamp,
|
CreateEmbed, CreateEmbedFooter, EditInteractionResponse, Timestamp,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{bot::commands::audio::create_response, data::events::Event};
|
use crate::{bot::commands::create_response, data::events::Event};
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
// Create the initial response
|
// Create the initial response
|
||||||
create_response(&ctx, &command, format!(".....")).await;
|
create_response(&ctx, &command, format!("Processing..."), true).await;
|
||||||
|
|
||||||
// Process the command options
|
// Process the command options
|
||||||
let title = command.data.options.get(0).unwrap().value.as_str().unwrap();
|
let title = command.data.options.get(0).unwrap().value.as_str().unwrap();
|
||||||
|
|||||||
@@ -3,10 +3,17 @@ use serenity::all::{
|
|||||||
CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption,
|
CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::bot::commands::audio::{create_response, edit_response};
|
use crate::bot::commands::{create_response, create_dm, edit_response};
|
||||||
|
|
||||||
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
||||||
create_response(&ctx, &command, format!(".....")).await;
|
let hidden = match command.data.options.get(1) {
|
||||||
|
Some(o) => match o.value.as_bool() {
|
||||||
|
Some(b) => b,
|
||||||
|
None => false,
|
||||||
|
},
|
||||||
|
None => false,
|
||||||
|
};
|
||||||
|
create_response(&ctx, &command, format!("Rolling..."), hidden).await;
|
||||||
let dice_string = match command.data.options.get(0) {
|
let dice_string = match command.data.options.get(0) {
|
||||||
Some(o) => match o.value.as_str() {
|
Some(o) => match o.value.as_str() {
|
||||||
Some(s) => s.split_whitespace().collect::<String>(),
|
Some(s) => s.split_whitespace().collect::<String>(),
|
||||||
@@ -33,7 +40,8 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
|||||||
rolls.push(roll);
|
rolls.push(roll);
|
||||||
}
|
}
|
||||||
let response = format!(
|
let response = format!(
|
||||||
"{}d{}{} = {}",
|
"🎲 **{}** (Rolled {}d{}{})",
|
||||||
|
total + (modifier as u32),
|
||||||
count,
|
count,
|
||||||
sides,
|
sides,
|
||||||
if modifier > 0 {
|
if modifier > 0 {
|
||||||
@@ -42,8 +50,7 @@ pub async fn run(ctx: &Context, command: &CommandInteraction) {
|
|||||||
format!("-{}", modifier)
|
format!("-{}", modifier)
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
},
|
}
|
||||||
total + (modifier as u32)
|
|
||||||
);
|
);
|
||||||
edit_response(&ctx, &command, response).await;
|
edit_response(&ctx, &command, response).await;
|
||||||
}
|
}
|
||||||
@@ -84,10 +91,18 @@ fn parse_dice(dice: &str) -> Result<(u32, u32, i32), String> {
|
|||||||
if n == 4 || n == 6 || n == 8 || n == 10 || n == 12 || n == 20 || n == 100 {
|
if n == 4 || n == 6 || n == 8 || n == 10 || n == 12 || n == 20 || n == 100 {
|
||||||
n
|
n
|
||||||
} else {
|
} else {
|
||||||
return Err(format!("Invalid dice sides: {}", s));
|
return Err(format!(
|
||||||
|
"Expected one of d4, d6, d8, d10, d12, d20, d100 but received d{}",
|
||||||
|
s
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => return Err(format!("Invalid dice sides: {}", s)),
|
Err(_) => {
|
||||||
|
return Err(format!(
|
||||||
|
"Expected one of d4, d6, d8, d10, d12, d20, d100 but received d{}",
|
||||||
|
s
|
||||||
|
))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
None => return Err(format!("Invalid dice string: {}", dice)),
|
None => return Err(format!("Invalid dice string: {}", dice)),
|
||||||
};
|
};
|
||||||
@@ -113,4 +128,12 @@ pub fn register() -> CreateCommand {
|
|||||||
.add_option(
|
.add_option(
|
||||||
CreateCommandOption::new(CommandOptionType::String, "dice", "Dice to roll").required(true),
|
CreateCommandOption::new(CommandOptionType::String, "dice", "Dice to roll").required(true),
|
||||||
)
|
)
|
||||||
|
.add_option(
|
||||||
|
CreateCommandOption::new(
|
||||||
|
CommandOptionType::Boolean,
|
||||||
|
"hidden",
|
||||||
|
"Whether the roll should be hidden",
|
||||||
|
)
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,59 @@
|
|||||||
|
use serenity::prelude::*;
|
||||||
|
use serenity::all::{
|
||||||
|
CommandInteraction, CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage,
|
||||||
|
EditInteractionResponse, InteractionResponseFlags, Message,
|
||||||
|
};
|
||||||
|
|
||||||
pub mod audio;
|
pub mod audio;
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod fun;
|
pub mod fun;
|
||||||
pub mod utility;
|
pub mod utility;
|
||||||
|
|
||||||
|
pub async fn process_message(ctx: &Context, command: &CommandInteraction, private: bool) {
|
||||||
|
create_response(&ctx, &command, format!("Processing..."), private).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_dm(
|
||||||
|
ctx: &Context,
|
||||||
|
command: &CommandInteraction,
|
||||||
|
content: String,
|
||||||
|
) -> Option<Message> {
|
||||||
|
let data = CreateMessage::new().content(content.to_owned());
|
||||||
|
return match command.user.direct_message(ctx, data).await {
|
||||||
|
Ok(message) => Some(message),
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Failed to create direct message for {content}\n{err}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_response(
|
||||||
|
ctx: &Context,
|
||||||
|
command: &CommandInteraction,
|
||||||
|
content: String,
|
||||||
|
private: bool,
|
||||||
|
) {
|
||||||
|
let mut data = CreateInteractionResponseMessage::new().content(content.to_owned());
|
||||||
|
if private {
|
||||||
|
data = data.flags(InteractionResponseFlags::EPHEMERAL);
|
||||||
|
}
|
||||||
|
let builder = CreateInteractionResponse::Message(data);
|
||||||
|
match command.create_response(&ctx.http, builder).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Failed to create response for {content}\n{err}");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn edit_response(ctx: &Context, command: &CommandInteraction, content: String) {
|
||||||
|
let builder = EditInteractionResponse::new().content(content.to_owned());
|
||||||
|
match command.edit_response(&ctx.http, builder).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("Failed to create response for {content}\n{err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use serenity::prelude::*;
|
|||||||
|
|
||||||
use crate::data::guilds::GuildCache;
|
use crate::data::guilds::GuildCache;
|
||||||
use super::{commands, oai};
|
use super::{commands, oai};
|
||||||
use super::commands::audio::create_response;
|
use super::commands::create_response;
|
||||||
|
|
||||||
pub struct Handler {
|
pub struct Handler {
|
||||||
// Open AI Config
|
// Open AI Config
|
||||||
@@ -62,7 +62,7 @@ impl EventHandler for Handler {
|
|||||||
"ping" => commands::utility::ping::run(&command.data.options),
|
"ping" => commands::utility::ping::run(&command.data.options),
|
||||||
_ => "Unknown command".to_string(),
|
_ => "Unknown command".to_string(),
|
||||||
};
|
};
|
||||||
create_response(&ctx, &command, content).await;
|
create_response(&ctx, &command, content, false).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user