Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Bot bot = new Bot();
            string mensaje = string.Empty;
            Console.Write("Mensaje: ");
            mensaje = Console.ReadLine();

            bot.SendMessage(mensaje);

            Console.WriteLine(mensaje);
            Console.ReadKey();
        }
Exemplo n.º 2
0
        private static async void SendNotification()
        {
            var dateTime = DateTime.Now;

            if (Settings.ExcludeDays.Contains((int)dateTime.DayOfWeek))
            {
                return;
            }

            var nowTime = new Time(dateTime.Hour, dateTime.Minute);

            if (nowTime == Settings.BeforeGameNotificationTime)
            {
                var notifications = await _notificationService.GetAllBeforeGameNotifications();

                var stickers = await _notificationService.GetAllStickers();

                var text = notifications.RandomElement().Text;
                await _botClient.SendMessage(text, ParseMode.MarkdownV2);

                await _botClient.SendSticker(stickers.RandomElement().StickerId);

                LogToConsole($"Message: {text} has been sent", LogTypes.Info);
            }

            if (nowTime == Settings.AfterGameNotificationTime)
            {
                var notifications = await _notificationService.GetAllAfterGameNotifications();

                var playerStat = await _playerStatService.GetBestPlayerStat();

                if (playerStat.Count < 3)
                {
                    await _botClient.SendMessage("Сегодня нас было слишком мало", ParseMode.MarkdownV2);

                    return;
                }

                var notification = notifications.FirstOrDefault();

                if (notification == null || notification.Text.IsEmpty() || playerStat == null || !playerStat.Any())
                {
                    return;
                }

                var text = HandlebarsEngine.ProcessTemplate(notification.Text, new
                {
                    firstUserName  = playerStat.First().Player.NickName,
                    firstKdStat    = playerStat.First().KdRatio.ToString(CultureInfo.InvariantCulture).Replace(".", "\\."),
                    firstKad       = playerStat.First().Kad,
                    firstHeadShot  = Math.Round(playerStat.First().HeadShotsPercent, 0),
                    secondUserName = playerStat.Skip(1).Take(1).First().Player.NickName,
                    secondKdStat   = playerStat.Skip(1).Take(1).First().KdRatio.ToString(CultureInfo.InvariantCulture).Replace(".", "\\."),
                    secondKad      = playerStat.Skip(1).Take(1).First().Kad,
                    secondHeadShot = Math.Round(playerStat.Skip(1).Take(1).First().HeadShotsPercent, 0),
                    thirdUserName  = playerStat.Last().Player.NickName,
                    thirdKdStat    = playerStat.Last().KdRatio.ToString(CultureInfo.InvariantCulture).Replace(".", "\\."),
                    thirdKad       = playerStat.Last().Kad,
                    thirdHeadShot  = Math.Round(playerStat.Last().HeadShotsPercent, 0),
                });

                await _botClient.SendMessage(text, ParseMode.MarkdownV2);

                LogToConsole($"Message: {text} has been sent", LogTypes.Info);
            }
        }