From d30f462afcfc73985eab837848715d51e59c2451 Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Sat, 30 Apr 2016 09:21:43 -0400 Subject: [PATCH] Added SelfBot Setting --- src/Discord.Net.Commands/CommandService.cs | 8 +++++++- src/Discord.Net.Commands/CommandServiceConfig.cs | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 8e6f42c51..1baa04270 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -80,7 +80,13 @@ namespace Discord.Commands client.MessageReceived += async (s, e) => { if (_allCommands.Count == 0) return; - if (e.Message.User == null || e.Message.User.Id == Client.CurrentUser.Id) return; + + if (Config.IsSelfBot) + { + if (e.Message.User == null || e.Message.User.Id != Client.CurrentUser.Id) return; // Will only listen to Self + } + else + if (e.Message.User == null || e.Message.User.Id == Client.CurrentUser.Id) return; // Normal expected behavior for bots string msg = e.Message.RawText; if (msg.Length == 0) return; diff --git a/src/Discord.Net.Commands/CommandServiceConfig.cs b/src/Discord.Net.Commands/CommandServiceConfig.cs index f43c838fb..2829cf9d1 100644 --- a/src/Discord.Net.Commands/CommandServiceConfig.cs +++ b/src/Discord.Net.Commands/CommandServiceConfig.cs @@ -14,6 +14,11 @@ namespace Discord.Commands /// and a negative value if the message should be ignored. /// public Func CustomPrefixHandler { get; set; } = null; + /// + /// Changing this to makes the bot ignore all messages, except when the messages are from its own account. + /// This is desired behavior for "Self Bots" only, so unless this bot is being run under a normal user's account, leave it alone!! + /// + public bool IsSelfBot { get; set; } = false; /// Gets or sets whether a help function should be automatically generated. public HelpMode HelpMode { get; set; } = HelpMode.Disabled; @@ -28,9 +33,10 @@ namespace Discord.Commands } public class CommandServiceConfig { - public char? PrefixChar { get; } + public char? PrefixChar { get; } public bool AllowMentionPrefix { get; } public Func CustomPrefixHandler { get; } + public bool IsSelfBot { get; } /// Gets or sets whether a help function should be automatically generated. public HelpMode HelpMode { get; set; } = HelpMode.Disabled; @@ -41,6 +47,7 @@ namespace Discord.Commands AllowMentionPrefix = builder.AllowMentionPrefix; CustomPrefixHandler = builder.CustomPrefixHandler; HelpMode = builder.HelpMode; + IsSelfBot = builder.IsSelfBot; } } }