public void SomeResult(ParseMessage pm, DND cube) { //extremly bad practice should think about it if (cube is D4) { cube.SetCubeResult(); } else if (cube is D8) { cube.SetCubeResult(); } else if (cube is D10) { cube.SetCubeResult(); } else if (cube is D12) { cube.SetCubeResult(); } else if (cube is D20) { cube.SetCubeResult(); } else if (cube is D100) { cube.SetCubeResult(); } //TODO think about the message huh? if (pm.HasArgument && !pm.HasMessage) { StringBuilder sb = new StringBuilder(); sb.Append("Кидаю d" + $"{cube.CubeType}" + " " + $"{pm.Argument} раз"); TextMessage = sb.ToString(); } if (pm.HasMessage && !pm.HasArgument) { StringBuilder sb = new StringBuilder(); sb.Append("Кидаю d" + $"{cube.CubeType}" + " " + $"с надеждой, что {pm.MessageText}"); TextMessage = sb.ToString(); } if (!pm.HasMessage && !pm.HasArgument) { StringBuilder sb = new StringBuilder(); sb.Append("Кидаю d" + $"{cube.CubeType}"); TextMessage = sb.ToString(); } if (pm.HasMessage && pm.HasArgument) { StringBuilder sb = new StringBuilder(); sb.Append("Кидаю d" + $"{cube.CubeType}" + " " + $"{pm.Argument} раз " + $"c надеждой что {pm.MessageText}"); TextMessage = sb.ToString(); } }
public void FinalResult(ParseMessage pm, DND cube) { StringBuilder sb = new StringBuilder(); if (cube is D20) { d20Result(pm, cube); } else { dResult(pm, cube); } pm.CommandExecuted = true; }
public void GetPasteFromOtecNotepad(ParseMessage pm) { Random rand = new Random(Guid.NewGuid().GetHashCode()); // impressive random :) string pathToFile = @"D:\projects\Valentin_Core\Valentin_Core\resources\text\otecPaste.txt"; // you can easily read from your file using (StreamReader reader = new StreamReader(pathToFile)) { var lines = GetLinesFromText(reader.BaseStream); var certainLine = rand.Next(0, (int)lines); // that's how you shouldn't var paste = File.ReadAllLines(pathToFile, Encoding.UTF8).Skip(certainLine - 1).Take(1).First(); MessageText = paste; pm.CommandExecuted = true; } }
private void dResult(ParseMessage pm, DND cube) { StringBuilder sb = new StringBuilder(); if (pm.HasArgument && pm.HasMessage) { var listValues = DndCaluclation.GetValues(cube, pm.Argument); sb.Append($"{pm.MessageText}" + " с такими результатами:\n"); foreach (var value in listValues) { sb.Append(value + " "); } TextMessage = sb.ToString(); } else if (!pm.HasArgument && pm.HasMessage || !pm.HasMessage) { sb.Append($"Куб показывает {cube.CubeResult}"); TextMessage = sb.ToString();; } }
private Bitmap CreateFrescoQuotes(ParseMessage pm) { string imagepath = @"D:\projects\Valentin_Core\Valentin_Core\resources\img\fresco.jpg"; if (pm.HasMessage) { StringBuilder part = new StringBuilder(); List <string> text = new List <string>(); foreach (var token in pm.MessageTextList) { if (pm.MessageTextList.LastOrDefault().Equals(token)) { part.Append(token); text.Add(part.ToString()); continue; } if (part.Length < 35) { part.Append(token + " "); continue; } if (part.Length >= 35) { text.Add(part.ToString()); part.Clear(); if (token != null) { part.Append(token + " "); } } } using (Stream BitmapStream = File.Open(imagepath, FileMode.Open)) { PointF location = new PointF(y: 30f, x: 20f); Image img = Image.FromStream(BitmapStream); var mBitmap = new Bitmap(img); //Bitmap bitmap = (Bitmap) Image.FromFile(imagepath); using (Graphics graphics = Graphics.FromImage(mBitmap)) { using (Font arialFont = new Font("Arial", 12)) { foreach (var token in text) { graphics.DrawString(token, arialFont, Brushes.Black, location); location.Y += 20f; } } } mBitmap.Save("Quotes.bpm", ImageFormat.Bmp); return(mBitmap); } } else { return(CreateFrescoQuotes()); //rewrite this } }
public Quotes(ParseMessage pm) { this.ImageFresco = CreateFrescoQuotes(pm); this.IOF = CreateIOF(); }
private void d20Result(ParseMessage pm, DND cube) { StringBuilder sb = new StringBuilder(); if (pm.HasMessage && pm.HasArgument) { var listValues = DndCaluclation.GetValues(cube, pm.Argument); sb.Append($"{pm.MessageText}" + " с такими результатами:\n"); foreach (var value in listValues) { sb.Append(value + " "); } TextMessage = sb.ToString(); } else if (!pm.HasMessage && pm.HasArgument) { var listValues = DndCaluclation.GetValues(cube, pm.Argument); sb.Append(" с такими результатами:\n"); foreach (var value in listValues) { sb.Append(value + " "); } TextMessage = sb.ToString(); } else if (pm.HasMessage && !pm.HasArgument) { switch (cube.CubeResult) { case int n when(n == 20): sb.Append($"Критический разрыв ебала на {cube.CubeResult}" + "," + $" вы точно: {pm.MessageText} "); TextMessage = sb.ToString(); break; case int n when(n == 1): sb.Append($"Вы обосрались конкретно тупа на {cube.CubeResult}" + "," + " пошёл нахуй!'"); TextMessage = sb.ToString(); break; case int n when(n < 7): sb.Append($"Вы не смогли {pm.MessageText}," + $" куб показывает {cube.CubeResult}"); TextMessage = sb.ToString(); break; case int n when(n >= 7 && n < 11): sb.Append($"Не могу точно сказать смогли ли вы {pm.MessageText}," + $" куб показывает {cube.CubeResult}, кинь ещё раз"); TextMessage = sb.ToString(); break; case int n when(n >= 11 && n <= 19): sb.Append($"Вы смогли {pm.MessageText}," + $" куб показывает: {cube.CubeResult}"); TextMessage = sb.ToString(); break; } } else if (!pm.HasMessage && !pm.HasArgument) { sb.Append($"Куб показывает {cube.CubeResult}"); TextMessage = sb.ToString(); } }
static async void Bot_OnMessage(object sender, MessageEventArgs e) { try { Message message = new Message(); ParseMessage pm = new ParseMessage(); PasteDotaThread pdt = new PasteDotaThread(); pm.ParseUserMessage(message.ReplyToMessage.Text); switch (pm.ExistBotCommands.Find(x => x.Equals(pm.BotCommand))) { case "/paste": pdt.GetPasteFromNotepad(pm); await botClient.SendTextMessageAsync(chatId : e.Message.Chat, text : pdt.MessageText, replyToMessageId : e.Message.MessageId); break; case "/d4": case "/d8": case "/d10": case "/d12": case "/d20": case "/d100": var cube = DndCaluclation.GetCube(pm.BotCommand); DNDResults dndr = new DNDResults(); dndr.SomeResult(pm, cube); await botClient.SendTextMessageAsync(chatId : e.Message.Chat, text : dndr.TextMessage, replyToMessageId : e.Message.MessageId, parseMode : ParseMode.Markdown); dndr.FinalResult(pm, cube); await botClient.SendTextMessageAsync(chatId : e.Message.Chat, text : dndr.TextMessage, replyToMessageId : e.Message.MessageId, parseMode : ParseMode.Markdown); break; case "/otec": pdt.GetPasteFromOtecNotepad(pm); await botClient.SendTextMessageAsync(chatId : e.Message.Chat, text : pdt.MessageText, replyToMessageId : e.Message.MessageId); break; case "/help": await botClient.SendTextMessageAsync(chatId : e.Message.Chat, text : "Напиши вот этому человеку @shadowmorex", replyToMessageId : e.Message.MessageId); break; case "/fresco": Quotes quotes = new Quotes(pm); await using (var file = File.OpenRead(quotes.PathToFile)) { var iof = new InputOnlineFile(file, "quotes.bpm"); await botClient.SendPhotoAsync(e.Message.Chat, iof, "Все факты достоверны и тщательно проверены администрацией", replyToMessageId : e.Message.MessageId); } break; case "/test": await using (var file = File.OpenRead(@"D:\projects\Valentin_Core\Valentin_Core\resources\img\fresco.jpg")) { var iofa = new InputOnlineFile(file, "shit.png"); await botClient.SendPhotoAsync(e.Message.Chat, iofa, "иди нахуй", replyToMessageId : e.Message.MessageId); } break; } } catch (Exception er) { await botClient.SendPhotoAsync(chatId : e.Message.Chat, photo : "http://reactionimage.org/img/gallery/3926393515.jpg", replyToMessageId : e.Message.MessageId, caption : "Какая-то хуйня, больше так не делай.\n" + "Если думаешь, что проблема в боте\n" + "то вызови автора командой */help*", parseMode : ParseMode.Markdown); } }