mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix a crash with Discord Bridge when getting an empty message
This commit is contained in:
parent
2ca470de57
commit
b89aeda198
1 changed files with 12 additions and 2 deletions
|
|
@ -149,6 +149,10 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
text = GetVerbatim(text).Trim();
|
text = GetVerbatim(text).Trim();
|
||||||
|
|
||||||
|
// Stop the crash when an empty text is recived somehow
|
||||||
|
if (string.IsNullOrEmpty(text))
|
||||||
|
return;
|
||||||
|
|
||||||
string message = "";
|
string message = "";
|
||||||
string username = "";
|
string username = "";
|
||||||
bool teleportRequest = false;
|
bool teleportRequest = false;
|
||||||
|
|
@ -185,7 +189,7 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
public void SendMessage(string message)
|
public void SendMessage(string message)
|
||||||
{
|
{
|
||||||
if (!CanSendMessages())
|
if (!CanSendMessages() || string.IsNullOrEmpty(message))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_client!.SendMessageAsync(_channel, message).Wait();
|
_client!.SendMessageAsync(_channel, message).Wait();
|
||||||
|
|
@ -215,7 +219,10 @@ namespace MinecraftClient.ChatBots
|
||||||
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||||
{
|
{
|
||||||
filePath = filePath[(filePath.IndexOf(Path.DirectorySeparatorChar) + 1)..];
|
filePath = filePath[(filePath.IndexOf(Path.DirectorySeparatorChar) + 1)..];
|
||||||
var messageBuilder = new DiscordMessageBuilder().WithContent(text);
|
var messageBuilder = new DiscordMessageBuilder();
|
||||||
|
|
||||||
|
if (text != null)
|
||||||
|
messageBuilder.WithContent(text);
|
||||||
|
|
||||||
messageBuilder.WithFiles(new Dictionary<string, Stream>() { { $"attachment://{filePath}", fs } });
|
messageBuilder.WithFiles(new Dictionary<string, Stream>() { { $"attachment://{filePath}", fs } });
|
||||||
|
|
||||||
|
|
@ -305,6 +312,9 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
string message = e.Message.Content.Trim();
|
string message = e.Message.Content.Trim();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(message) || string.IsNullOrWhiteSpace(message))
|
||||||
|
return;
|
||||||
|
|
||||||
if (bridgeDirection == BridgeDirection.Discord)
|
if (bridgeDirection == BridgeDirection.Discord)
|
||||||
{
|
{
|
||||||
if (!message.StartsWith(".dscbridge"))
|
if (!message.StartsWith(".dscbridge"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue