Skip to content

Commit

Permalink
Merge pull request #526 from tktcorporation/493/feature/select-channel
Browse files Browse the repository at this point in the history
493/feature/select channel
  • Loading branch information
tktcorporation authored Dec 29, 2024
2 parents ef031a3 + 6af4292 commit 3e19e73
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/commands/usecase/slash_commands/select_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub struct SelectChannel {}
impl SlashCommand for SelectChannel {
async fn run(_ctx: &Context, command: &CommandInteraction) -> SlashCommandResult {
let resolved_options = command.data.options();
let channel = match resolved_options.first().unwrap() {
ResolvedOption {
let channel_id = match resolved_options.first() {
Some(ResolvedOption {
value: ResolvedValue::Channel(channel),
..
} => channel,
_ => return SlashCommandResult::Simple(Some("Must provide a channel".to_string())),
}) => channel.id,
None => command.channel_id,
_ => return SlashCommandResult::Simple(Some("Invalid channel provided".to_string())),
};
let channel_id = channel.id;

let guild_id = command.guild_id.unwrap();
services::select_channel(&guild_id, channel_id).await;
Expand All @@ -28,14 +28,14 @@ impl SlashCommand for SelectChannel {

fn register(command: CreateCommand) -> CreateCommand {
command
.description("select a channel to speech")
.description("select a channel to speech (optional)")
.add_option(
CreateCommandOption::new(
CommandOptionType::Channel,
"channel",
"channel to speech",
"channel to speech (defaults to current channel if not specified)",
)
.required(true),
.required(false),
)
}
}
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use sentry;
use std::error::Error;

pub fn report_error(message: &str) {
sentry::capture_message(message, sentry::Level::Error);
}

pub fn report_error_with_cause<E: Error + ?Sized>(message: &str, error: &E) {
sentry::capture_error(error);
sentry::capture_message(&format!("{}: {}", message, error), sentry::Level::Error);
}

pub fn format_err<T: std::fmt::Debug>(context: &str, err: T) -> String {
format!("{}: {:?}", context, err)
}
1 change: 1 addition & 0 deletions src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl EventHandler for Handler {
}
});

// 新しいコマンドを登録
Command::set_global_commands(&ctx.http, SlashCommands::get_commands())
.await
.expect("Failed to set global commands");
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async fn main() {
let _guard = sentry::init(sentry::ClientOptions {
dsn: env::var("SENTRY_DSN").ok().and_then(|dsn| dsn.parse().ok()),
release: sentry::release_name!(),
traces_sample_rate: 1.0,
auto_session_tracking: true,
debug: true,
..Default::default()
});

Expand Down

0 comments on commit 3e19e73

Please sign in to comment.