示例#1
0
        private async Task CmdUpdateAsync(CommandContext context, string userInput = null, CancellationToken cancellationToken = default)
        {
            // determine ID to set, if null means failed (message will be sent automatically
            uint?nextID = await GetNextIdAsync(context, userInput, cancellationToken).ConfigureAwait(false);

            if (nextID == null)
            {
                return;
            }

            // start interactive session with AP to update
            await context.ReplyTextAsync(_nextGameOptions.AutoPostBotRemoveCommand, cancellationToken).ConfigureAwait(false);

            ChatMessage botResponse = await context.Client.AwaitNextGroupByUserAsync(_nextGameOptions.AutoPostBotID, context.Message.RecipientID, TimeSpan.FromSeconds(_nextGameOptions.AutoPostBotWaitSeconds), cancellationToken).ConfigureAwait(false);

            if (botResponse == null)
            {
                await context.ReplyTextAsync($"(n) AP didn't respond within {_nextGameOptions.AutoPostBotWaitSeconds} seconds.");
            }
            else
            {
                await context.ReplyTextAsync(BotInteractionUtilities.GetAutopostBotAddCommand(_nextGameOptions, nextID), cancellationToken).ConfigureAwait(false);
            }

            // update config and save in DB
            await SaveGroupConfigAsync(context.Client, context.Message.RecipientID, nextID.Value, cancellationToken).ConfigureAwait(false);
        }
示例#2
0
        private async Task CmdNextAsync(CommandContext context, string userInput = null, CancellationToken cancellationToken = default)
        {
            uint?nextID = await GetNextIdAsync(context, userInput, cancellationToken).ConfigureAwait(false);

            if (nextID == null)
            {
                return;
            }

            // request next
            await context.ReplyTextAsync(BotInteractionUtilities.GetSubmissionBotShowCommand(_botOptions, nextID.Value), cancellationToken).ConfigureAwait(false);

            // update config and save in DB
            await SaveGroupConfigAsync(context.Client, context.Message.RecipientID, nextID.Value, cancellationToken).ConfigureAwait(false);
        }
示例#3
0
        private async Task CmdNextAsync(CommandContext context, string queueName, CancellationToken cancellationToken = default)
        {
            // get queue and ensure not empty
            IdQueue queue = await GetOrCreateQueueAsync(context, queueName, cancellationToken).ConfigureAwait(false);

            if (queue == null)
            {
                return;         // if null, it means it's a forbidden name
            }
            if (!queue.QueuedIDs.Any())
            {
                await context.ReplyTextAsync($"Queue {queue.Name} is empty.", cancellationToken).ConfigureAwait(false);

                return;
            }

            uint gameID = queue.QueuedIDs.Dequeue();
            await context.ReplyTextAsync(BotInteractionUtilities.GetSubmissionBotShowCommand(_botOptions, gameID), cancellationToken).ConfigureAwait(false);

            await SaveQueueAsync(context, queue, cancellationToken).ConfigureAwait(false);
        }
示例#4
0
        private async Task CmdContinueAsync(CommandContext context, string userInput = null, CancellationToken cancellationToken = default)
        {
            // try user input first
            string rawNextID;

            if (!string.IsNullOrWhiteSpace(userInput))
            {
                rawNextID = userInput;
            }
            // if user did not provide ID, start interactive session with AP
            else
            {
                await context.ReplyTextAsync(_nextGameOptions.AutoPostBotPostCommand, cancellationToken).ConfigureAwait(false);

                ChatMessage botResponse = await context.Client.AwaitNextGroupByUserAsync(_nextGameOptions.AutoPostBotID, context.Message.RecipientID, TimeSpan.FromSeconds(_nextGameOptions.AutoPostBotWaitSeconds), cancellationToken).ConfigureAwait(false);

                if (botResponse == null)
                {
                    await context.ReplyTextAsync($"(n) AP didn't respond within {_nextGameOptions.AutoPostBotWaitSeconds} seconds.");

                    return;
                }
                rawNextID = botResponse.Text;
            }

            // validate ID
            if (!uint.TryParse(rawNextID, out uint nextID))
            {
                await context.ReplyTextAsync($"(n) {rawNextID} is not a correct game ID!", cancellationToken).ConfigureAwait(false);

                return;
            }

            // request next
            await context.ReplyTextAsync(BotInteractionUtilities.GetSubmissionBotShowCommand(_botOptions, nextID), cancellationToken).ConfigureAwait(false);

            // update config and save in DB
            await SaveGroupConfigAsync(context.Client, context.Message.RecipientID, nextID, cancellationToken).ConfigureAwait(false);
        }