コード例 #1
0
        public async Task SetRoleAsSafe(DiscordRequest request, Contexts contexts)
        {
            var args = request.Arguments.Skip(1).ToArray(); // 1 args is string "role", so it's not needed

            if (args.Length < 2)
            {
                throw new NotEnoughArgumentsException();
            }

            var roleName    = args[0].Value;
            var toSetAsSafe = args[1].Value == "safe";

            var serverRole = _usersRolesService.GetRoleByName(roleName, contexts.Server);

            if (serverRole == null)
            {
                throw new RoleNotFoundException(roleName);
            }

            if (toSetAsSafe)
            {
                var command = new SetRoleAsSafeCommand(roleName, contexts.Server.Id);
                await _commandBus.ExecuteAsync(command);
            }
            else
            {
                var command = new SetRoleAsUnsafeCommand(roleName, contexts.Server.Id);
                await _commandBus.ExecuteAsync(command);
            }

            var messagesService = _messagesServiceFactory.Create(contexts);
            await messagesService.SendResponse(x => x.RoleSettingsChanged(roleName), contexts);
        }
コード例 #2
0
        public Task SetSafeRole(string roleName, ulong serverId)
        {
            var command = new SetRoleAsSafeCommand(roleName, serverId);

            return(this._commandBus.ExecuteAsync(command));
        }