public static byte GetRolePermission(SocketRole role, GuildDB database) { // find any permissions in the database PermissionTB dbresult = (from p in database.Permissions where p.PermissionType == PermissionType.Role && p.Guild.GuildId == role.Guild.Id && p.PermissionTarget == role.Id select p).FirstOrDefault(); // if no permission was found, this role has public permission if (dbresult == null) { return(Public); } // otherwise, return permission return(dbresult.Permission); }
public static bool SetUserPermission(SocketGuildUser user, byte permission, GuildDB database, GuildTB guildentry) { // First check if there is already a permission for this user PermissionTB p = (from perm in database.Permissions where perm.Guild.GuildId == user.Guild.Id && perm.PermissionType == PermissionType.User && perm.PermissionTarget == user.Id select perm).FirstOrDefault(); if (p != null) { // if there is already a permission for given user, update it p.Permission = permission; database.Permissions.Update(p); } else { // if no permission is specified, create a new one p = new PermissionTB { Guild = guildentry, PermissionType = PermissionType.User, PermissionTarget = user.Id, Permission = permission, }; database.Permissions.Add(p); } try { database.SaveChanges(); return(true); } catch (Exception) { return(false); } }