From b19d64b69c0230abca286512a7a5a3ce66b68ec6 Mon Sep 17 00:00:00 2001
From: tec <tec@ucc.gu.uwa.edu.au>
Date: Fri, 16 Aug 2019 22:50:06 +0800
Subject: [PATCH] Make command prefix more easily variable

---
 src/config.rs |  2 ++
 src/main.rs   | 19 +++++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index 0790fd8..5fc3bb7 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -21,6 +21,8 @@ pub static TIEBREAKER_ROLE: u64 = 607509283483025409;
 pub static UNREGISTERED_MEMBER_ROLE: u64 = 608282247350714408;
 pub static REGISTERED_MEMBER_ROLE: u64 = 608282133118582815;
 
+pub static COMMAND_PREFIX: &str = "!";
+
 pub static FOR_VOTE: &str = "👍";
 pub static AGAINST_VOTE: &str = "👎";
 pub static ABSTAIN_VOTE: &str = "🙊";
diff --git a/src/main.rs b/src/main.rs
index c14064f..e4c67b4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -26,7 +26,7 @@ impl EventHandler for Handler {
     // Event handlers are dispatched through a threadpool, and so multiple
     // events can be dispatched simultaneously.
     fn message(&self, ctx: Context, msg: Message) {
-        if msg.content.starts_with("!") {
+        if msg.content.starts_with(config::COMMAND_PREFIX) {
             let message_content: Vec<_> = msg.content[1..].splitn(2, ' ').collect();
             match message_content[0] {
                 "register" => {
@@ -49,9 +49,14 @@ impl EventHandler for Handler {
                 }
                 "help" => {
                     let mut message = MessageBuilder::new();
-                    message.push_line("Use !move <action> to make a circular motion");
-                    message
-                        .push_line("Use !poll <proposal> to see what people think about something");
+                    message.push_line(format!(
+                        "Use {}move <action> to make a circular motion",
+                        config::COMMAND_PREFIX
+                    ));
+                    message.push_line(format!(
+                        "Use {}poll <proposal> to see what people think about something",
+                        config::COMMAND_PREFIX
+                    ));
                     e!(
                         "Error sending message: {:?}",
                         msg.channel_id.say(&ctx.http, message.build())
@@ -60,8 +65,10 @@ impl EventHandler for Handler {
                 _ => {
                     e!(
                         "Error sending message: {:?}",
-                        msg.channel_id
-                            .say(&ctx.http, "Unrecognised command. Try !help")
+                        msg.channel_id.say(
+                            &ctx.http,
+                            format!("Unrecognised command. Try {}help", config::COMMAND_PREFIX)
+                        )
                     );
                 }
             }
-- 
GitLab