コード例 #1
0
        public async Task Stats(params string[] names)
        {
            var players = new List <Player>();

            foreach (var name in names)
            {
                var player = await _playerService.GetAsync(name);

                if (player is null)
                {
                    var errorEmbed = _basicEmbedsService.CreateErrorEmbed($"Could not find player `{name}`." +
                                                                          " Are you sure they exist and are a Barca player?\n\n" +
                                                                          "If you think there is a player missing from the database please report it to the creator of BarcaBot: `Trace#8994` or open a GitHub issue.");
                    await Context.Channel.SendMessageAsync("", false, errorEmbed.Build());

                    return;
                }

                players.Add(player);
            }

            var chart = await _chartService.GetStatsBarChart(players);

            var chartStream = new MemoryStream(chart);
            await Context.Channel.SendFileAsync(chartStream, "chart.png");
        }
コード例 #2
0
ファイル: LaLigaTableModule.cs プロジェクト: TraceLD/BarcaBot
        public LaLigaTableModule(ILogger <LaLigaTableModule> logger, ILaLigaTableService tableService, ILaLigaTableEmbedService embedService, IBasicEmbedsService basicEmbedsService)
        {
            _logger             = logger;
            _tableService       = tableService;
            _embedService       = embedService;
            _basicEmbedsService = basicEmbedsService;

            _errorEmbed = _basicEmbedsService.CreateErrorEmbed("Error while obtaining the table.").Build();
        }
コード例 #3
0
        public async Task Scorers()
        {
            var scorers = await _scorersService.GetAsync();

            if (!scorers.Any())
            {
                var errorEmbed = _basicEmbedsService.CreateErrorEmbed("No scorers found.");
                await Context.Channel.SendMessageAsync("", false, errorEmbed.Build());

                return;
            }

            var embed = _embedService.CreateScorersEmbed(scorers);

            await Context.Channel.SendMessageAsync("", false, embed.Build());
        }
コード例 #4
0
        public async Task Schedule()
        {
            var schedule = await _matchService.GetAsync();

            if (!schedule.Any())
            {
                var errorEmbed = _basicEmbedsService.CreateErrorEmbed("No upcoming matches found.");
                await Context.Channel.SendMessageAsync("", false, errorEmbed.Build());

                return;
            }

            var embed = _embedService.CreateScheduleEmbed(schedule);

            await Context.Channel.SendMessageAsync("", false, embed.Build());
        }
コード例 #5
0
        private Task BotMessageReceivedAsync(SocketMessage message)
        {
            if (message.Author.IsBot)
            {
                return(Task.CompletedTask);
            }

            if (!(message is SocketUserMessage userMessage))
            {
                return(Task.CompletedTask);
            }

            var argPos = 0;

            if (!userMessage.HasCharPrefix(_settings.Prefix, ref argPos))
            {
                return(Task.CompletedTask);
            }

            _botService.ExecuteHandlerAsynchronously(
                handler: (client) =>
            {
                var context = new SocketCommandContext(client, userMessage);
                return(_commandService.ExecuteAsync(context, argPos, _provider));
            },
                callback: async(result) =>
            {
                if (result.IsSuccess)
                {
                    return;
                }

                if (result.Error == CommandError.UnknownCommand)
                {
                    return;
                }

                if (result.Error.HasValue)
                {
                    var errEmbed =
                        _basicEmbedsService.CreateErrorEmbed($"Unhandled error occurred.\n{result.Error.Value}, {result.ErrorReason}");
                    await message.Channel.SendMessageAsync("", false, errEmbed.Build());
                }
            });

            return(Task.CompletedTask);
        }
コード例 #6
0
        public async Task Player([Remainder] string name)
        {
            var player = await _playerService.GetAsync(name);

            if (player is null)
            {
                var errorEmbed = _basicEmbedsService.CreateErrorEmbed($"Could not find player `{name}`." +
                                                                      " Are you sure they exist and are a Barca player?\n\n" +
                                                                      "If you think there is a player missing from the database please report it to the creator of BarcaBot: `Trace#8994` or open a GitHub issue.");
                await Context.Channel.SendMessageAsync($"", false, errorEmbed.Build());

                return;
            }

            var embed = _embedService.CreatePlayerEmbed(player);

            await Context.Channel.SendMessageAsync("", false, embed.Build());
        }