public void ChangeClientInformation(DiscordUserInformation info) { string usernameRequestJson; if (info.password != ClientPrivateInformation.password) { usernameRequestJson = JsonConvert.SerializeObject(new { email = info.email, new_password = info.password, password = ClientPrivateInformation.password, username = info.username, avatar = info.avatar }); ClientPrivateInformation.password = info.password; File.Delete("token_cache"); DebugLogger.Log("Deleted token_cache due to change of password."); } else { usernameRequestJson = JsonConvert.SerializeObject(new { email = info.email, password = info.password, username = info.username, avatar = info.avatar }); } string url = Endpoints.BaseAPI + Endpoints.Users + "/@me"; try { var result = JObject.Parse(WebWrapper.Patch(url, token, usernameRequestJson)); foreach (var server in ServersList) { foreach (var member in server.members) { if (member.ID == Me.ID) member.Username = info.username; } } Me.Username = info.username; Me.Email = info.email; Me.Avatar = info.avatar; } catch(Exception ex) { DebugLogger.Log($"Error ocurred while changing client's information: {ex.Message}", MessageLevel.Error); } }
public void ChangeBotInformation(DiscordUserInformation info) { string usernameRequestJson; if (info.password != ClientPrivateInformation.password) { usernameRequestJson = JsonConvert.SerializeObject(new { email = info.email, new_password = info.password, password = ClientPrivateInformation.password, username = info.username, avatar = info.avatar }); ClientPrivateInformation.password = info.password; } else { usernameRequestJson = JsonConvert.SerializeObject(new { email = info.email, password = info.password, username = info.username, avatar = info.avatar }); } var httpRequest = (HttpWebRequest)WebRequest.Create("https://discordapp.com/api/users/@me"); httpRequest.Headers["authorization"] = token; httpRequest.ContentType = "application/json"; httpRequest.Method = "PATCH"; using (var sw = new StreamWriter(httpRequest.GetRequestStream())) { sw.Write(usernameRequestJson.ToString()); sw.Flush(); sw.Close(); } try { var httpResponse = (HttpWebResponse)httpRequest.GetResponse(); using (var sr = new StreamReader(httpResponse.GetResponseStream())) { var result = JObject.Parse(sr.ReadLine()); foreach (var server in ServersList) { foreach (var member in server.members) { if (member.user.id == Me.user.id) member.user.username = info.username; } } Me.user.username = info.username; Me.user.email = info.email; Me.user.avatar = info.avatar; } } catch (Exception ex) { if (DebugMessageReceived != null) DebugMessageReceived(this, new DiscordDebugMessagesEventArgs { message = ex.Message }); } }
public DiscordClient() { if (ClientPrivateInformation == null) ClientPrivateInformation = new DiscordUserInformation(); DebugLogger.LogMessageReceived += (sender, e) => { if (e.message.Level == MessageLevel.Error) DisconnectFromVoice(); if (TextClientDebugMessageReceived != null) TextClientDebugMessageReceived(this, e); }; }
public DiscordClient() { if (ClientPrivateInformation == null) ClientPrivateInformation = new DiscordUserInformation(); }