public void incrementEmotes(string channel, ChatMessage message, EmoteManager emoteManager) { List <string> split_msg = new List <string>(message.message.Split(' ')); HashSet <Emote> emoteList = new HashSet <Emote>(emoteManager.getEmoteList()); SQLiteCommand sqlcmd; string query; foreach (Emote emote in emoteList) { int occurances = split_msg.Where(word => word == emote.name).Count(); if (occurances > 0) { query = $"UPDATE '{channel}' SET count = count + {occurances} WHERE id = '{emote.id}'"; sqlcmd = new SQLiteCommand(query, connection); int record_exists = sqlcmd.ExecuteNonQuery(); if (record_exists < 1) { query = $"INSERT OR IGNORE INTO '{channel}'(id, name, count, origin) VALUES (@id, @name, @count, @origin)"; sqlcmd = new SQLiteCommand(query, connection); sqlcmd.Parameters.AddWithValue("@id", emote.id); sqlcmd.Parameters.AddWithValue("@name", emote.name); sqlcmd.Parameters.AddWithValue("@count", 0); sqlcmd.Parameters.AddWithValue("@origin", emote.origin); sqlcmd.ExecuteNonQuery(); query = $"UPDATE '{channel}' SET count = count + {occurances} WHERE id = '{emote.id}'"; sqlcmd = new SQLiteCommand(query, connection); sqlcmd.ExecuteNonQuery(); } } } }
public async Task start(string channel) { var tcpClient = new TcpClient(); await tcpClient.ConnectAsync(ip, port); SslStream sslStream = new SslStream(tcpClient.GetStream(), false, ValidateServerCertificate, null); await sslStream.AuthenticateAsClientAsync(ip); streamReader = new StreamReader(sslStream); streamWriter = new StreamWriter(sslStream) { NewLine = "\r\n", AutoFlush = true }; await streamWriter.WriteLineAsync("CAP REQ :twitch.tv/tags"); await streamWriter.WriteLineAsync($"PASS {oauth}"); await streamWriter.WriteLineAsync($"NICK {nick}"); connected.SetResult(0); await joinChannel(channel); await refreshStreamsData(true); refreshStreamsData().SafeFireAndForget(); chatDatabase = new ChatDatabase(currentChannel); emoteDatabase = new EmoteDatabase(currentChannel); emoteManager = new EmoteManager(currentChannel, channelId); await emoteManager.start(); string line = ""; while (true) { line = await streamReader.ReadLineAsync(); string[] split = line.Split(" "); if (line.StartsWith("PING")) { await streamWriter.WriteLineAsync($"PONG tmi.twitch.tv"); } if (split.Length > 3 && split[2] == "PRIVMSG") { ChatMessage twitchMessage = processIRCMessage(line, split); chatDatabase.appendMessage(twitchMessage); emoteDatabase.incrementEmotes(currentChannel, twitchMessage, emoteManager); } } }