public override Func <CommandEventArgs, Task> DoFunc() => async(e) => { if (cards == null) { await e.Send("Shuffling cards..."); cards = new Cards(); } try { int num = 1; var isParsed = int.TryParse(e.GetArg("count"), out num); if (!isParsed || num < 2) { await e.Channel.SendFile(cards.DrawACard().Path); return; } if (num > 5) { num = 5; } List <Image> images = new List <Image>(); List <Cards.Card> cardObjects = new List <Cards.Card>(); for (int i = 0; i < num; i++) { if (cards.CardPool.Count == 0 && i != 0) { await e.Send("No more cards in a deck."); break; } var currentCard = cards.DrawACard(); cardObjects.Add(currentCard); images.Add(Image.FromFile(currentCard.Path)); } Bitmap bitmap = ImageHandler.MergeImages(images); await e.Channel.SendFile(images.Count + " cards.jpg", ImageHandler.ImageToStream(bitmap, ImageFormat.Jpeg)); if (cardObjects.Count == 5) { await e.Send(Cards.GetHandValue(cardObjects)); } } catch (Exception ex) { Console.WriteLine("Error drawing (a) card(s) " + ex.ToString()); } };
public override Func <CommandEventArgs, Task> DoFunc() { Random r = new Random(); return(async e => { if (e.Args[0] == "") { int num1 = r.Next(0, 10); int num2 = r.Next(0, 10); Console.WriteLine(num1 + "|" + num2); Image[] images; if (num1 == 0 && num2 == 0 && r.Next(0, 2) == 1) { images = new Image[3] { GetDice(1), GetDice(0), GetDice(0) }; } else { images = new Image[2] { GetDice(num1), GetDice(num2) }; } Bitmap bitmap = ImageHandler.MergeImages(images); await e.Channel.SendFile("dice.png", ImageHandler.ImageToStream(bitmap, ImageFormat.Png)); return; } else { try { int num = int.Parse(e.Args[0]); if (num < 1) { num = 1; } if (num > 30) { await e.Send("You can roll up to 30 dies at a time."); num = 30; } List <Image> dices = new List <Image>(num); List <int> values = new List <int>(num); for (int i = 0; i < num; i++) { int randomNumber = r.Next(1, 7); int toInsert = dices.Count; if (randomNumber == 6 || dices.Count == 0) { toInsert = 0; } else if (randomNumber != 1) { for (int j = 0; j < dices.Count; j++) { if (values[j] < randomNumber) { toInsert = j; break; } } } dices.Insert(toInsert, GetDice(randomNumber)); values.Insert(toInsert, randomNumber); } Bitmap bitmap = ImageHandler.MergeImages(dices.ToArray()); await e.Send(values.Count + " Dies rolled. Total: **" + values.Sum() + "** Average: **" + (values.Sum() / (1.0f * values.Count)).ToString("N2") + "**"); await e.Channel.SendFile("dices.png", ImageHandler.ImageToStream(bitmap, ImageFormat.Png)); } catch (Exception) { await e.Send("Please enter a number of dices to roll."); return; } } }); }