diff --git a/MinecraftClient/config/ChatBots/VkMessager.cs b/MinecraftClient/config/ChatBots/VkMessager.cs index deed8965..b9fe4f6e 100644 --- a/MinecraftClient/config/ChatBots/VkMessager.cs +++ b/MinecraftClient/config/ChatBots/VkMessager.cs @@ -21,13 +21,54 @@ MCC.LoadBot(new VkMessager(vkToken, chatId, botCommunityId)); /// /// This bot forwarding messages between Minecraft and VKonrakte chats. /// Shares only messages that starts with dot ("."). Example: .Hello! -/// Also, send message to VK when any player joins or leaves. /// /// Needs: /// - VK Community token (also LongPool API with NewMessageEvent, api >= 5.80), /// - VK ChatId (typically 2000000001, etc.) /// - Bot's CommunityId /// +public class VkMessager : ChatBot +{ + private VkLongPoolClient VkLongPoolClient { get; set; } + private readonly string ChatId; + + public VkMessager(string vkToken, string chatId, string botCommunityId) + { + VkLongPoolClient = new VkLongPoolClient(vkToken, botCommunityId, ProcessMsgFromVk); + ChatId = chatId; + } + + public override void Initialize() + { + LogToConsole("Bot enabled!"); + } + + public override void GetText(string text) + { + // Here you can process a message coming from the Minecraft chat + // Example below: Forward a message to VKonrakte if it starts with a dot + + string message = ""; + string username = ""; + text = GetVerbatim(text); + + if (IsChatMessage(GetVerbatim(text), ref message, ref username) && message.StartsWith(".")) + { + this.VkLongPoolClient.Messages_Send_Text(this.ChatId, text); + } + } + + private void ProcessMsgFromVk(string senderId, string peer_id, string text, string conversation_message_id, string id, string event_id) + { + // Here you can process a message coming from VKonrakte + // Example below: Forward a message to Minecraft if it starts wit a dot + + if (text.StartsWith(".")) + { + SendText(text); + } + } +} /// /// Client for VK Community (bot) LongPool API.