public static bool MergeAccounts(Bots.StandardisedMessageRequest e, BotInstance BotInstance, string ID) { if (BotInstance.CommandConfig["Discord"]["TwitchMerging"].ToString().ToLower() == "true") { if (e.MessageType == Bots.MessageType.Discord) { if (e.Viewer.TwitchID != "") { return(false); } try { WebRequest Req = WebRequest.Create("https://discordapp.com/api/v6/users/" + ID + "/profile"); Req.Headers.Add("authorization", Init.MasterConfig["Discord"]["User"]["AuthToken"].ToString()); Req.Method = "GET"; WebResponse Res = Req.GetResponse(); string D = new StreamReader(Res.GetResponseStream()).ReadToEnd(); Newtonsoft.Json.Linq.JObject ProfileData = Newtonsoft.Json.Linq.JObject.Parse(D); foreach (Newtonsoft.Json.Linq.JObject Connection in ProfileData["connected_accounts"]) { if (Connection["type"].ToString() == "twitch") { Viewer Twitch = FromTwitchDiscord(Bots.MessageType.Twitch, BotInstance, Connection["id"].ToString()); Viewer Discord = e.Viewer; if (Twitch.DiscordID == "" && Discord.TwitchID == "") { AdjustBalance(Twitch, Twitch.Balance, "-"); AdjustBalance(Discord, Twitch.Balance, "+"); List <KeyValuePair <string, string> > Headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("TwitchID", Connection["id"].ToString()), new KeyValuePair <string, string>("DiscordID", ID), new KeyValuePair <string, string>("ID", Discord.ID.ToString()) }; ResponseObject RObj = WebRequests.PostRequest("viewer", Headers, true); Headers = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("ID", Twitch.ID.ToString()) }; RObj = WebRequests.PostRequest("viewer", Headers, true); } } } } catch (WebException E) { } } } return(false); }
public static Viewer FromTwitchDiscord(Bots.StandardisedMessageRequest e, BotInstance BotInstance, string ID, ref bool CreatedViewer) { return(FromTwitchDiscord(e.MessageType, BotInstance, ID, ref CreatedViewer)); }