// Place into a region after completion private void Client_OnChatCommandReceived(object sender, TwitchLib.Events.Client.OnChatCommandReceivedArgs e) { switch (e.Command.Command) { case "test": Client.SendMessage("Test command fired!"); break; case "UpdateViewerList": UpdateViewersText(); break; default: // Action taken by all commands break; } }
private void Client_OnChatCommandReceived(object sender, TwitchLib.Events.Client.OnChatCommandReceivedArgs e) { // yeey commands string m = string.Empty; List <string> param = e.Command.ArgumentsAsList; tbx_chat.BeginInvoke((MethodInvoker) delegate { // close enough damnit switch (e.Command.Command) { case "songrequest": case "sr": if (param.Count == 0) { m = $"@{e.Command.ChatMessage.DisplayName} you need to specify an youtube link to request a song."; } else { Regex r = new Regex(@"watch\?v="); Song s = new Song(); s.title = e.Command.ChatMessage.DisplayName; Uri u = new Uri(r.Replace(param[0], "v/")); s.link = u; songs.Add(s); if (songs.First() == s) { ytplayer.Movie = s.link.ToString(); ytplayer.Play(); } m = $"@{e.Command.ChatMessage.DisplayName} Your song has succesfully been added to the queue."; } break; case "addcommand": if (!e.Command.ChatMessage.IsModerator) { m = $"@{e.Command.ChatMessage.DisplayName} you need to be an moderator to add commands."; break; } if (param.Count == 0) { m = $"@{e.Command.ChatMessage.DisplayName} you need to type more parameters to add a command."; } else if (param.Count == 1) { m = $"@{e.Command.ChatMessage.DisplayName} you need to specify my response."; } else { string reply = string.Empty; for (int i = 0; i < param.Count; i++) { if (i == 1) { reply = param[i]; } else if (i > 1) { reply += $" {param[i]}"; } } using (SQLiteConnection db = new SQLiteConnection(ConnectionString)) { db.Open(); using (SQLiteCommand dbCommand = new SQLiteCommand($"INSERT INTO `commands`(ctext,message) VALUES(\"{param[0]}\",\"{reply}\")", db)) { dbCommand.ExecuteNonQuery(); } } m = $"@{e.Command.ChatMessage.DisplayName}, i have succesfully added the command: !{param[0]} with as response: {reply}"; getCommands(); // refresh the commands visible } break; case "points": using (SQLiteConnection db = new SQLiteConnection(ConnectionString)) { db.Open(); using (SQLiteCommand dbCommand = new SQLiteCommand($"SELECT points FROM `users` WHERE `username`=\"{e.Command.ChatMessage.Username}\" LIMIT 1", db)) { m = $"@{e.Command.ChatMessage.Username} you currently have: {dbCommand.ExecuteScalar()} Points."; } } break; case "commands": int cc; string commands = string.Empty, tmp; using (SQLiteConnection db = new SQLiteConnection(ConnectionString)) { db.Open(); using (SQLiteCommand dbCommand = new SQLiteCommand("SELECT COUNT(id) FROM `commands`", db)) { cc = Convert.ToInt16(dbCommand.ExecuteScalar()); } for (int i = 0; i < cc; i++) { using (SQLiteCommand dbCommand = new SQLiteCommand($"SELECT ctext FROM `commands` WHERE `id`={i + 1}", db)) { tmp = (string)dbCommand.ExecuteScalar(); } if (i == 0) { commands = $"!{tmp}"; } else { commands += $",!{tmp}"; } } } if (e.Command.ChatMessage.IsModerator) { commands += ",!addcommand(mod)"; } m = $"The available commands are: {commands}"; break; default: using (SQLiteConnection db = new SQLiteConnection(ConnectionString)) { db.Open(); using (SQLiteCommand dbCommand = new SQLiteCommand($"SELECT message FROM `commands` WHERE `ctext`=\"{e.Command.Command}\" LIMIT 1", db)) { m = (string)dbCommand.ExecuteScalar(); } } if (string.IsNullOrEmpty(m)) { m = $"@{e.Command.ChatMessage.DisplayName} i cannot find the command \"{e.Command.ChatMessage.Message}\""; } break; } client.SendMessage($"/me {m}"); tbx_chat.AppendText($"[waifu]{username}: {m}{Environment.NewLine}"); }); }