예제 #1
0
 public UpdateService(BotDbContext dbContext, IBotService botService, IOpenDotaService dotaService, ILogger <UpdateService> logger)
 {
     _dbContext   = dbContext;
     _botService  = botService;
     _logger      = logger;
     _dotaService = dotaService;
 }
예제 #2
0
 public CommandProcessorService(IBotService botService, IOpenDotaService dotaService)
 {
     ServiceContext    = new ServicesContext((BotService)botService, (OpenDotaService)dotaService);
     CommandProcessors = new List <ICommandProcessor>();
     CommandProcessors.Add(new TrackingCommandProcessor());
     CommandProcessors.Add(new GroupWelcomeCommandProcessor());
     CommandProcessors.Add(new UserCommandProcessor());
     CommandProcessors.Add(new DotaCommandProcessor());
     CommandProcessors.Add(new AdminCommandProcessor());
 }
예제 #3
0
        private static async Task MatchDetailsCommand(IBotService botService, Message message, IOpenDotaService dotaService)
        {
            var client       = botService.Client;
            var messageParts = message.Text.Split(' ');

            if (messageParts.Length >= 2)
            {
                var  matchIdString = messageParts[2];
                uint matchId;
                var  parsed = uint.TryParse(matchIdString, out matchId);
                if (parsed)
                {
                    var match = await dotaService.Client.GetMatchDetails(matchId);

                    if (match != null)
                    {
                        var report         = dotaService.Client.DrawMatchReport(match).ToArray();
                        var radiantReports = new List <InputMediaPhoto>();
                        var direReports    = new List <InputMediaPhoto>();
                        for (var i = 0; i < report.Length; i++)
                        {
                            var    picture = report[i];
                            string pictureName;
                            if (i == 0)
                            {
                                using (var pictureStream = new MemoryStream(picture))
                                {
                                    await client.SendPhotoAsync
                                    (
                                        message.Chat.Id,
                                        new InputOnlineFile(pictureStream, "MatchReport.png"),
                                        disableNotification : true,
                                        caption : "MatchReport",
                                        replyToMessageId : message.MessageId
                                    );
                                }
                            }
                            else if (i < 6)
                            {
                                pictureName = $"{((i - 1) / 5 == 0 ? "Radiant" : "Dire")} {(i - 1) % 5 + 1}";
                                var media         = new InputMediaPhoto();
                                var pictureStream = new MemoryStream(picture);
                                media.Media   = new InputMedia(pictureStream, $"{pictureName}.png");
                                media.Caption = pictureName;
                                radiantReports.Add(media);
                            }
                            else
                            {
                                pictureName = $"{((i - 1) / 5 == 0 ? "Radiant" : "Dire")} {(i - 1) % 5 + 1}";
                                var media         = new InputMediaPhoto();
                                var pictureStream = new MemoryStream(picture);
                                media.Media   = new InputMedia(pictureStream, $"{pictureName}.png");
                                media.Caption = pictureName;
                                direReports.Add(media);
                            }
                        }
                        await client.SendMediaGroupAsync
                        (
                            message.Chat.Id,
                            radiantReports,
                            disableNotification : true,
                            replyToMessageId : message.MessageId
                        );

                        await client.SendMediaGroupAsync
                        (
                            message.Chat.Id,
                            direReports,
                            disableNotification : true,
                            replyToMessageId : message.MessageId
                        );

                        foreach (var playerReport in radiantReports)
                        {
                            playerReport.Media.Content.Dispose();
                        }
                        foreach (var playerReport in direReports)
                        {
                            playerReport.Media.Content.Dispose();
                        }
                    }
                    else
                    {
                        await client.SendTextMessageAsync
                        (
                            message.Chat.Id,
                            "owpen dowta is down >w<!",
                            replyToMessageId : message.MessageId
                        );
                    }
                }
                else
                {
                    await client.SendTextMessageAsync
                    (
                        message.Chat.Id,
                        "bwad match id >w<!",
                        replyToMessageId : message.MessageId
                    );
                }
            }
            else
            {
                await client.SendTextMessageAsync
                (
                    message.Chat.Id,
                    "pweese giw a walid command UwU!",
                    replyToMessageId : message.MessageId
                );
            }
        }