コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: DiscordClient.cs プロジェクト: talemon/DiscordSharp
        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 });
            }
        }
コード例 #3
0
        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);
            };
        }
コード例 #4
0
ファイル: DiscordClient.cs プロジェクト: talemon/DiscordSharp
 public DiscordClient()
 {
     if (ClientPrivateInformation == null)
         ClientPrivateInformation = new DiscordUserInformation();
 }