Esempio n. 1
0
        public async Task ShowOrCreateDedicatedRoleplayChannel
        (
            [RequireEntityOwnerOrPermission(typeof(StartStopRoleplay), PermissionTarget.Other)]
            Roleplay roleplay
        )
        {
            var getDedicatedChannelResult = await _dedicatedChannels.GetDedicatedChannelAsync
                                            (
                this.Context.Guild,
                roleplay
                                            );

            if (getDedicatedChannelResult.IsSuccess)
            {
                var existingDedicatedChannel = getDedicatedChannelResult.Entity;
                var message = $"\"{roleplay.Name}\" has a dedicated channel at " +
                              $"{MentionUtils.MentionChannel(existingDedicatedChannel.Id)}";

                await _feedback.SendConfirmationAsync(this.Context, message);

                return;
            }

            await _feedback.SendConfirmationAsync(this.Context, "Setting up dedicated channel...");

            // The roleplay either doesn't have a channel, or the one it has has been deleted or is otherwise invalid.
            var result = await _dedicatedChannels.CreateDedicatedChannelAsync
                         (
                this.Context.Guild,
                roleplay
                         );

            if (!result.IsSuccess)
            {
                await _feedback.SendErrorAsync(this.Context, result.ErrorReason);

                return;
            }

            var dedicatedChannel = result.Entity;
            await _feedback.SendConfirmationAsync
            (
                this.Context,
                $"All done! Your roleplay now has a dedicated channel at {MentionUtils.MentionChannel(dedicatedChannel.Id)}."
            );

            if (roleplay.IsActive && roleplay.ActiveChannelID != (long)dedicatedChannel.Id)
            {
                await StopRoleplayAsync(roleplay);
                await StartRoleplayAsync(roleplay);
            }
        }
