浏览代码

Add command text channel limitation

Frans Bergman 7 年之前
父节点
当前提交
3ae8a2d95d
共有 2 个文件被更改,包括 11 次插入1 次删除
  1. 2 0
      config/example.toml
  2. 9 1
      src/main.rs

+ 2 - 0
config/example.toml

@@ -1,2 +1,4 @@
 discord_token = "token goes here"
 command_prefix = "!"
+# Optionally limit the bot to only accept commands from a specific channel
+# command_channel = channel_id_here

+ 9 - 1
src/main.rs

@@ -8,12 +8,13 @@ extern crate serde_derive;
 use std::fs::File;
 use std::io::prelude::*;
 use discord::{Discord, State};
-use discord::model::Event;
+use discord::model::{Event, ChannelId};
 
 #[derive(Debug, Deserialize)]
 struct Config {
     discord_token: String,
     command_prefix: String,
+    command_channel: Option<u64>,
 }
 
 pub fn main() {
@@ -60,6 +61,13 @@ pub fn main() {
                     continue
                 }
 
+                // ignore message outside of command channel
+                if let Some(channel_id) = config.command_channel {
+                    if ChannelId(channel_id) != message.channel_id {
+                        continue
+                    }
+                }
+
                 // reply to a command if there was one
                 let mut split = message.content.split_whitespace();
                 let first_word = split.next().unwrap_or("");