コード例 #1
0
        /// <summary>
        /// Implementers should derive from this to handle a matched message.
        /// </summary>
        /// <param name="message">The message received.</param>
        /// <param name="handleCache">The match object returned from the regex match.</param>
        /// <returns>The handle task.</returns>
        protected override async Task HandleMatchedMessage(SocketMessage message, Match handleCache)
        {
            var messageChannel   = message.Channel as SocketGuildChannel;
            var guildConnection  = messageChannel.Guild;
            var messageReference = new MessageReference(message.Id, messageChannel.Id, guildConnection.Id);

            var checkoutResult = checkoutResultPool.Get();

            try
            {
                checkoutResult = await this.guildRepository.Checkout(guildConnection.Id, checkoutResult);

                switch (checkoutResult.Result)
                {
                case GuildCheckoutResult.ResultType.Success:
                    using (var borrowedGuild = checkoutResult.BorrowedGuild)
                    {
                        borrowedGuild.Commit = false;
                        var guildData = borrowedGuild.Instance;

                        await ListOptinsGuildHandler.ListOptinChannels(message, guildConnection, guildData);
                    }
                    break;

                case GuildCheckoutResult.ResultType.DoesNotExist:
                    await message.Channel.SendMessageAsync(
                        text : "This server has not been configured for Chill Bot yet.",
                        messageReference : messageReference)
                    .ConfigureAwait(false);

                    break;

                case GuildCheckoutResult.ResultType.Locked:
                    await message.Channel.SendMessageAsync(
                        text : "Please try again.",
                        messageReference : messageReference)
                    .ConfigureAwait(false);

                    break;

                default:
                    throw new NotImplementedException(checkoutResult.Result.ToString());
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Request dropped - exception thrown");
                await message.Channel.SendMessageAsync(
                    text : "Something went wrong trying to do this for you. File a bug report with Chill Bot.",
                    messageReference : messageReference)
                .ConfigureAwait(false);
            }
            finally
            {
                checkoutResult.ClearReferences();
                checkoutResultPool.Return(checkoutResult);
            }
        }
コード例 #2
0
        /// <summary>
        /// Given guild data, list all of the optin channels.
        /// </summary>
        /// <param name="message">The source message (for replying to). May not be null.</param>
        /// <param name="guildConnection">A connection to the guild. May not be null.</param>
        /// <param name="guildData">The guild data. May not be null.</param>
        /// <returns>When listing has completed.</returns>
        private static async Task ListOptinChannels(SocketMessage message, SocketGuild guildConnection, Guild guildData)
        {
            var messageReference = new MessageReference(message.Id, message.Channel.Id, guildConnection.Id);
            var listResult       = listResultPool.Get();

            try
            {
                listResult = OptinChannel.List(guildConnection, guildData, listResult);

                switch (listResult.Result)
                {
                case OptinChannel.ListResult.ResultType.Success:
                    var namesDescriptions = listResult.NamesDescriptions;
                    if (namesDescriptions.Count > 0)
                    {
                        await message.Channel.SendMessageAsync(
                            ListOptinsGuildHandler.GetListingMessage(namesDescriptions),
                            messageReference : messageReference)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync(
                            text : "This server deosn't have any opt-in channels yet. Try creating one with \"@Chill Bot new opt-in channel-name A description of your channel!\"",
                            messageReference : messageReference)
                        .ConfigureAwait(false);
                    }
                    break;

                case OptinChannel.ListResult.ResultType.NoOptinCategory:
                    await message.Channel.SendMessageAsync(
                        text : "This server is not set up for opt-in channels.",
                        messageReference : messageReference)
                    .ConfigureAwait(false);

                    break;

                default:
                    throw new NotImplementedException(listResult.Result.ToString());
                }
            }
            finally
            {
                listResult.ClearReferences();
                listResultPool.Return(listResult);
            }
        }