From 16c1dcc080a3e010b3d8ec75a708afca22d6ebe8 Mon Sep 17 00:00:00 2001 From: logan Date: Mon, 21 Oct 2024 11:36:50 -0400 Subject: [PATCH] refactor commands add alias to "does_my_game_work" command "help" enable dynamic command name changes the footer text to dynamically use the command name invoked rather than a static string refactor command "whats_where" to be "paths" "whats_where" is now an alias --- src/commands/discord.rs | 6 +++--- src/commands/does_my_game_work.rs | 8 ++++---- src/commands/game_support.rs | 6 +++--- src/commands/github.rs | 6 +++--- src/commands/heroic.rs | 4 ++-- src/commands/mod.rs | 2 +- src/commands/msync.rs | 6 +++--- src/commands/{whats_where.rs => paths.rs} | 8 ++++---- src/commands/username.rs | 5 +++-- src/commands/website.rs | 6 +++--- src/main.rs | 4 ++-- 11 files changed, 31 insertions(+), 30 deletions(-) rename src/commands/{whats_where.rs => paths.rs} (89%) diff --git a/src/commands/discord.rs b/src/commands/discord.rs index 4b7e073..e124cc3 100644 --- a/src/commands/discord.rs +++ b/src/commands/discord.rs @@ -3,17 +3,17 @@ use crate::{Context, Error}; #[poise::command(prefix_command, slash_command)] pub async fn discord(ctx: Context<'_>) -> Result<(), Error> { let mut message = "https://discord.gg/CsqAfs9CnM".to_owned(); - + let cmd_name = ctx.invoked_command_name(); if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "discord"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "discord"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/does_my_game_work.rs b/src/commands/does_my_game_work.rs index 156b409..11d1d36 100644 --- a/src/commands/does_my_game_work.rs +++ b/src/commands/does_my_game_work.rs @@ -1,6 +1,6 @@ use crate::{Context, Error}; -#[poise::command(prefix_command, slash_command, aliases("dmgw"))] +#[poise::command(prefix_command, slash_command, aliases("dmgw", "help"))] pub async fn does_my_game_work(ctx: Context<'_>) -> Result<(), Error> { let mut message = "Does your game work? Check https://docs.getwhisky.app/game-support/ first, and search to see if anyone else has this same issue in this Discord or the GitHub repository. @@ -14,17 +14,17 @@ Can't find your game from those sources? Check here: If you've checked all of these places and still can't find an answer, feel free to create a support post in #support ! As a reminder: Most games with EasyAntiCheat and most other anti-cheats will **NOT** work without workarounds.".to_owned(); - + let cmd_name = ctx.invoked_command_name(); if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "does_my_game_work"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "does_my_game_work"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/game_support.rs b/src/commands/game_support.rs index 78c9c74..b92798c 100644 --- a/src/commands/game_support.rs +++ b/src/commands/game_support.rs @@ -6,7 +6,7 @@ pub async fn game_support(ctx: Context<'_>, #[description = "Game Name"] game_name: Option) -> Result<(), Error> { // String containing default response let mut message = String::from("https://docs.getwhisky.app/game-support/"); - + let cmd_name = ctx.invoked_command_name(); match game_name { Some(name) => { let esc_name = name @@ -46,13 +46,13 @@ pub async fn game_support(ctx: Context<'_>, if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "game_support"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "game_support"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/github.rs b/src/commands/github.rs index 0268dbf..d4e95b6 100644 --- a/src/commands/github.rs +++ b/src/commands/github.rs @@ -3,17 +3,17 @@ use crate::{Context, Error}; #[poise::command(prefix_command, slash_command)] pub async fn github(ctx: Context<'_>) -> Result<(), Error> { let mut message = "https://github.com/Whisky-App/Whisky".to_owned(); - + let cmd_name = ctx.invoked_command_name(); if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "github"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "github"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/heroic.rs b/src/commands/heroic.rs index 6b32912..90dec13 100644 --- a/src/commands/heroic.rs +++ b/src/commands/heroic.rs @@ -34,13 +34,13 @@ pub async fn heroic(ctx: Context<'_>) -> Result<(), Error> { if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "heroic"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; } None => { - message += &format!("\n-# This command was invoked using `~{}`", "heroic"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d0bfe67..b920a30 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -7,5 +7,5 @@ pub mod website; pub mod discord; pub mod username; pub mod heroic; -pub mod whats_where; +pub mod paths; pub mod msync; diff --git a/src/commands/msync.rs b/src/commands/msync.rs index 7ef830d..6e97b91 100644 --- a/src/commands/msync.rs +++ b/src/commands/msync.rs @@ -6,17 +6,17 @@ pub async fn msync(ctx: Context<'_>) -> Result<(), Error> { 1. Kill All Bottles: Press `Command`⌘ + `Shift`⇧ + `K` or Go to `File` (near the Apple logo) -> `Kill All Bottles` 2. Change MSync to ESync: `Bottle Configuration` -> `Enhanced Sync` 3. Run Steam".to_owned(); - + let cmd_name = ctx.invoked_command_name(); if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "msync"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "msync"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/whats_where.rs b/src/commands/paths.rs similarity index 89% rename from src/commands/whats_where.rs rename to src/commands/paths.rs index 25628e1..95be62a 100644 --- a/src/commands/whats_where.rs +++ b/src/commands/paths.rs @@ -1,7 +1,7 @@ use crate::{Context, Error}; -#[poise::command(prefix_command, slash_command, aliases("whiskywine", "bottles", "logs", "whiskycmd", "whatswhere", "where", "paths", "path"))] -pub async fn whats_where(ctx: Context<'_>) -> Result<(), Error> { +#[poise::command(prefix_command, slash_command, aliases("whiskywine", "bottles", "logs", "whiskycmd", "whats_where", "whatswhere", "where", "path"))] +pub async fn paths(ctx: Context<'_>) -> Result<(), Error> { let whiskywine = "**WhiskyWine:** `~/Library/Application Support/com.isaacmarovitz.Whisky/Libraries`"; let bottles = "**Bottles:** `~/Library/Containers/com.isaacmarovitz.Whisky/Bottles`"; @@ -51,13 +51,13 @@ pub async fn whats_where(ctx: Context<'_>) -> Result<(), Error> { if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "whats_where"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "whats_where"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/username.rs b/src/commands/username.rs index e6dea56..87072b0 100644 --- a/src/commands/username.rs +++ b/src/commands/username.rs @@ -6,16 +6,17 @@ pub async fn username(ctx: Context<'_>) -> Result<(), Error> { Follow this Apple support guide to change your username: https://support.apple.com/en-us/102547".to_owned(); + let cmd_name = ctx.invoked_command_name(); if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "username"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "username"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/commands/website.rs b/src/commands/website.rs index 328d3b9..8509146 100644 --- a/src/commands/website.rs +++ b/src/commands/website.rs @@ -3,17 +3,17 @@ use crate::{Context, Error}; #[poise::command(prefix_command, slash_command)] pub async fn website(ctx: Context<'_>) -> Result<(), Error> { let mut message ="https://getwhisky.app/".to_owned(); - + let cmd_name = ctx.invoked_command_name(); if let Context::Prefix(prefix) = ctx { match prefix.msg.clone().referenced_message { Some(parent) => { - message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), "website"); + message += &format!("\n-# This command was invoked by {} using `~{}`", ctx.author().to_string().as_str(), cmd_name); parent.reply_ping(&ctx, message).await?; prefix.msg.delete(ctx).await?; }, None => { - message += &format!("\n-# This command was invoked using `~{}`", "website"); + message += &format!("\n-# This command was invoked using `~{}`", cmd_name); ctx.reply(message).await?; } } diff --git a/src/main.rs b/src/main.rs index 904abbd..8c9aaf7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use crate::commands::does_my_game_work::*; use crate::commands::say::*; use crate::commands::username::*; use crate::commands::heroic::*; -use crate::commands::whats_where::*; +use crate::commands::paths::*; use crate::commands::msync::*; pub mod header; @@ -48,7 +48,7 @@ async fn serenity( say(), username(), heroic(), - whats_where(), + paths(), msync() ], prefix_options: poise::PrefixFrameworkOptions {