mirror of
https://github.com/Sanae6/SmoOnlineServer.git
synced 2024-11-22 03:05:16 +00:00
Removed some log messages as they would trigger before prefix checking, would start spamming the server if they remained
This commit is contained in:
parent
86fb18962f
commit
4c4ce35f14
1 changed files with 12 additions and 27 deletions
|
@ -1,6 +1,4 @@
|
||||||
#define SEND_RESP_TO_BAD_REQ //should the bot send a message to people who attempt to run a command from an invalid location? (Comment out to disable)
|
#define SEND_RESP_TO_BAD_REQ_DM // should the bot send a message to people who attempt to run commands/speak in dms
|
||||||
#define LOG_BAD_REQ //should the bot log aformentioned invalid requests?
|
|
||||||
#define LOG_CHANNELS_ON_COMMAND_ATTEMPT_VERBOSE //print a message describing relevant channel ids whenever a command is attempted to be sent?
|
|
||||||
|
|
||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
|
@ -15,7 +13,7 @@ public class DiscordBot {
|
||||||
private Settings.DiscordTable Config => Settings.Instance.Discord;
|
private Settings.DiscordTable Config => Settings.Instance.Discord;
|
||||||
private string Prefix => Config.Prefix;
|
private string Prefix => Config.Prefix;
|
||||||
private readonly Logger Logger = new Logger("Discord");
|
private readonly Logger Logger = new Logger("Discord");
|
||||||
private DiscordChannel? CommandChannel;
|
//private DiscordChannel? CommandChannel;
|
||||||
private DiscordChannel? LogChannel;
|
private DiscordChannel? LogChannel;
|
||||||
private bool Reconnecting;
|
private bool Reconnecting;
|
||||||
|
|
||||||
|
@ -45,9 +43,10 @@ public class DiscordBot {
|
||||||
try {
|
try {
|
||||||
if (DiscordClient == null || Token != Config.Token)
|
if (DiscordClient == null || Token != Config.Token)
|
||||||
await Run();
|
await Run();
|
||||||
if (Config.CommandChannel != null)
|
//CommandChannel not currently used
|
||||||
CommandChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.CommandChannel)) ??
|
//if (Config.CommandChannel != null)
|
||||||
throw new NullReferenceException("Discord client not setup yet!"));
|
// CommandChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.CommandChannel)) ??
|
||||||
|
// throw new NullReferenceException("Discord client not setup yet!"));
|
||||||
if (Config.LogChannel != null)
|
if (Config.LogChannel != null)
|
||||||
LogChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.LogChannel)) ??
|
LogChannel = await (DiscordClient?.GetChannelAsync(ulong.Parse(Config.LogChannel)) ??
|
||||||
throw new NullReferenceException("Discord client not setup yet!"));
|
throw new NullReferenceException("Discord client not setup yet!"));
|
||||||
|
@ -99,40 +98,26 @@ public class DiscordBot {
|
||||||
Logger.Info(
|
Logger.Info(
|
||||||
$"Discord bot logged in as {DiscordClient.CurrentUser.Username}#{DiscordClient.CurrentUser.Discriminator}");
|
$"Discord bot logged in as {DiscordClient.CurrentUser.Username}#{DiscordClient.CurrentUser.Discriminator}");
|
||||||
Reconnecting = false;
|
Reconnecting = false;
|
||||||
string mentionPrefix = $"{DiscordClient.CurrentUser.Mention} ";
|
string mentionPrefix = $"{DiscordClient.CurrentUser.Mention}";
|
||||||
DiscordClient.MessageCreated += async (_, args) => {
|
DiscordClient.MessageCreated += async (_, args) => {
|
||||||
if (args.Author.IsCurrent) return; //dont respond to commands from ourselves (prevent "sql-injection" esq attacks)
|
if (args.Author.IsCurrent) return; //dont respond to commands from ourselves (prevent "sql-injection" esq attacks)
|
||||||
#if LOG_CHANNELS_ON_COMMAND_ATTEMPT_VERBOSE
|
|
||||||
//Logger.Info($"Message recieved on channel \"{args.Channel.Id}\", accepting commands from channel \"{Config.LogChannel ?? "(Any Channel)"}\", do channels match: {(args.Channel.Id.ToString() == Config.LogChannel) || (Config.LogChannel == null && !(args.Channel is DiscordDmChannel))}");
|
|
||||||
Logger.Info($"cmdchannel == channel id exec ({args.Channel.Id.ToString() == Config.CommandChannel})");
|
|
||||||
#endif
|
|
||||||
//prevent commands via dm and non-public channels
|
//prevent commands via dm and non-public channels
|
||||||
if (Config.CommandChannel == null) {
|
if (Config.CommandChannel == null) {
|
||||||
if (!warnedAboutNullLogChannel) {
|
if (!warnedAboutNullLogChannel) {
|
||||||
Logger.Warn("You probably should set your LogChannel in settings.json");
|
Logger.Warn("You probably should set your CommandChannel in settings.json");
|
||||||
warnedAboutNullLogChannel = true;
|
warnedAboutNullLogChannel = true;
|
||||||
}
|
}
|
||||||
if (args.Channel is DiscordDmChannel) {
|
if (args.Channel is DiscordDmChannel) {
|
||||||
#if LOG_BAD_REQ
|
#if SEND_RESP_TO_BAD_REQ_DM
|
||||||
Logger.Warn("A command was sent to the bot in a direct message channel. This will not be processed. (Send commands in the specified LogChannel in settings.json or only in public channels)");
|
await args.Message.RespondAsync("DM's are not valid for running commands or communication to the bot. (Your command was not processed).");
|
||||||
#endif
|
|
||||||
#if SEND_RESP_TO_BAD_REQ
|
|
||||||
await args.Message.RespondAsync("This channel is not valid for running commands. (Your command was not processed).");
|
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ulong chId = ulong.Parse(Config.CommandChannel);
|
ulong chId = ulong.Parse(Config.CommandChannel);
|
||||||
if (args.Channel.Id != chId) {
|
if (args.Channel.Id != chId)
|
||||||
#if LOG_BAD_REQ
|
|
||||||
Logger.Warn("A command was sent to the bot in some non-public channel. This will not be processed. (Send commands in the specified LogChannel in settings.json or only in public channels)");
|
|
||||||
#endif
|
|
||||||
#if SEND_RESP_TO_BAD_REQ
|
|
||||||
await args.Message.RespondAsync("This channel is not valid for running commands. (Your command was not processed).");
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//run command
|
//run command
|
||||||
try {
|
try {
|
||||||
|
@ -146,7 +131,7 @@ public class DiscordBot {
|
||||||
resp = string.Join('\n', CommandHandler.GetResult(msg.Content[Prefix.Length..]).ReturnStrings);
|
resp = string.Join('\n', CommandHandler.GetResult(msg.Content[Prefix.Length..]).ReturnStrings);
|
||||||
} else if (msg.Content.StartsWith(mentionPrefix)) {
|
} else if (msg.Content.StartsWith(mentionPrefix)) {
|
||||||
await msg.Channel.TriggerTypingAsync();
|
await msg.Channel.TriggerTypingAsync();
|
||||||
resp = string.Join('\n', CommandHandler.GetResult(msg.Content[mentionPrefix.Length..]).ReturnStrings);
|
resp = string.Join('\n', CommandHandler.GetResult(msg.Content[mentionPrefix.Length..].TrimStart()).ReturnStrings);
|
||||||
}
|
}
|
||||||
if (resp != null)
|
if (resp != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue