public IChannel GetChannel() { if (Server.chans.Any(s => s.Id == ChannelID)) { return(Server.chans.Where(s => s.Id == ChannelID).First()); } else { SocketChannel ch = SocketChannel.GetChannel(ChannelID); Server.chans.Add(ch); return(ch); } }
public static SocketRemoteUser GetUser(long UserId) { string data; if (Server.poeople is null) { Server.poeople = new(); } if (Server.poeople.Count > 0 && Server.poeople.Any(s => s.ID == UserId)) { var temp = Server.poeople.Where(s => s.ID == UserId).FirstOrDefault() as SocketRemoteUser; if (temp.Channel == null) { foreach (SocketChannel chan in Server.chans) { if (chan.Type == ChannelType.DM && chan.Id != 0 && chan.members is not null) { if (chan.members.Any(s => s == UserId)) { temp.Channel = chan; } } } } return(temp); } while (true) { if (Server.CanRequest) { using HttpClient web = new(); web.DefaultRequestHeaders.Add("token", Server.Token); web.DefaultRequestHeaders.Add("id", UserId.ToString()); data = web.GetAsync($"https://{Server.Domain}/Luski/api/{Server.API_Ver}/socketuser").Result.Content.ReadAsStringAsync().Result; break; } } SocketRemoteUser?user = JsonSerializer.Deserialize <SocketRemoteUser>(data); if (user is null) { throw new Exception("Server did not return a user"); } if (Server.poeople.Count > 0 && Server.poeople.Any(s => s.ID == UserId)) { foreach (IUser?p in Server.poeople.Where(s => s.ID == UserId)) { Server.poeople.Remove(p); } } if (UserId != 0) { foreach (SocketChannel chan in Server.chans) { if (chan.Type == ChannelType.DM && chan.Id != 0 && chan.members is not null) { if (chan.members.Any(s => s == UserId)) { user.Channel = chan; } } } } else { user.Channel = SocketChannel.GetChannel(0); } Server.poeople.Add(user); return(user); }