From 712875251ef8c14d72ea94de974be0ca48adffde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=20=D0=94=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= <35975332+Nekiplay@users.noreply.github.com> Date: Sat, 1 Aug 2020 17:24:17 +0500 Subject: [PATCH] Add UnLoadBot to ChatBot API (#1164) Add UnloadBot Add BotList Update VkMessager Remove debug info --- MinecraftClient/ChatBot.cs | 2 ++ MinecraftClient/config/ChatBots/VkMessager.cs | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 90173a6f..039be7eb 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -35,6 +35,8 @@ namespace MinecraftClient public void SetHandler(McClient handler) { this._handler = handler; } protected void SetMaster(ChatBot master) { this.master = master; } protected void LoadBot(ChatBot bot) { Handler.BotUnLoad(bot); Handler.BotLoad(bot); } + protected List GetLoadedChatBots() { return Handler.GetLoadedChatBots(); } + protected void UnLoadBot(ChatBot bot) { Handler.BotUnLoad(bot); } private McClient _handler = null; private ChatBot master = null; private List registeredPluginChannels = new List(); diff --git a/MinecraftClient/config/ChatBots/VkMessager.cs b/MinecraftClient/config/ChatBots/VkMessager.cs index 53a712e6..27dffd07 100644 --- a/MinecraftClient/config/ChatBots/VkMessager.cs +++ b/MinecraftClient/config/ChatBots/VkMessager.cs @@ -1,5 +1,12 @@ //MCCScript 1.0 //using System.Threading.Tasks; +//dll Newtonsoft.Json.dll +//using Newtonsoft.Json; +//using Newtonsoft.Json.Linq; + +//==== INFO START ==== +// Download Newtonsoft.Json.dll and install it into the program folder Link: https://www.newtonsoft.com/json +//==== INFO END ==== //==== CONFIG START ==== string vkToken = ""; @@ -125,6 +132,29 @@ internal class VkLongPoolClient CallVkMethod("messages.send", "peer_id=" + chatId + "&random_id=" + random_id + "&message=" + text + "&keyboard=" + keyboard); } + + public void SendMessageAndDocument(string chatId, string text, string file, string title, string keyboard = "", int random_id = 0) + { + if (random_id == 0) + { + random_id = lastrand; + lastrand++; + } + var c = new WebClient(); + // + var u = CallVkMethod("docs.getMessagesUploadServer", "peer_id=" + chatId + "&type=doc"); + var j = JsonConvert.DeserializeObject(u) as JObject; + // + var u2 = j["response"]["upload_url"].ToString(); + var r2 = Encoding.UTF8.GetString(c.UploadFile(u2, "POST", file)); + var j2 = JsonConvert.DeserializeObject(r2) as JObject; + // + var r3 = CallVkMethod("docs.save", "&file=" + j2["file"] + + "&title=" + title); + var j3 = JsonConvert.DeserializeObject(r3) as JObject; + var at = "doc"+ j3["response"]["doc"]["owner_id"].ToString() + "_" + j3["response"]["doc"]["id"].ToString(); + CallVkMethod("messages.send", "peer_id=" + chatId + "&random_id=" + random_id + "&message=" + text + "&keyboard=" + keyboard + "&attachment=" + at); + } public void SendSticker(string chatId, int sticker_id, int random_id = 0) {