Example #1
0
        }                                               //Necessary evul.


        public CommandArguments(IBotwinderClient client, Command command, Server server, SocketTextChannel channel, SocketMessage message, string commandId, string trimmedMessage, string[] messageArgs, CommandOptions options = null)
        {
            this.Client         = client;
            this.Command        = command;
            this.CommandOptions = options;
            this.Server         = server;
            this.Channel        = channel;
            this.Message        = message;
            this.CommandId      = commandId;
            this.TrimmedMessage = trimmedMessage;
            this.MessageArgs    = messageArgs;
        }
Example #2
0
        public bool CanExecuteCommand(string commandId, int commandPermissions, SocketGuildChannel channel, SocketGuildUser user)
        {
            CommandOptions commandOptions = GetCommandOptions(commandId);
            List <CommandChannelOptions> commandChannelOptions = GetCommandChannelOptions(commandId);

            //Custom Command Channel Permissions
            CommandChannelOptions currentChannelOptions = null;

            if (commandPermissions != PermissionType.OwnerOnly &&
                channel != null && commandChannelOptions != null &&
                (currentChannelOptions = commandChannelOptions.FirstOrDefault(c => c.ChannelId == channel.Id)) != null &&
                currentChannelOptions.Blacklisted)
            {
                return(false);
            }

            if (commandPermissions != PermissionType.OwnerOnly &&
                channel != null && commandChannelOptions != null &&
                commandChannelOptions.Any(c => c.Whitelisted) &&
                ((currentChannelOptions = commandChannelOptions.FirstOrDefault(c => c.ChannelId == channel.Id)) == null ||
                 !currentChannelOptions.Whitelisted))
            {
                return(false);                //False only if there are *some* whitelisted channels, but it's not the current one.
            }
            //Custom Command Permission Overrides
            if (commandOptions != null && commandOptions.PermissionOverrides != PermissionOverrides.Default)
            {
                switch (commandOptions.PermissionOverrides)
                {
                case PermissionOverrides.Nobody:
                    return(false);

                case PermissionOverrides.ServerOwner:
                    commandPermissions = PermissionType.ServerOwner;
                    break;

                case PermissionOverrides.Admins:
                    commandPermissions = PermissionType.ServerOwner | PermissionType.Admin;
                    break;

                case PermissionOverrides.Moderators:
                    commandPermissions = PermissionType.ServerOwner | PermissionType.Admin | PermissionType.Moderator;
                    break;

                case PermissionOverrides.SubModerators:
                    commandPermissions = PermissionType.ServerOwner | PermissionType.Admin | PermissionType.Moderator |
                                         PermissionType.SubModerator;
                    break;

                case PermissionOverrides.Members:
                    commandPermissions = PermissionType.ServerOwner | PermissionType.Admin | PermissionType.Moderator |
                                         PermissionType.SubModerator | PermissionType.Member;
                    break;

                case PermissionOverrides.Everyone:
                    commandPermissions = PermissionType.Everyone;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("permissionOverrides");
                }
            }

            //Actually check them permissions!
            return(((commandPermissions & PermissionType.Everyone) > 0) ||
                   ((commandPermissions & PermissionType.ServerOwner) > 0 && IsOwner(user)) ||
                   ((commandPermissions & PermissionType.Admin) > 0 && IsAdmin(user)) ||
                   ((commandPermissions & PermissionType.Moderator) > 0 && IsModerator(user)) ||
                   ((commandPermissions & PermissionType.SubModerator) > 0 && IsSubModerator(user)) ||
                   ((commandPermissions & PermissionType.Member) > 0 && IsMember(user)));
        }