Add UnLoadBot to ChatBot API (#1164)

Add UnloadBot
Add BotList
Update VkMessager
Remove debug info
This commit is contained in:
Рома Данилов 2020-08-01 17:24:17 +05:00 committed by GitHub
parent 55f8988bbc
commit 712875251e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View file

@ -35,6 +35,8 @@ namespace MinecraftClient
public void SetHandler(McClient handler) { this._handler = handler; } public void SetHandler(McClient handler) { this._handler = handler; }
protected void SetMaster(ChatBot master) { this.master = master; } protected void SetMaster(ChatBot master) { this.master = master; }
protected void LoadBot(ChatBot bot) { Handler.BotUnLoad(bot); Handler.BotLoad(bot); } protected void LoadBot(ChatBot bot) { Handler.BotUnLoad(bot); Handler.BotLoad(bot); }
protected List<ChatBot> GetLoadedChatBots() { return Handler.GetLoadedChatBots(); }
protected void UnLoadBot(ChatBot bot) { Handler.BotUnLoad(bot); }
private McClient _handler = null; private McClient _handler = null;
private ChatBot master = null; private ChatBot master = null;
private List<string> registeredPluginChannels = new List<String>(); private List<string> registeredPluginChannels = new List<String>();

View file

@ -1,5 +1,12 @@
//MCCScript 1.0 //MCCScript 1.0
//using System.Threading.Tasks; //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 ==== //==== CONFIG START ====
string vkToken = ""; string vkToken = "";
@ -125,6 +132,29 @@ internal class VkLongPoolClient
CallVkMethod("messages.send", "peer_id=" + chatId + "&random_id=" + random_id + "&message=" + text + "&keyboard=" + keyboard); 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) public void SendSticker(string chatId, int sticker_id, int random_id = 0)
{ {