Пример #1
0
        public async Task ListDataSourcesCommandAsync()
        {
            var messageBuilder = new StringBuilder();
            int count          = 0;

            foreach (var dataSource in AlternateBackendProvider.GetBackendNames())
            {
                count++;
                messageBuilder.AppendLine(string.Join(" / ", dataSource));
            }

            messageBuilder.AppendLine();
            messageBuilder.Append(Utilities.Pluralize("alternate data source", count)).AppendLine(" loaded");

            await ReplyAsync(messageBuilder.ToString()).ConfigureAwait(false);
        }
Пример #2
0
        public async Task ExecuteWrappedCommandAsync(
            [Summary("The identifier of the data source from which scores should be provided to the command.")] string dataSourceId,
            [Remainder, Summary("The command (without any prefix) that should be executed.")] string command)
        {
            if (!AlternateBackendProvider.TryGetAlternateDataBackend(dataSourceId, out IScoreRetrievalService newBackend))
            {
                throw new ArgumentException("The given alternate data source ID is invalid. Valid data sources can be listed with the `listdatasources` command.");
            }

            IResult result = await CommandService.ExecuteAsync(Context, command, Services.Overlay(newBackend)).ConfigureAwait(false);

            if (!result.IsSuccess)
            {
                throw new Exception("Error executing datasource-wrapped command: " + (result.Error?.ToStringCamelCaseToSpace() ?? "") + ": " + (result.ErrorReason ?? "[Unknown Details]"));
            }
        }