From 23f5a860136266cad8937fe7992ae8000c0c0553 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Mon, 7 Mar 2022 19:56:12 -0700 Subject: [PATCH] Updated prefix and added help command --- README.md | 22 +++++++++++----------- src/commands.rs | 26 ++++++++++++++++++++++++-- src/helper.rs | 2 ++ src/main.rs | 2 +- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2f2ed84..60c1021 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Discord bot for managing an anonymous [Werewolf Game](https://en.wikipedia.org/wiki/Mafia_(party_game)). ## How It Works -A host gets a list of players to play, and then begins the game with the `!start` command. +A host gets a list of players to play, and then begins the game with the `$start` command. Each player is assigned a channel where they will view the game through. The player can read and send messages in this channel normally. When a message is sent, it is forwarded to all other player channels. The message's author @@ -19,18 +19,18 @@ The game proceeds as a normal Werewolf game. ## Commands ## Host -* `!start ` - starts the game -* `!end` - Ends the current game -* `!say ` - Allows the host to speak into the game chat -* `!broadcast ` - Broadcasts a system message, this message is then pinned in each player channel -* `!next_phase ` - Send the next phase message. Also cycles the phase -* `!terminate ` - Kills a player and removes them from the game -* `!add_time ` - Adds more time to the current game +* `$start ` - starts the game +* `$end` - Ends the current game +* `$say ` - Allows the host to speak into the game chat +* `$broadcast ` - Broadcasts a system message, this message is then pinned in each player channel +* `$next_phase ` - Send the next phase message. Also cycles the phase +* `$terminate ` - Kills a player and removes them from the game +* `$add_time ` - Adds more time to the current game ## Players -* `!vote ` - Casts a vote for a player to be terminated. Only can be used during the day phase -* `!status` - Get the current game status. Includes time left in the phase and current vote tallies -* `!players` - Lists all the players in the game +* `$vote ` - Casts a vote for a player to be terminated. Only can be used during the day phase +* `$status` - Get the current game status. Includes time left in the phase and current vote tallies +* `$players` - Lists all the players in the game ## Example Config ```toml diff --git a/src/commands.rs b/src/commands.rs index fa17f82..2d0e750 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,10 +1,11 @@ use serenity::framework::standard::macros::{command, group}; -use serenity::framework::standard::{Args, CommandResult}; +use serenity::framework::standard::{Args, CommandResult, HelpOptions, CommandGroup, help_commands}; use serenity::framework::StandardFramework; use serenity::model::id::ChannelId; use serenity::model::prelude::{Message, UserId}; use serenity::prelude::Context; use serenity::utils::MessageBuilder; +use serenity::framework::standard::macros::help; use crate::data::{GlobalData, MessageSource, Phase}; use crate::helper; @@ -12,6 +13,7 @@ use crate::helper::{ build_system_message, clear_game_state, get_phase_end_timestamp, print_game_status, save_game_state, send_msg_to_player_channels, }; +use std::collections::HashSet; #[group] #[commands(start, say, end, broadcast, next_phase, terminate, add_time)] @@ -412,9 +414,29 @@ async fn players(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { Ok(()) } +#[help] +#[individual_command_tip = "If you want more information about a specific command, just pass the command as argument."] +#[command_not_found_text = "Could not find: `{}`."] +#[max_levenshtein_distance(3)] +#[indention_prefix = "+"] +#[lacking_role = "Nothing"] +#[wrong_channel = "Strike"] +async fn help( + context: &Context, + msg: &Message, + args: Args, + help_options: &'static HelpOptions, + groups: &[&'static CommandGroup], + owners: HashSet, +) -> CommandResult { + let _ = help_commands::with_embeds(context, msg, args, help_options, groups, owners).await; + Ok(()) +} + pub fn command_framework() -> StandardFramework { StandardFramework::new() - .configure(|c| c.prefix("!")) + .configure(|c| c.prefix('$')) .group(&HOST_GROUP) .group(&PLAYER_GROUP) + .help(&HELP) } diff --git a/src/helper.rs b/src/helper.rs index 9ee6e79..4be577e 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -172,6 +172,8 @@ pub async fn add_user_to_game( .push_line("You will also use this terminal for choosing one of your fellow subjects for termination.") .push_line("Happy testing :)") .push_line("") + .push_line("Do $help to see all commands.") + .push_line("") .push("SUBJECT CODENAME: ") .push_line(&codename) .push(print_game_status(&global_data.game_state)) diff --git a/src/main.rs b/src/main.rs index 774443d..23c1842 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ impl EventHandler for Handler { return; } - if msg.content.starts_with('!') { + if msg.content.starts_with('$') { return; }