Esempio n. 2
0
    /// <summary>
    /// Creates a new roleplay with the given owner and parameters.
    /// </summary>
    /// <param name="guildID">The ID of the guild the user is on.</param>
    /// <param name="userID">The ID of the user.</param>
    /// <param name="name">The name of the roleplay.</param>
    /// <param name="summary">A short summary.</param>
    /// <param name="isNSFW">Whether the roleplay is NSFW.</param>
    /// <param name="isPublic">Whether the roleplay is public.</param>
    /// <returns>A creation result which may or may not have succeeded.</returns>
    public async Task <Result <Roleplay> > CreateRoleplayAsync
    (
        Snowflake guildID,
        Snowflake userID,
        string name,
        string summary,
        bool isNSFW,
        bool isPublic
    )
    {
        var getUser = await _users.GetOrRegisterUserAsync(userID);

        if (!getUser.IsSuccess)
        {
            return(Result <Roleplay> .FromError(getUser));
        }

        var user = getUser.Entity;

        var getServer = await _servers.GetOrRegisterServerAsync(guildID);

        if (!getServer.IsSuccess)
        {
            return(Result <Roleplay> .FromError(getServer));
        }

        var server = getServer.Entity;

        var createRoleplay = await _roleplays.CreateRoleplayAsync(user, server, name, summary, isNSFW, isPublic);

        if (!createRoleplay.IsSuccess)
        {
            return(createRoleplay);
        }

        var roleplay = createRoleplay.Entity;

        var createChannel = await _dedicatedChannels.CreateDedicatedChannelAsync(roleplay);

        return(!createChannel.IsSuccess
            ? Result <Roleplay> .FromError(createChannel)
            : roleplay);
    }
    public async Task <Result <FeedbackMessage> > ShowOrCreateDedicatedRoleplayChannel
    (
        [RequireEntityOwner]
        [AutocompleteProvider("roleplay::owned")]
        Roleplay roleplay
    )
    {
        var getDedicatedChannelResult = DedicatedChannelService.GetDedicatedChannel(roleplay);

        if (getDedicatedChannelResult.IsSuccess)
        {
            var existingDedicatedChannel = getDedicatedChannelResult.Entity;
            var message = $"\"{roleplay.Name}\" has a dedicated channel at " +
                          $"<#{existingDedicatedChannel}>";

            return(new FeedbackMessage(message, _feedback.Theme.Secondary));
        }

        var workingMessage = new Embed
        {
            Colour      = _feedback.Theme.Secondary,
            Description = "Setting up dedicated channel..."
        };

        var send = await _feedback.SendContextualEmbedAsync(workingMessage);

        if (!send.IsSuccess)
        {
            return(Result <FeedbackMessage> .FromError(send));
        }

        // The roleplay either doesn't have a channel, or the one it has has been deleted or is otherwise invalid.
        var result = await _dedicatedChannels.CreateDedicatedChannelAsync(roleplay);

        if (!result.IsSuccess)
        {
            return(Result <FeedbackMessage> .FromError(result));
        }

        var dedicatedChannel = result.Entity;

        if (!roleplay.IsActive || roleplay.ActiveChannelID == dedicatedChannel.ID)
        {
            return(new FeedbackMessage
                   (
                       $"All done! Your roleplay now has a dedicated channel at <#{dedicatedChannel}>.",
                       _feedback.Theme.Secondary
                   ));
        }

        var stopResult = await StopRoleplayAsync(roleplay);

        if (!stopResult.IsSuccess)
        {
            return(stopResult);
        }

        var startResult = await StartRoleplayAsync(roleplay);

        if (!startResult.IsSuccess)
        {
            return(startResult);
        }

        return(new FeedbackMessage
               (
                   $"All done! Your roleplay now has a dedicated channel at <#{dedicatedChannel}>.",
                   _feedback.Theme.Secondary
               ));
    }
        public async Task <RuntimeResult> ShowOrCreateDedicatedRoleplayChannel
        (
            [RequireEntityOwnerOrPermission(typeof(StartStopRoleplay), PermissionTarget.Other)]
            Roleplay roleplay
        )
        {
            var getDedicatedChannelResult = await _dedicatedChannels.GetDedicatedChannelAsync
                                            (
                this.Context.Guild,
                roleplay
                                            );

            if (getDedicatedChannelResult.IsSuccess)
            {
                var existingDedicatedChannel = getDedicatedChannelResult.Entity;
                var message = $"\"{roleplay.Name}\" has a dedicated channel at " +
                              $"{MentionUtils.MentionChannel(existingDedicatedChannel.Id)}";

                return(RuntimeCommandResult.FromSuccess(message));
            }

            await _feedback.SendConfirmationAsync(this.Context, "Setting up dedicated channel...");

            // The roleplay either doesn't have a channel, or the one it has has been deleted or is otherwise invalid.
            var result = await _dedicatedChannels.CreateDedicatedChannelAsync
                         (
                this.Context.Guild,
                roleplay
                         );

            if (!result.IsSuccess)
            {
                return(result.ToRuntimeResult());
            }

            var dedicatedChannel = result.Entity;

            if (!roleplay.IsActive || roleplay.ActiveChannelID == (long)dedicatedChannel.Id)
            {
                return(RuntimeCommandResult.FromSuccess
                       (
                           $"All done! Your roleplay now has a dedicated channel at " +
                           $"{MentionUtils.MentionChannel(dedicatedChannel.Id)}."
                       ));
            }

            var stopResult = await StopRoleplayAsync(roleplay);

            if (!stopResult.IsSuccess)
            {
                return(stopResult);
            }

            var startResult = await StartRoleplayAsync(roleplay);

            if (!startResult.IsSuccess)
            {
                return(startResult);
            }

            return(RuntimeCommandResult.FromSuccess
                   (
                       $"All done! Your roleplay now has a dedicated channel at " +
                       $"{MentionUtils.MentionChannel(dedicatedChannel.Id)}."
                   ));
        }