static void SimpleTextAnalyse(string src, Chat CurChat) { if (CurChat.AddNew == "") { if (!StringChanger.HasKirill(src)) { src = StringChanger.LatinToKirill(src); Say(Answering("mistake") + "\n" + src, CurChat); } else { src = StringChanger.ToLower(src); src = StringChanger.RemoveSymb(src, "part"); if (src[src.Length - 1] != '.' && src[src.Length - 1] != '?' && src[src.Length - 1] != '!') { src += '.'; } if (src.Length > 2 && src[0] == '?') { Say(Answering("чтосказать"), CurChat); CurChat.AddNew = src.Substring(1); } else if (StringChanger.HasKirill(src)) { TextToResp(src, CurChat); } } } else // Addnew !="" { if (!DB.CancelSignal(src)) { src = StringChanger.RemoveSymb(src, "none"); DB.UpdateOrSaveReq(src, CurChat.AddNew); Say(Answering("запомню"), CurChat); Console.WriteLine(CurChat.ID + " added " + CurChat.AddNew + " -> " + src); } else if (CurChat.AddNew != "") { DB.DeleteReq(CurChat.AddNew); Say(Answering("cancel"), CurChat); } CurChat.AddNew = ""; } DB.SaveChat(CurChat, false); }
static void FindRhyme(string src, Chat CurChat) { src = StringChanger.ToLower(src); if (src.IndexOf(' ') > 0) { src = src.Substring(src.LastIndexOf(' ')); } if (src.Length < 0) { return; } CurChat.index = 0; CurChat.Arr = null; string goog = "https://rifmus.net/rifma/" + src; WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; int x = -1; string s = ""; try { s = wc.DownloadString(goog); x = s.IndexOf("multicolumn"); } catch {} if (x < 0) { Say(Answering("none"), CurChat); return; } s = s.Substring(x); x = s.IndexOf("</div>"); s = s.Substring(0, x); CurChat.Arr = StringChanger.HTMLtoText(s); SayRhymes(CurChat); }
private static void GetMessage(object sender, Telegram.Bot.Args.MessageEventArgs e) { var msg = e.Message; if (msg == null) { return; } msg.Date = msg.Date.ToLocalTime(); if (TurnOn == DateTime.MinValue || DateTime.Compare(msg.Date, TurnOn) < 0) { return; ///not first } Chat CurChat = DB.IDtoChat(msg.Chat.Id); if (CurChat.LastMsgId == msg.MessageId) { return; } if (msg.Type == Telegram.Bot.Types.Enums.MessageType.Voice && CurChat.IsAdmin()) { SpecCommands("block", CurChat); } if (msg.Type == Telegram.Bot.Types.Enums.MessageType.Text) { if (msg.Text[0] == '/') { CommandAnalyse(msg.Text, CurChat, msg.Date); } else { bool FromBot = msg.ReplyToMessage != null && msg.ReplyToMessage.From.Id == BOT; if (!CurChat.IsPrivate() && !StringChanger.ToLower(StringChanger.RemoveSymb(msg.Text, "none")).Contains("сапфир") && !FromBot) { return; } if (CurChat.mode == 0) { SimpleTextAnalyse(msg.Text, CurChat); } else if (!TextToResp(msg.Text, CurChat)) { if (!FromBot && !CurChat.IsPrivate()) { return; } if (CurChat.mode == 1) { FindPhoto(msg.Text, CurChat); } else if (CurChat.mode == 2) { msg.Text = StringChanger.RemoveSymb(msg.Text, "none"); msg.Text = StringChanger.ToLower(msg.Text); FindSong(msg.Text, CurChat); } else if (CurChat.mode == 3) { msg.Text = StringChanger.RemoveSpaces(msg.Text); FindRhyme(msg.Text, CurChat); } } } } CurChat.LastMsgId = msg.MessageId; DB.SaveChat(CurChat, false); }
static void CommandAnalyse(string src, Chat CurChat, DateTime DT) { if (src.Length < 1 || src[0] != '/') { return; } src = StringChanger.ToLower(src); int x = src.IndexOf("@"); if (x > 0 && src.IndexOf(name) < 0) { return; } else if (x > 0) { src = src.Substring(0, x); } if (src == "/start") { Say(Answering("приветствие"), CurChat); } else if (src == "/reset") { SpecCommands("reset", CurChat); } else if (src == "/show") { SpecCommands("show", CurChat); } else if (src == "/exit") { SpecCommands("exit", CurChat); } else if (src == "/block") { SpecCommands("block", CurChat); } else if (src == "/full") { SpecCommands("full", CurChat); } else if (src == "/help") { Say(DB.Help(), CurChat); } else if (src == "/talk") { CurChat.ChangeMode(0); } else if (src == "/photo") { CurChat.ChangeMode(1); } else if (src == "/song") { CurChat.ChangeMode(2); } else if (src == "/poet") { CurChat.ChangeMode(3); } else if (src == "/ping") { Say(Pong(DT), CurChat); } else if (src == "/next" && CurChat.mode == 1) { SendPhoto(CurChat); } else if (src == "/next" && CurChat.mode == 3) { SayRhymes(CurChat); } else if (src == "/stat") { Say(Answering(CurChat.mode + "mode"), CurChat); } DB.SaveChat(CurChat, false); }