public static void LoadUsersEmotes() { //LoadEmotesFromApi(); if (loadEmotes == false) { loadEmotes = true; bool isalreadyjoined = false; foreach (var channel in TwitchChannel.Channels) { if (channel.Name.Equals(Account.Username)) { isalreadyjoined = true; break; } } //part and join the users channel if (isalreadyjoined) { Client.WriteConnection.WriteLine("PART #" + Account.Username); } Client.WriteConnection.WriteLine("JOIN #" + Account.Username); if (!isalreadyjoined) { Client.WriteConnection.WriteLine("PART #" + Account.Username); } } Emotes.TriggerEmotesLoaded(); }
public static void LoadUsersEmotes() { try { string userid = Account.UserId, oauth = Account.OauthToken; var request = WebRequest.Create( $"https://api.twitch.tv/kraken/users/{userid}/emotes"); if (AppSettings.IgnoreSystemProxy) { request.Proxy = null; } ((HttpWebRequest)request).Accept = "application/vnd.twitchtv.v5+json"; request.Headers["Client-ID"] = $"{DefaultClientID}"; request.Headers["Authorization"] = $"OAuth {oauth}"; using (var response = request.GetResponse()) { using (var stream = response.GetResponseStream()) { dynamic json = new JsonParser().Parse(stream); //GuiEngine.Current.log(JsonConvert.SerializeObject(json)); Emotes.TwitchEmotes.Clear(); foreach (var set in json["emoticon_sets"]) { int setID; int.TryParse(set.Key, out setID); foreach (var emote in set.Value) { string id; id = emote["id"]; string code = Emotes.GetTwitchEmoteCodeReplacement(emote["code"]); Emotes.TwitchEmotes[code] = new TwitchEmoteValue { ID = id, Set = setID, ChannelName = "<unknown>" }; } } } response.Close(); } } catch (Exception e) { GuiEngine.Current.log("Generic Exception Handler: " + e.ToString()); } Emotes.TriggerEmotesLoaded(); }
// Connection public static void Connect() { Disconnect(); // Login string username = Account.Username, oauth = Account.OauthToken; try { if (Account.IsAnon) { if (AppSettings.SelectedUser != "") { AppSettings.SelectedUser = ""; AppSettings.Save(); } } else { if (!string.Equals(username, AppSettings.SelectedUser)) { AppSettings.SelectedUser = username; AppSettings.Save(); } } } catch { } LoggedIn?.Invoke(null, EventArgs.Empty); AppSettings.UpdateCustomHighlightRegex(); // fetch ignored users if (!Account.IsAnon) { Task.Run(() => { try { var limit = 100; var count = 0; string nextLink = $"https://api.twitch.tv/kraken/users/{username}/blocks?limit={limit}&client_id={Account.ClientId}"; var request = WebRequest.Create(nextLink + $"&oauth_token={oauth}"); using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) { dynamic json = new JsonParser().Parse(stream); dynamic _links = json["_links"]; nextLink = _links["next"]; dynamic blocks = json["blocks"]; count = blocks.Count; foreach (var block in blocks) { dynamic user = block["user"]; string name = user["name"]; string display_name = user["display_name"]; twitchBlockedUsers[name] = null; } } } catch { } }); } // fetch available twitch emotes if (!Account.IsAnon) { Task.Run(() => { try { var request = WebRequest.Create( $"https://api.twitch.tv/kraken/users/{username}/emotes?oauth_token={oauth}&client_id={Account.ClientId}"); using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) { dynamic json = new JsonParser().Parse(stream); Emotes.TwitchEmotes.Clear(); foreach (var set in json["emoticon_sets"]) { int setID; int.TryParse(set.Key, out setID); foreach (var emote in set.Value) { int id; int.TryParse(emote["id"], out id); string code = Emotes.GetTwitchEmoteCodeReplacement(emote["code"]); Emotes.TwitchEmotes[code] = new TwitchEmoteValue { ID = id, Set = setID, ChannelName = "<unknown>" }; } } } } catch { } Emotes.TriggerEmotesLoaded(); }); } // connect read Task.Run(() => { Client = new IrcClient(Account.IsAnon); Client.ReadConnection.Connected += (s, e) => { foreach (var channel in TwitchChannel.Channels) { Client.ReadConnection.WriteLine("JOIN #" + channel.Name); } Connected?.Invoke(null, EventArgs.Empty); }; Client.ReadConnection.Disconnected += (s, e) => { Disconnected?.Invoke(null, EventArgs.Empty); }; if (!Account.IsAnon) { Client.WriteConnection.Connected += (s, e) => { foreach (var channel in TwitchChannel.Channels) { Client.WriteConnection.WriteLine("JOIN #" + channel.Name); } }; } Client.Connect(username, (oauth.StartsWith("oauth:") ? oauth : "oauth:" + oauth)); Client.ReadConnection.MessageReceived += ReadConnection_MessageReceived; Client.WriteConnection.MessageReceived += WriteConnection_MessageReceived; }); // secret telemetry, please ignore :) // anonymously count user on fourtf.com with the first 32 characters of a sha 256 hash of the username if (!Account.IsAnon) { Task.Run(() => { try { string hash; using (var sha = SHA256.Create()) { hash = string.Join("", sha .ComputeHash(Encoding.UTF8.GetBytes(username)) .Select(item => item.ToString("x2"))); } hash = hash.Remove(32); var request = WebRequest.Create($"https://fourtf.com/chatterino/countuser.php?hash={hash}"); using (var response = request.GetResponse()) using (response.GetResponseStream()) { } } catch { } }); } }
private static void UpdateEmotes(IrcMessage msg) { if (loadEmotes && msg.Tags.TryGetValue("emote-sets", out string value)) { //GuiEngine.Current.log("sets: " + value); string[] emote_sets = value.Split(','); string temp = ""; int count = 1; string emote_set; //split into groups of 10 since thats the limit you can request at once from the api https://api.twitch.tv/helix/chat/emotes/set?emote_set_id= for (int i = 0; i < emote_sets.Length; i++) { emote_set = emote_sets[i]; if (count != 1) { temp += "&emote_set_id="; } temp += emote_set; if (count == 10 || i == (emote_sets.Length - 1)) { //api request try { var request = WebRequest.Create($"https://api.twitch.tv/helix/chat/emotes/set?emote_set_id={temp}"); request.Method = "GET"; //GuiEngine.Current.log("url : " + $"https://api.twitch.tv/helix/chat/emotes/set?emote_set_id={temp}"); if (AppSettings.IgnoreSystemProxy) { request.Proxy = null; } ((HttpWebRequest)request).Accept = "application/json"; request.Headers["Client-ID"] = $"{Account.ClientId}"; request.Headers["Authorization"] = $"Bearer {Account.OauthToken}"; //GuiEngine.Current.log("body: Client-ID: " + Account.ClientId + " Authorization: Bearer " + Account.OauthToken); using (var response = request.GetResponse()) { using (var stream = response.GetResponseStream()) { dynamic json = new JsonParser().Parse(stream); if (json != null) { dynamic data = json["data"]; foreach (var emote in data) { string id = emote["id"]; string owner_id = emote["owner_id"]; if (owner_id == "twitch") { owner_id = "0"; } string emote_type = emote["emote_type"]; string name = emote["name"]; int emote_set_id = Int32.Parse(emote["emote_set_id"]); //GuiEngine.Current.log("name : " + name + " set_id " + emote_set_id + " owner_id " + owner_id + " emotetype " + emote_type ); string code = Emotes.GetTwitchEmoteCodeReplacement(name); Emotes.RecentlyUsedEmotes.TryRemove(code, out LazyLoadedImage image); if (!emote_type.Equals("limitedtime") && !emote_type.Equals("owl2019")) { Emotes.TwitchEmotes[code] = new TwitchEmoteValue { OwnerID = owner_id, Type = emote_type, Name = name, ID = id, Set = emote_set_id, ChannelName = "" }; } } } } response.Close(); } } catch (Exception exc) { GuiEngine.Current.log("Generic Exception Handler: " + exc.ToString()); } temp = ""; count = 1; } else { count++; } } } loadEmotes = false; Emotes.TriggerEmotesLoaded(); }