2022-10-21 19:05:49 +08:00
|
|
|
|
using System;
|
2022-10-21 20:25:48 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2022-10-21 02:29:47 +02:00
|
|
|
|
using System.Linq;
|
2022-10-21 19:05:49 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using DSharpPlus;
|
2022-10-21 02:29:47 +02:00
|
|
|
|
using DSharpPlus.Entities;
|
|
|
|
|
|
using DSharpPlus.Exceptions;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-21 19:05:49 +08:00
|
|
|
|
using Tomlet.Attributes;
|
2022-10-21 02:29:47 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.ChatBots
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
internal enum BridgeDirection
|
|
|
|
|
|
{
|
|
|
|
|
|
Both = 0,
|
|
|
|
|
|
Minecraft,
|
|
|
|
|
|
Discord
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public class DiscordBridge : ChatBot
|
|
|
|
|
|
{
|
2022-10-21 20:25:48 +02:00
|
|
|
|
private static DiscordBridge? instance = null;
|
2022-10-21 21:41:45 +02:00
|
|
|
|
public bool IsConnected { get; private set; }
|
2022-10-21 20:25:48 +02:00
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
private DiscordClient? _client;
|
|
|
|
|
|
private DiscordChannel? _channel;
|
2022-10-22 12:15:44 +02:00
|
|
|
|
private BridgeDirection bridgeDirection = BridgeDirection.Both;
|
2022-10-21 02:29:47 +02:00
|
|
|
|
|
|
|
|
|
|
public static Configs Config = new();
|
|
|
|
|
|
|
|
|
|
|
|
[TomlDoNotInlineObject]
|
|
|
|
|
|
public class Configs
|
|
|
|
|
|
{
|
|
|
|
|
|
[NonSerialized]
|
|
|
|
|
|
private const string BotName = "DiscordBridge";
|
|
|
|
|
|
|
|
|
|
|
|
public bool Enabled = false;
|
|
|
|
|
|
|
2022-10-21 12:25:33 +02:00
|
|
|
|
[TomlInlineComment("$config.ChatBot.DiscordBridge.Token$")]
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public string Token = "your bot token here";
|
|
|
|
|
|
|
2022-10-21 12:25:33 +02:00
|
|
|
|
[TomlInlineComment("$config.ChatBot.DiscordBridge.GuildId$")]
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public ulong GuildId = 1018553894831403028L;
|
|
|
|
|
|
|
2022-10-21 12:25:33 +02:00
|
|
|
|
[TomlInlineComment("$config.ChatBot.DiscordBridge.ChannelId$")]
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public ulong ChannelId = 1018565295654326364L;
|
|
|
|
|
|
|
2022-10-21 12:25:33 +02:00
|
|
|
|
[TomlInlineComment("$config.ChatBot.DiscordBridge.OwnersIds$")]
|
2022-10-21 19:05:49 +08:00
|
|
|
|
public ulong[] OwnersIds = new[] { 978757810781323276UL };
|
2022-10-21 12:25:33 +02:00
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
[TomlInlineComment("$config.ChatBot.DiscordBridge.MessageSendTimeout$")]
|
|
|
|
|
|
public int Message_Send_Timeout = 3;
|
|
|
|
|
|
|
2022-10-21 12:25:33 +02:00
|
|
|
|
[TomlPrecedingComment("$config.ChatBot.DiscordBridge.Formats$")]
|
|
|
|
|
|
public string PrivateMessageFormat = "**[Private Message]** {username}: {message}";
|
|
|
|
|
|
public string PublicMessageFormat = "{username}: {message}";
|
|
|
|
|
|
public string TeleportRequestMessageFormat = "A new Teleport Request from **{username}**!";
|
2022-10-21 19:05:49 +08:00
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
public void OnSettingUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
Message_Send_Timeout = Message_Send_Timeout <= 0 ? 3 : Message_Send_Timeout;
|
|
|
|
|
|
}
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 20:25:48 +02:00
|
|
|
|
public DiscordBridge()
|
|
|
|
|
|
{
|
|
|
|
|
|
instance = this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
RegisterChatBotCommand("dscbridge", "bot.DiscordBridge.desc", "dscbridge direction <both|mc|discord>", OnDscCommand);
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
Task.Run(async () => await MainAsync());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~DiscordBridge()
|
|
|
|
|
|
{
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnUnload()
|
|
|
|
|
|
{
|
|
|
|
|
|
Disconnect();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Disconnect()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_client != null)
|
|
|
|
|
|
{
|
2022-10-22 16:34:26 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_channel != null)
|
|
|
|
|
|
_client.SendMessageAsync(_channel, new DiscordEmbedBuilder
|
|
|
|
|
|
{
|
|
|
|
|
|
Description = Translations.TryGet("bot.DiscordBridge.disconnected"),
|
|
|
|
|
|
Color = new DiscordColor(0xFF0000)
|
|
|
|
|
|
}).Wait(Config.Message_Send_Timeout * 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole("§w§l§f" + Translations.TryGet("bot.DiscordBridge.canceled_sending"));
|
|
|
|
|
|
LogDebugToConsole(e);
|
|
|
|
|
|
}
|
2022-10-21 02:29:47 +02:00
|
|
|
|
|
|
|
|
|
|
_client.DisconnectAsync().Wait();
|
2022-10-21 21:41:45 +02:00
|
|
|
|
IsConnected = false;
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 20:25:48 +02:00
|
|
|
|
public static DiscordBridge? GetInstance()
|
|
|
|
|
|
{
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-22 12:15:44 +02:00
|
|
|
|
private string OnDscCommand(string cmd, string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Length == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args[0].ToLower().Equals("direction"))
|
|
|
|
|
|
{
|
|
|
|
|
|
string direction = args[1].ToLower().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
string? bridgeName = "";
|
|
|
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "b":
|
|
|
|
|
|
case "both":
|
|
|
|
|
|
bridgeName = "bot.DiscordBridge.direction.both";
|
|
|
|
|
|
bridgeDirection = BridgeDirection.Both;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "mc":
|
|
|
|
|
|
case "minecraft":
|
|
|
|
|
|
bridgeName = "bot.DiscordBridge.direction.minecraft";
|
|
|
|
|
|
bridgeDirection = BridgeDirection.Minecraft;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "d":
|
|
|
|
|
|
case "dcs":
|
|
|
|
|
|
case "discord":
|
|
|
|
|
|
bridgeName = "bot.DiscordBridge.direction.discord";
|
|
|
|
|
|
bridgeDirection = BridgeDirection.Discord;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
return Translations.TryGet("bot.DiscordBridge.invalid_direction");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Translations.TryGet("bot.DiscordBridge.direction", Translations.TryGet(bridgeName));
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "dscbridge direction <both|mc|discord>";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
public override void GetText(string text)
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
if (!CanSendMessages())
|
2022-10-21 02:29:47 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
text = GetVerbatim(text).Trim();
|
|
|
|
|
|
|
2022-10-22 14:21:35 +02:00
|
|
|
|
// Stop the crash when an empty text is recived somehow
|
|
|
|
|
|
if (string.IsNullOrEmpty(text))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
string message = "";
|
|
|
|
|
|
string username = "";
|
|
|
|
|
|
bool teleportRequest = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsPrivateMessage(text, ref message, ref username))
|
2022-10-21 12:25:33 +02:00
|
|
|
|
message = Config.PrivateMessageFormat.Replace("{username}", username).Replace("{message}", message).Replace("{timestamp}", GetTimestamp()).Trim();
|
2022-10-21 02:29:47 +02:00
|
|
|
|
else if (IsChatMessage(text, ref message, ref username))
|
2022-10-21 12:25:33 +02:00
|
|
|
|
message = Config.PublicMessageFormat.Replace("{username}", username).Replace("{message}", message).Replace("{timestamp}", GetTimestamp()).Trim();
|
2022-10-21 02:29:47 +02:00
|
|
|
|
else if (IsTeleportRequest(text, ref username))
|
|
|
|
|
|
{
|
2022-10-21 12:25:33 +02:00
|
|
|
|
message = Config.TeleportRequestMessageFormat.Replace("{username}", username).Replace("{timestamp}", GetTimestamp()).Trim();
|
2022-10-21 02:29:47 +02:00
|
|
|
|
teleportRequest = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else message = text;
|
|
|
|
|
|
|
|
|
|
|
|
if (teleportRequest)
|
|
|
|
|
|
{
|
|
|
|
|
|
var messageBuilder = new DiscordMessageBuilder()
|
2022-10-21 02:43:43 +02:00
|
|
|
|
.WithEmbed(new DiscordEmbedBuilder
|
|
|
|
|
|
{
|
|
|
|
|
|
Description = message,
|
|
|
|
|
|
Color = new DiscordColor(0x3399FF)
|
|
|
|
|
|
})
|
|
|
|
|
|
.AddComponents(new DiscordComponent[]{
|
|
|
|
|
|
new DiscordButtonComponent(ButtonStyle.Success, "accept_teleport", "Accept"),
|
|
|
|
|
|
new DiscordButtonComponent(ButtonStyle.Danger, "deny_teleport", "Deny")
|
|
|
|
|
|
});
|
2022-10-21 02:29:47 +02:00
|
|
|
|
|
2022-10-21 20:25:48 +02:00
|
|
|
|
SendMessage(messageBuilder);
|
2022-10-21 02:29:47 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-21 20:25:48 +02:00
|
|
|
|
else SendMessage(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendMessage(string message)
|
|
|
|
|
|
{
|
2022-10-22 14:21:35 +02:00
|
|
|
|
if (!CanSendMessages() || string.IsNullOrEmpty(message))
|
2022-10-21 20:25:48 +02:00
|
|
|
|
return;
|
2022-10-21 02:29:47 +02:00
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_client!.SendMessageAsync(_channel, message).Wait(Config.Message_Send_Timeout * 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole("§w§l§f" + Translations.TryGet("bot.DiscordBridge.canceled_sending"));
|
|
|
|
|
|
LogDebugToConsole(e);
|
|
|
|
|
|
}
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 20:25:48 +02:00
|
|
|
|
public void SendMessage(DiscordMessageBuilder builder)
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
if (!CanSendMessages())
|
2022-10-21 20:25:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_client!.SendMessageAsync(_channel, builder).Wait(Config.Message_Send_Timeout * 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole("§w§l§f" + Translations.TryGet("bot.DiscordBridge.canceled_sending"));
|
|
|
|
|
|
LogDebugToConsole(e);
|
|
|
|
|
|
}
|
2022-10-21 20:25:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendMessage(DiscordEmbedBuilder embedBuilder)
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
if (!CanSendMessages())
|
2022-10-21 20:25:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_client!.SendMessageAsync(_channel, embedBuilder).Wait(Config.Message_Send_Timeout * 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole("§w§l§f" + Translations.TryGet("bot.DiscordBridge.canceled_sending"));
|
|
|
|
|
|
LogDebugToConsole(e);
|
|
|
|
|
|
}
|
2022-10-21 20:25:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
public void SendImage(string filePath, string? text = null)
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
if (!CanSendMessages())
|
2022-10-21 20:25:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
try
|
2022-10-21 20:25:48 +02:00
|
|
|
|
{
|
2022-10-22 16:34:26 +02:00
|
|
|
|
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
|
|
|
|
|
{
|
|
|
|
|
|
filePath = filePath[(filePath.IndexOf(Path.DirectorySeparatorChar) + 1)..];
|
|
|
|
|
|
var messageBuilder = new DiscordMessageBuilder();
|
2022-10-22 14:21:35 +02:00
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
if (text != null)
|
|
|
|
|
|
messageBuilder.WithContent(text);
|
2022-10-21 20:25:48 +02:00
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
messageBuilder.WithFiles(new Dictionary<string, Stream>() { { $"attachment://{filePath}", fs } });
|
2022-10-21 20:25:48 +02:00
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
_client!.SendMessageAsync(_channel, messageBuilder).Wait(Config.Message_Send_Timeout * 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole("§w§l§f" + Translations.TryGet("bot.DiscordBridge.canceled_sending"));
|
|
|
|
|
|
LogDebugToConsole(e);
|
2022-10-21 20:25:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SendFile(FileStream fileStream)
|
|
|
|
|
|
{
|
2022-10-22 12:15:44 +02:00
|
|
|
|
if (!CanSendMessages())
|
2022-10-21 20:25:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-22 16:34:26 +02:00
|
|
|
|
SendMessage(new DiscordMessageBuilder().WithFile(fileStream));
|
2022-10-21 20:25:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-22 12:15:44 +02:00
|
|
|
|
private bool CanSendMessages()
|
|
|
|
|
|
{
|
|
|
|
|
|
return _client == null || _channel == null || bridgeDirection == BridgeDirection.Minecraft ? false : true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
async Task MainAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(Config.Token.Trim()))
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole(Translations.TryGet("bot.DiscordBridge.missing_token"));
|
|
|
|
|
|
UnloadBot();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_client = new DiscordClient(new DiscordConfiguration()
|
|
|
|
|
|
{
|
|
|
|
|
|
Token = Config.Token.Trim(),
|
|
|
|
|
|
TokenType = TokenType.Bot,
|
|
|
|
|
|
AutoReconnect = true,
|
|
|
|
|
|
Intents = DiscordIntents.All,
|
2022-10-21 15:08:11 +02:00
|
|
|
|
MinimumLogLevel = Settings.Config.Logging.DebugMessages ?
|
|
|
|
|
|
(LogLevel.Trace | LogLevel.Information | LogLevel.Debug | LogLevel.Critical | LogLevel.Error | LogLevel.Warning) : LogLevel.None
|
2022-10-21 02:29:47 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
await _client.GetGuildAsync(Config.GuildId);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e is NotFoundException)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole(Translations.TryGet("bot.DiscordBridge.guild_not_found", Config.GuildId));
|
|
|
|
|
|
UnloadBot();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-21 15:08:11 +02:00
|
|
|
|
|
|
|
|
|
|
LogDebugToConsole("Exception when trying to find the guild:");
|
|
|
|
|
|
LogDebugToConsole(e);
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_channel = await _client.GetChannelAsync(Config.ChannelId);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e is NotFoundException)
|
|
|
|
|
|
{
|
|
|
|
|
|
LogToConsole(Translations.TryGet("bot.DiscordBridge.channel_not_found", Config.ChannelId));
|
|
|
|
|
|
UnloadBot();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2022-10-21 15:08:11 +02:00
|
|
|
|
|
|
|
|
|
|
LogDebugToConsole("Exception when trying to find the channel:");
|
|
|
|
|
|
LogDebugToConsole(e);
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_client.MessageCreated += async (source, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Guild.Id != Config.GuildId)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Channel.Id != Config.ChannelId)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-21 19:05:49 +08:00
|
|
|
|
if (!Config.OwnersIds.Contains(e.Author.Id))
|
2022-10-21 02:29:47 +02:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
string message = e.Message.Content.Trim();
|
|
|
|
|
|
|
2022-10-22 14:21:35 +02:00
|
|
|
|
if (string.IsNullOrEmpty(message) || string.IsNullOrWhiteSpace(message))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-10-22 12:15:44 +02:00
|
|
|
|
if (bridgeDirection == BridgeDirection.Discord)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!message.StartsWith(".dscbridge"))
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
if (message.StartsWith("."))
|
|
|
|
|
|
{
|
|
|
|
|
|
message = message[1..];
|
2022-10-22 12:15:44 +02:00
|
|
|
|
await e.Message.CreateReactionAsync(DiscordEmoji.FromName(_client, ":gear:"));
|
2022-10-21 02:43:43 +02:00
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
string? result = "";
|
|
|
|
|
|
PerformInternalCommand(message, ref result);
|
|
|
|
|
|
result = string.IsNullOrEmpty(result) ? "-" : result;
|
2022-10-21 02:43:43 +02:00
|
|
|
|
|
2022-10-21 02:29:47 +02:00
|
|
|
|
await e.Message.DeleteOwnReactionAsync(DiscordEmoji.FromName(_client, ":gear:"));
|
|
|
|
|
|
await e.Message.CreateReactionAsync(DiscordEmoji.FromName(_client, ":white_check_mark:"));
|
2022-10-21 12:25:33 +02:00
|
|
|
|
await e.Message.RespondAsync($"{Translations.TryGet("bot.DiscordBridge.command_executed")}:\n```{result}```");
|
2022-10-21 02:29:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
else SendText(message);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_client.ComponentInteractionCreated += async (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!(e.Id.Equals("accept_teleport") || e.Id.Equals("deny_teleport")))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
string result = e.Id.Equals("accept_teleport") ? "Accepted :white_check_mark:" : "Denied :x:";
|
|
|
|
|
|
SendText(e.Id.Equals("accept_teleport") ? "/tpaccept" : "/tpdeny");
|
|
|
|
|
|
await e.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, new DiscordInteractionResponseBuilder().WithContent(result));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await _client.ConnectAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await _client.SendMessageAsync(_channel, new DiscordEmbedBuilder
|
|
|
|
|
|
{
|
2022-10-21 12:25:33 +02:00
|
|
|
|
Description = Translations.TryGet("bot.DiscordBridge.connected"),
|
2022-10-21 02:29:47 +02:00
|
|
|
|
Color = new DiscordColor(0x00FF00)
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2022-10-21 21:41:45 +02:00
|
|
|
|
IsConnected = true;
|
2022-10-22 16:34:26 +02:00
|
|
|
|
LogToConsole("§y§l§f" + Translations.TryGet("bot.DiscordBridge.connected"));
|
2022-10-21 02:29:47 +02:00
|
|
|
|
await Task.Delay(-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2022-10-22 16:34:26 +02:00
|
|
|
|
LogToConsole("§w§l§f" + Translations.TryGet("bot.DiscordBridge.unknown_error"));
|
2022-10-21 02:29:47 +02:00
|
|
|
|
LogToConsole(e);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|