Example #1
0
 private DynPermFullData(DynamicPerms perms, string pastebinUrl)
 {
     Perms = perms;
     PastebinUrl = pastebinUrl;
     if (string.IsNullOrEmpty(pastebinUrl))
         IsDirty = true;
 }
Example #2
0
 private DynPermFullData(DynamicPerms perms, string pastebinUrl)
 {
     Perms       = perms;
     PastebinUrl = pastebinUrl;
     if (string.IsNullOrEmpty(pastebinUrl))
     {
         IsDirty = true;
     }
 }
Example #3
0
        public DynPermFullData SetDynPermFullData(ulong serverId, string input, out string error)
        {
            try
            {
                DynamicPerms perms = JsonConvert.DeserializeObject <DynamicPerms>(input);

                if (perms == null)
                {
                    error = "Deserialization of input resulted in null params.";
                    return(null);
                }

                DynPermFullData fullPermData = new DynPermFullData(perms);
                Server          server       = _client.GetServer(serverId);

                // verify the data (role && user ids)
                if (server == null)
                {
                    error = $"Server id {serverId} not found.";
                    return(null);
                }

                foreach (var pair in fullPermData.Perms.RolePerms)
                {
                    ulong invalidChannelId;
                    if (IsInvalidChannelsInBlock(pair.Value, server, out invalidChannelId))
                    {
                        error = $"Channel id {invalidChannelId} not found.";
                        return(null);
                    }
                }

                foreach (var pair in fullPermData.Perms.UserPerms)
                {
                    if (server.GetUser(pair.Key) == null)
                    {
                        error = $"User id {pair.Key} not found.";
                        return(null);
                    }
                }

                // data looks fine, add the dynrole to the dict.
                _perms.AddOrUpdate(serverId, fullPermData, (k, v) => fullPermData);

                error = null;
                return(fullPermData);
            }
            catch (Exception ex)
            {
                error =
                    $"Failed deserializing input. Make sure your input is valid JSON.\r\nDebug: ```{ex.GetType().Name}: {ex.Message}:{ex.TargetSite}```";
            }

            return(null);
        }
Example #4
0
 public DynPermFullData(DynamicPerms perms) : this(perms, null)
 {
 }
Example #5
0
 public DynPermFullData(DynamicPerms perms) : this(perms, null)
 {
 }