diff --git a/src/ARKServerManager/App.config b/src/ARKServerManager/App.config
index a136ee00..f74ceca5 100644
--- a/src/ARKServerManager/App.config
+++ b/src/ARKServerManager/App.config
@@ -863,6 +863,9 @@
Info
+
+ False
+
diff --git a/src/ARKServerManager/App.xaml.cs b/src/ARKServerManager/App.xaml.cs
index 74642a34..aded5630 100644
--- a/src/ARKServerManager/App.xaml.cs
+++ b/src/ARKServerManager/App.xaml.cs
@@ -612,7 +612,7 @@ namespace ServerManagerTool
discordWhiteList.AddRange(Config.Default.DiscordBotWhitelist.Cast());
}
- await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataDir, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);
+ await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataDir, Config.Default.DiscordBotAllowAllBots, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);
if (_tokenSourceDiscordBot != null)
{
diff --git a/src/ARKServerManager/Config.Designer.cs b/src/ARKServerManager/Config.Designer.cs
index 60833055..ae20bf76 100644
--- a/src/ARKServerManager/Config.Designer.cs
+++ b/src/ARKServerManager/Config.Designer.cs
@@ -3032,5 +3032,17 @@ namespace ServerManagerTool {
return ((int)(this["DiscordBotStatusCheckTime"]));
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ public bool DiscordBotAllowAllBots {
+ get {
+ return ((bool)(this["DiscordBotAllowAllBots"]));
+ }
+ set {
+ this["DiscordBotAllowAllBots"] = value;
+ }
+ }
}
}
diff --git a/src/ARKServerManager/Config.settings b/src/ARKServerManager/Config.settings
index 19c0a3ec..6f6869f6 100644
--- a/src/ARKServerManager/Config.settings
+++ b/src/ARKServerManager/Config.settings
@@ -837,5 +837,8 @@
10
+
+ False
+
\ No newline at end of file
diff --git a/src/ARKServerManager/Globalization/en-US/en-US.xaml b/src/ARKServerManager/Globalization/en-US/en-US.xaml
index 5d540166..d905aa52 100644
--- a/src/ARKServerManager/Globalization/en-US/en-US.xaml
+++ b/src/ARKServerManager/Globalization/en-US/en-US.xaml
@@ -634,6 +634,8 @@
Log Level:Get Token...Help...
+ Allow All Bots
+ If enabled, the server manager bot will respond to all other bots, otherwise they will be ignored unless they are in the whitelist.Bot WhitelistBot IDThe id of the bot to whitelist.
diff --git a/src/ARKServerManager/UserControls/GlobalSettingsControl.xaml b/src/ARKServerManager/UserControls/GlobalSettingsControl.xaml
index bee4de9a..b82088fc 100644
--- a/src/ARKServerManager/UserControls/GlobalSettingsControl.xaml
+++ b/src/ARKServerManager/UserControls/GlobalSettingsControl.xaml
@@ -586,12 +586,14 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -629,7 +631,7 @@
-
+
@@ -677,6 +679,8 @@
+
+
diff --git a/src/ARKServerManager/Utils/DiscordBotHelper.cs b/src/ARKServerManager/Utils/DiscordBotHelper.cs
index dace86c7..3ee4e57b 100644
--- a/src/ARKServerManager/Utils/DiscordBotHelper.cs
+++ b/src/ARKServerManager/Utils/DiscordBotHelper.cs
@@ -165,7 +165,9 @@ namespace ServerManagerTool.Utils
else
{
var mapName = _globalizer.GetResourceString($"Map_{info.Map}") ?? info.Map;
- response.Add($"```{info.Name}\n{_globalizer.GetResourceString("DiscordBot_MapLabel")} {mapName}\n{_globalizer.GetResourceString("ServerSettings_PlayersLabel")} {info.Players} / {info.MaxPlayers}```");
+ response.Add($"```{info.Name}\n" +
+ $"{_globalizer.GetResourceString("DiscordBot_MapLabel")} {mapName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_PlayersLabel")} {info.Players} / {info.MaxPlayers}```");
}
}
}
@@ -193,7 +195,10 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
- response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
+ response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n" +
+ (string.IsNullOrWhiteSpace(server.Profile.DiscordAlias) ? "" : $"{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n") +
+ $"{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
}
}).Wait();
@@ -212,7 +217,12 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
- response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}\n{_globalizer.GetResourceString("ServerSettings_StatusLabel")} {server.Runtime.StatusString}\n{_globalizer.GetResourceString("ServerSettings_AvailabilityLabel")} {_globalizer.GetResourceString($"ServerSettings_Availability_{server.Runtime.Availability}")}```");
+ response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n" +
+ (string.IsNullOrWhiteSpace(server.Profile.DiscordAlias) ? "" : $"{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n") +
+ $"{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_StatusLabel")} {server.Runtime.StatusString}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_AvailabilityLabel")} {_globalizer.GetResourceString($"ServerSettings_Availability_{server.Runtime.Availability}")}```");
}
}).Wait();
diff --git a/src/ARKServerManager/VersionFeed.xml b/src/ARKServerManager/VersionFeed.xml
index d2349003..4841b4be 100644
--- a/src/ARKServerManager/VersionFeed.xml
+++ b/src/ARKServerManager/VersionFeed.xml
@@ -19,16 +19,17 @@
NEW
+
Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
Global Settings - Discord Bot section - Added a log level droplist.
+
Global Settings - Discord Bot section - Added a checkbox to allow all bots.
Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
-
Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
CHANGE
Made changes to the code to help improve performance.
-
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change the existing functionality, but you can now change it.
+
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
+
Global Settings - Discord Bot section - Added a checkbox to allow all bots.
@@ -118,7 +119,7 @@
CHANGE
-
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change the existing functionality, but you can now change it.
+
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
zh-CN Translation file updated.
diff --git a/src/ConanServerManager/App.config b/src/ConanServerManager/App.config
index 61f2b35c..b96df230 100644
--- a/src/ConanServerManager/App.config
+++ b/src/ConanServerManager/App.config
@@ -629,6 +629,9 @@
Info
+
+ False
+
\ No newline at end of file
diff --git a/src/ConanServerManager/App.xaml.cs b/src/ConanServerManager/App.xaml.cs
index 6096007d..55b63548 100644
--- a/src/ConanServerManager/App.xaml.cs
+++ b/src/ConanServerManager/App.xaml.cs
@@ -593,7 +593,7 @@ namespace ServerManagerTool
discordWhiteList.AddRange(Config.Default.DiscordBotWhitelist.Cast());
}
- await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataPath, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);
+ await ServerManagerBotFactory.GetServerManagerBot()?.StartAsync(Config.Default.DiscordBotLogLevel, Config.Default.DiscordBotToken, Config.Default.DiscordBotPrefix, Config.Default.DataPath, Config.Default.DiscordBotAllowAllBots, discordWhiteList, DiscordBotHelper.HandleDiscordCommand, DiscordBotHelper.HandleTranslation, _tokenSourceDiscordBot.Token);
if (_tokenSourceDiscordBot != null)
{
diff --git a/src/ConanServerManager/Config.Designer.cs b/src/ConanServerManager/Config.Designer.cs
index 9a861e60..b8f4d5e1 100644
--- a/src/ConanServerManager/Config.Designer.cs
+++ b/src/ConanServerManager/Config.Designer.cs
@@ -2185,5 +2185,17 @@ namespace ServerManagerTool {
return ((int)(this["DiscordBotStatusCheckTime"]));
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("False")]
+ public bool DiscordBotAllowAllBots {
+ get {
+ return ((bool)(this["DiscordBotAllowAllBots"]));
+ }
+ set {
+ this["DiscordBotAllowAllBots"] = value;
+ }
+ }
}
}
diff --git a/src/ConanServerManager/Config.settings b/src/ConanServerManager/Config.settings
index 3d319f4d..a9c38c97 100644
--- a/src/ConanServerManager/Config.settings
+++ b/src/ConanServerManager/Config.settings
@@ -603,5 +603,8 @@
10
+
+ False
+
\ No newline at end of file
diff --git a/src/ConanServerManager/Globalization/en-US/en-US.xaml b/src/ConanServerManager/Globalization/en-US/en-US.xaml
index 392e8d78..ddb3222f 100644
--- a/src/ConanServerManager/Globalization/en-US/en-US.xaml
+++ b/src/ConanServerManager/Globalization/en-US/en-US.xaml
@@ -798,6 +798,8 @@
Log Level:Get Token...Help...
+ Allow All Bots
+ If enabled, the server manager bot will respond to all other bots, otherwise they will be ignored unless they are in the whitelist.Bot WhitelistBot IDThe id of the bot to whitelist.
diff --git a/src/ConanServerManager/UserControls/GlobalSettingsControl.xaml b/src/ConanServerManager/UserControls/GlobalSettingsControl.xaml
index c2676d59..430ccbd6 100644
--- a/src/ConanServerManager/UserControls/GlobalSettingsControl.xaml
+++ b/src/ConanServerManager/UserControls/GlobalSettingsControl.xaml
@@ -534,12 +534,14 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -577,7 +579,7 @@
-
+
@@ -625,6 +627,8 @@
+
+
diff --git a/src/ConanServerManager/Utils/DiscordBotHelper.cs b/src/ConanServerManager/Utils/DiscordBotHelper.cs
index aa82a14c..bd7fb824 100644
--- a/src/ConanServerManager/Utils/DiscordBotHelper.cs
+++ b/src/ConanServerManager/Utils/DiscordBotHelper.cs
@@ -165,7 +165,9 @@ namespace ServerManagerTool.Utils
else
{
var mapName = _globalizer.GetResourceString($"Map_{info.Map}") ?? info.Map;
- response.Add($"```{info.Name}\n{_globalizer.GetResourceString("DiscordBot_MapLabel")} {mapName}\n{_globalizer.GetResourceString("ServerSettings_PlayersLabel")} {info.Players} / {info.MaxPlayers}```");
+ response.Add($"```{info.Name}\n" +
+ $"{_globalizer.GetResourceString("DiscordBot_MapLabel")} {mapName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_PlayersLabel")} {info.Players} / {info.MaxPlayers}```");
}
}
}
@@ -193,7 +195,10 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
- response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
+ response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n" +
+ (string.IsNullOrWhiteSpace(server.Profile.DiscordAlias) ? "" : $"{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n") +
+ $"{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}```");
}
}).Wait();
@@ -212,7 +217,12 @@ namespace ServerManagerTool.Utils
response.Add($"**{_globalizer.GetResourceString("DiscordBot_CountLabel")}** {serverList.Count()}");
foreach (var server in serverList)
{
- response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}\n{_globalizer.GetResourceString("ServerSettings_StatusLabel")} {server.Runtime.StatusString}\n{_globalizer.GetResourceString("ServerSettings_AvailabilityLabel")} {_globalizer.GetResourceString($"ServerSettings_Availability_{server.Runtime.Availability}")}```");
+ response.Add($"```{_globalizer.GetResourceString("ServerSettings_ProfileLabel")} {server.Profile.ProfileName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_ProfileIdLabel")} {server.Profile.ProfileID}\n" +
+ (string.IsNullOrWhiteSpace(server.Profile.DiscordAlias) ? "" : $"{_globalizer.GetResourceString("ServerSettings_DiscordAliasLabel")} {server.Profile.DiscordAlias}\n") +
+ $"{_globalizer.GetResourceString("ServerSettings_ServerNameLabel")} {server.Profile.ServerName}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_StatusLabel")} {server.Runtime.StatusString}\n" +
+ $"{_globalizer.GetResourceString("ServerSettings_AvailabilityLabel")} {_globalizer.GetResourceString($"ServerSettings_Availability_{server.Runtime.Availability}")}```");
}
}).Wait();
diff --git a/src/ConanServerManager/VersionFeed.xml b/src/ConanServerManager/VersionFeed.xml
index d810c45a..1178578f 100644
--- a/src/ConanServerManager/VersionFeed.xml
+++ b/src/ConanServerManager/VersionFeed.xml
@@ -19,16 +19,17 @@
NEW
+
Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
Global Settings - Discord Bot section - Added a log level droplist.
+
Global Settings - Discord Bot section - Added a checkbox to allow all bots.
Global Settings - Discord Bot section - Added a whitelist to allow bots to send commands to the server manager.
Server Settings - Discord Bot section - Added an alias that can be used with the discord command instead of the profile id.
-
Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
CHANGE
Made changes to the code to help improve performance.
-
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change the existing functionality, but you can now change it.
+
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
Main Window - Added Discord Bot Status and a button to Stop/Start the discord bot.
+
Global Settings - Discord Bot section - Added a checkbox to allow all bots.
@@ -116,7 +117,7 @@
CHANGE
-
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change the existing functionality, but you can now change it.
+
Removed the mandatory requirement to enter the '!' after the discord prefix. The '!' has been added to the existing prefix so no change to existing functionality, but you can now change it.
diff --git a/src/ServerManager.Discord/Interfaces/IServerManagerBot.cs b/src/ServerManager.Discord/Interfaces/IServerManagerBot.cs
index 7dc916c3..a4ef8f1e 100644
--- a/src/ServerManager.Discord/Interfaces/IServerManagerBot.cs
+++ b/src/ServerManager.Discord/Interfaces/IServerManagerBot.cs
@@ -10,6 +10,6 @@ namespace ServerManagerTool.DiscordBot.Interfaces
{
CancellationToken Token { get; }
- Task StartAsync(LogLevel logLevel, string discordToken, string commandPrefix, string dataDirectory, IEnumerable botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token);
+ Task StartAsync(LogLevel logLevel, string discordToken, string commandPrefix, string dataDirectory, bool allowAllBots, IEnumerable botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token);
}
}
diff --git a/src/ServerManager.Discord/Models/DiscordBotWhitelistConfig.cs b/src/ServerManager.Discord/Models/DiscordBotConfig.cs
similarity index 69%
rename from src/ServerManager.Discord/Models/DiscordBotWhitelistConfig.cs
rename to src/ServerManager.Discord/Models/DiscordBotConfig.cs
index bbb40957..c6a0ca59 100644
--- a/src/ServerManager.Discord/Models/DiscordBotWhitelistConfig.cs
+++ b/src/ServerManager.Discord/Models/DiscordBotConfig.cs
@@ -2,8 +2,10 @@
namespace ServerManagerTool.DiscordBot.Models
{
- public class DiscordBotWhitelistConfig
+ public class DiscordBotConfig
{
+ public bool AllowAllBots { get; set; } = false;
+
public List DiscordBotWhitelists { get; set; } = new List();
}
}
diff --git a/src/ServerManager.Discord/ServerManagerBot.cs b/src/ServerManager.Discord/ServerManagerBot.cs
index 08652fdb..957e8e82 100644
--- a/src/ServerManager.Discord/ServerManagerBot.cs
+++ b/src/ServerManager.Discord/ServerManagerBot.cs
@@ -28,7 +28,7 @@ namespace ServerManagerTool.DiscordBot
public CancellationToken Token { get; private set; }
public bool Started { get; private set; }
- public async Task StartAsync(LogLevel logLevel, string discordToken, string commandPrefix, string dataDirectory, IEnumerable botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token)
+ public async Task StartAsync(LogLevel logLevel, string discordToken, string commandPrefix, string dataDirectory, bool allowAllBots, IEnumerable botWhitelist, HandleCommandDelegate handleCommandCallback, HandleTranslationDelegate handleTranslationCallback, CancellationToken token)
{
if (string.IsNullOrWhiteSpace(commandPrefix) || string.IsNullOrWhiteSpace(discordToken) || handleTranslationCallback is null || handleCommandCallback is null)
{
@@ -74,9 +74,10 @@ namespace ServerManagerTool.DiscordBot
LogLevel = LogLevelHelper.GetLogSeverity(logLevel),
};
- var discordBotWhitelistConfig = new DiscordBotWhitelistConfig
+ var discordBotConfig = new DiscordBotConfig
{
- DiscordBotWhitelists = new List ( botWhitelist.Select(i => new DiscordBotWhitelist { BotId = i }) )
+ AllowAllBots = allowAllBots,
+ DiscordBotWhitelists = new List ( botWhitelist.Select(i => new DiscordBotWhitelist { BotId = i }) ),
};
// Build the service provider
@@ -93,7 +94,7 @@ namespace ServerManagerTool.DiscordBot
.AddSingleton()
.AddSingleton()
.AddSingleton(config)
- .AddSingleton(discordBotWhitelistConfig)
+ .AddSingleton(discordBotConfig)
.AddSingleton(handleCommandCallback)
.AddSingleton(handleTranslationCallback)
.AddSingleton(this);
diff --git a/src/ServerManager.Discord/Services/CommandHandlerService.cs b/src/ServerManager.Discord/Services/CommandHandlerService.cs
index 655256b7..6882a76b 100644
--- a/src/ServerManager.Discord/Services/CommandHandlerService.cs
+++ b/src/ServerManager.Discord/Services/CommandHandlerService.cs
@@ -17,53 +17,65 @@ namespace ServerManagerTool.DiscordBot.Services
private readonly LoggingService _logger;
private readonly IConfigurationRoot _config;
private readonly IServiceProvider _provider;
- private readonly DiscordBotWhitelistConfig _botWhitelist;
+ private readonly DiscordBotConfig _botConfig;
- public CommandHandlerService(DiscordSocketClient discord, CommandService commands, LoggingService logger, IConfigurationRoot config, IServiceProvider provider, DiscordBotWhitelistConfig botWhitelist)
+ public CommandHandlerService(DiscordSocketClient discord, CommandService commands, LoggingService logger, IConfigurationRoot config, IServiceProvider provider, DiscordBotConfig botConfig)
{
_discord = discord;
_commands = commands;
_logger = logger;
_config = config;
_provider = provider;
- _botWhitelist = botWhitelist ?? new DiscordBotWhitelistConfig();
+ _botConfig = botConfig ?? new DiscordBotConfig();
_discord.MessageReceived += OnMessageReceivedAsync;
}
private async Task OnMessageReceivedAsync(SocketMessage s)
{
if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"]))
- {
await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Intercepted the following message from {s.Author.Username} ({s.Author.Id}) - {s.Content}"));
- }
- // Ensure the message is from a user/bot
+ // Ensure the message is a valid user socket message
if (!(s is SocketUserMessage msg))
- {
return;
- }
- // Ignore self when checking commands
- if (msg.Author == _discord.CurrentUser)
+ // Ignore self
+ if (msg.Author.Id == _discord.CurrentUser.Id)
{
+ if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"]))
+ await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Message has come from this bot, message will be ignored."));
+
return;
}
// check if the author is a bot
if (msg.Author.IsBot)
- {
- // check if bot is on the whitelist
- if (!_botWhitelist.DiscordBotWhitelists.Any(b => b.BotId.Equals(msg.Author.Id.ToString())))
+ if (_botConfig.AllowAllBots)
{
- // Tell bot to ignore
- return;
+ if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"]))
+ await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Message has come from another bot, allow all bots enabled."));
}
- }
+ else
+ {
+ if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"]))
+ await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Message has come from another bot, checking if bot is in the whitelist."));
+
+ if (!_botConfig.DiscordBotWhitelists.Any(b => b.BotId.Equals(msg.Author.Id.ToString())))
+ {
+ if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"]))
+ await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Message has come from another bot, bot is not in the whitelist, message will be ignored."));
+
+ return;
+ }
+ }
// Check if the message has a valid command prefix
var argPos = 0;
if (msg.HasStringPrefix(_config["DiscordSettings:Prefix"], ref argPos) || msg.HasMentionPrefix(_discord.CurrentUser, ref argPos))
{
+ if (LogLevel.Debug.ToString().Equals(_config["DiscordSettings:LogLevel"]))
+ await _logger?.OnLogAsync(new LogMessage(LogSeverity.Debug, MessageSource.System.ToString(), $"Message prefix matched, message will be processed."));
+
// Create the command context
var context = new SocketCommandContext(_discord, msg);