Example #1
0
        public async Task Unpermit(IUser user, ITextChannel channel)
        {
            if (!Permissions.IsAdministratorOrBotOwner(Context))
            {
                await Context.ApplyResultReaction(CommandResult.FailedUserPermission).ConfigureAwait(false);

                return;
            }

            if (!(await Permissions.CanBotManageChannel(channel).ConfigureAwait(false)))
            {
                await Context.ApplyResultReaction(CommandResult.FailedBotPermission).ConfigureAwait(false);

                return;
            }

            var links = _links.Where(x => x.Channel == channel && GetUserIdFromLink(x) == user.Id);

            if (links.Count() > 0)
            {
                foreach (var link in links)
                {
                    await link.Channel.SendMessageAsync($"Access has been revoked for {user.Mention}, cleared the custom channel permissions.").ConfigureAwait(false);
                    await UnpermitLinkAsync(link).ConfigureAwait(false);
                }
                await Context.ApplyResultReaction(CommandResult.Success);
            }
            else
            {
                await Context.ApplyResultReaction(CommandResult.SuccessAlt1);
            }
        }
Example #2
0
        public async Task Permit(IUser user, ITextChannel channel, int numberOfKills = 0)
        {
            if (!Permissions.IsAdministratorOrBotOwner(Context))
            {
                await Context.ApplyResultReaction(CommandResult.FailedUserPermission).ConfigureAwait(false);

                return;
            }

            if (!(await Permissions.CanBotManageChannel(channel).ConfigureAwait(false)))
            {
                await Context.ApplyResultReaction(CommandResult.FailedBotPermission).ConfigureAwait(false);

                return;
            }

            // Find existing permit with the provided values.
            Link foundLink = null;

            foreach (var link in _links)
            {
                if (link.Guild == channel.Guild && link.Channel == channel)
                {
                    var userId = GetUserIdFromLink(link);
                    if (Context.User?.Id == userId)
                    {
                        foundLink = link;
                        break;
                    }
                }
            }

            if (foundLink != null)
            {
                // TODO: Update existing link?
                await Context.EmbedAsync(ContextMessageOption.ReplyWithError, "That user already has permission to access this channel, it's currently not supported to override or update existing permissions, please remove the permission first.");

                await Context.ApplyResultReaction(CommandResult.Failed).ConfigureAwait(false);
            }
            else
            {
                // Create link
                if (await PermitUserToChannel(user, channel, numberOfKills).ConfigureAwait(false))
                {
                    await Context.ApplyResultReaction(CommandResult.Success).ConfigureAwait(false);
                }
                else
                {
                    await Context.EmbedAsync(ContextMessageOption.ReplyWithError, "An unknown error occured while trying to create a user permission.");

                    await Context.ApplyResultReaction(CommandResult.Failed).ConfigureAwait(false);
                }
            }
        }