/// <summary> /// Chat Service ChatMessageReceived Event Handler. /// Adds received message to chat message collection. /// </summary> private void _chatService_ChatMessageReceived(object sender, ChatConnectionMessageReceivedEventArgs e) { // Add received message to limited collection DispatcherHelper.CheckBeginInvokeOnUI(() => { _chatMessages.AddAndTrim(e.ChatMessage); }); }
private void _chat_RawMessageReceived(object sender, ChatConnectionMessageReceivedEventArgs e) { if (e.ChatMessage.Command == IrcCommand.PrivMsg) { if (e.ChatMessage.IsSubscriber) { var length = e.ChatMessage.Message.Split().Length; var command = e.ChatMessage.Message.Split().First(); var msg = string.Join(" ", e.ChatMessage.Message.Split((char[])null, StringSplitOptions.RemoveEmptyEntries).Select(i => i.Trim()).Skip(1)); var ID = e.ChatMessage.UserId; var bday = new BDay(); if (command.ToLower() == "!mybday") { var IsDate = DateTime.TryParse(msg, out DateTime date); if ((length == 2 || length == 3) && !Exist(ID) && IsDate) { bday.UserID = e.ChatMessage.UserId; bday.Name = e.ChatMessage.Author; bday.Date = date.ToString(); AddBDay(bday); chat.SendMessage("edeGOOD " + e.ChatMessage.Author, false); } else if ((length < 2 || length > 3) || !IsDate) { chat.SendMessage("Correct Use is '!mybday (date)' Month and Day only! Examples: 10/3, 10-3, 10.3 or October 3 Either way works edeWINK", false); } else if (Exist(ID)) { } } else if (Exist(ID)) { if (!names.Contains(e.ChatMessage.UserId)) { bday = GetUser(ID); names += e.ChatMessage.UserId + " "; if (DateTime.Parse(bday.Date).Month == DateTime.Today.Month && DateTime.Parse(bday.Date).Day == DateTime.Today.Day) { chat.SendMessage("/me edeUP edeUP edeUP Happy Birthday " + e.ChatMessage.Author + " edeUP edeUP edeUP", false); } } } } else { var first = e.ChatMessage.Message.Split().First(); if (first.ToLower() == "!mybday") { chat.SendMessage("Sorry " + e.ChatMessage.Author + ", !mybday is a Subscriber only feature. edeWINK", false); } } } }
private void _chat_RawMessageReceived(object sender, ChatConnectionMessageReceivedEventArgs e) { if (e.ChatMessage.Command == IrcCommand.PrivMsg) { } }
/// Raw Message received event handler, fired on every IRC message received. private void _chat_RawMessageReceived(object sender, ChatConnectionMessageReceivedEventArgs e) { #region UserNotice // raw message UserNotice if (e.ChatMessage.Command == IrcCommand.UserNotice) { if (e.ChatMessage.NoticeType == NoticeMessageType.Sub || e.ChatMessage.NoticeType == NoticeMessageType.Resub || e.ChatMessage.NoticeType == NoticeMessageType.SubGift) { subCount += 1; Console.WriteLine(e.ChatMessage.RawMessage); int tier; var welcomeMessage = string.Empty; var ID = e.ChatMessage.UserId; var Name = e.ChatMessage.SubscriptionLogin; bool Add = false; var sub = new Sub(); if ((int)e.ChatMessage.SubscriptionPlan == 0) { tier = 1; } else { tier = (int)e.ChatMessage.SubscriptionPlan; } switch (e.ChatMessage.NoticeType) { case NoticeMessageType.Sub: welcomeMessage = " edeHI Welcome " + Name + ", edeHYPE Thank you for being our " + subCount + " subscriber today!! edeWINK edePIMP edePIMP"; break; case NoticeMessageType.Resub: welcomeMessage = " edeHI Welcome back " + Name + ", edeGOOD Thank you for being our " + subCount + " subscriber today!! edeWINK edePIMP edePIMP"; break; case NoticeMessageType.SubGift: Name = e.ChatMessage.GiftRecipientUserName; ID = e.ChatMessage.GiftRecipientUserID; welcomeMessage = " edeHI Welcome " + Name + ", edeHYPE Thank you for being our " + subCount + " subscriber today!! edeWINK edePIMP edePIMP (Courtesy of " + e.ChatMessage.SubscriptionLogin + ", Their " + e.ChatMessage.GiftSenderCount + " Gift) edeLOVE edeLOVE"; break; } if (IsSub(ID)) { Add = false; sub = GetSub(ID); if (tier != sub.Tier) { sub.Tier = tier; if (tier > sub.Tier) { prefix = "+"; } else if (tier < sub.Tier) { prefix = "-"; } if (tier == 3) { sub.New = true; } } else { prefix = string.Empty; } if (sub.Name != Name) { sub.Name = Name; } } else { prefix = string.Empty; Add = true; sub.Name = Name; sub.UserID = ID; sub.Tier = tier; if (tier == 3) { sub.New = true; } } chat.SendMessage("/me " + prefix + " " + welcomeMessage, false); if (trainEnd.Enabled || trainStart.Enabled) { trainCount += 1; chat.SendMessage("edeTRAIN edeTRAIN edeTRAIN edeTRAIN edeTRAIN " + trainCount, false); trainEnd.Reset(); trainWarn.Reset(); } else { trainCount = 1; trainStart.Start(); } if (trainCount > trainDayHigh) { trainDayHigh = trainCount; if (trainDayHigh > trainHigh) { trainHigh = trainDayHigh; // Save Highest Sub Train var tw = new StreamWriter(TRAINFILE + "HighestTrain.txt"); tw.WriteLine(trainHigh); tw.Close(); } } if (sub.New) { chat.SendMessage("/me " + Name + ", edeHYPE Congrats on the tier 3 sub please contact Flash0429 and he will get you set all setup with your intro!! edeGOOD", false); } if (Add) { AddSub(sub); } else { UpdateSub(sub); } var r = new Random(); var color = String.Format("#{0:X6}", r.Next(0x1000000)); chat.SendMessage("/color " + color, false); } if (e.ChatMessage.NoticeType == NoticeMessageType.Raid) { chat.SendMessage("/followersoff", false); raid.Start(); chat.SendMessage("Thank You " + e.ChatMessage.RaidUserName + " For the raid of " + e.ChatMessage.RaidCount + " viewers! edeCAP edeZORD edeCAP edeZORD edeCAP edeZORD", false); } } #endregion #region PrivMsg // normal chat message if (e.ChatMessage.Command == IrcCommand.PrivMsg) { string[] message = e.ChatMessage.Message.Split(); var emotes = e.ChatMessage.UsedEmotes; if (e.ChatMessage.Message.Contains("miistyDab") || e.ChatMessage.Message.Contains("broD")) { chat.SendMessage("/timeout " + e.ChatMessage.Author + " 1 No Dabbing", false); } if (message[0].ToLower() == "!multi") { if (multi == noMulti) { chat.SendMessage(multi, false); } else { chat.SendMessage(multiMessage + " " + multi + "/Lcolumns", false); } } if (e.ChatMessage.IsModerator || e.ChatMessage.Badges.Exists(x => x.Contains("broadcaster")) || e.ChatMessage.IsSubscriber) { switch (message[0].ToLower()) { case "!subs": chat.SendMessage("Subs Today: " + subCount, false); break; case "!train": if (trainEnd.Enabled) { chat.SendMessage("Train Length: " + trainCount + " - Train Departure: " + trainEnd.GetTimeLeft() + " - Longest Train Today: " + trainDayHigh + " - Longest Train All Time: " + trainHigh, false); } else { chat.SendMessage("The edeTRAIN has not arrived yet!!", false); } break; } } if (e.ChatMessage.IsModerator || e.ChatMessage.Badges.Exists(x => x.Contains("broadcaster"))) { switch (message[0].ToLower()) { case "~set": if (message.Length == 2) { subCount = Convert.ToInt32(message[1]); } break; case "~start": trainStart.Start(); break; case "!multiset": SetMulti(message); break; case "!multiadd": if (multi == noMulti) { chat.SendMessage("Sorry, No multi to edit right now, use !multiset to set the multi first", false); } else { AddMulti(message); } break; case "!multidel": if (multi == noMulti) { chat.SendMessage("Sorry, No multi to edit right now, use !multiset to set the multi first", false); } else { DelMulti(message); } break; case "!multimsg": if (multi == noMulti) { chat.SendMessage("Sorry, No multi to edit right now, use !multiset to set the multi first", false); } else { multiMessage = string.Join(" ", message.Select(i => i.Trim()).Skip(1)); chat.SendMessage("Message Changed edeGOOD", false); } break; case "!multiclear": if (multi == noMulti) { chat.SendMessage("Already Cleared edeBRUH", false); } else { multi = noMulti; chat.SendMessage("Multi Cleared edeANGEL", false); } break; case "~reset": test.Reset(); break; case "~tstart": test.Start(); break; case "~time": chat.SendMessage(test.GetTimeLeft(), false); break; case "~test": chat.SendMessage(chat.GetChannelName(), false); break; } } } #endregion }
/// <summary> /// Chat MessageReceived; handle chat command and entries for 'keyword' giveaway. /// </summary> private async void _chatService_ChatMessageReceived(object sender, ChatConnectionMessageReceivedEventArgs e) { // Can only be entered with the giveaway is active, keyword can be set to be case sensitive if (_isActive && e.ChatMessage.Message.StartsWith(_moduleSettings.Keyword, IgnoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture)) { // Let the AddEntry handle if the person is eligiable to enter AddEntry(e.ChatMessage); } // Winners messages if (!_isActive && _selectedWinner.UserId == e.ChatMessage.UserId) { // Winners first message if (!_WinnerHasReplied) { // Set winner has replied WinnerHasReplied = true; // Stop response timer _timerResponse.Stop(); // Transmit WS event _wsEventService.SendRegisteredEvent("GIVEAWAY_DONE", new GiveawayWebsocketEventBase(_moduleId)); // Add winner to winners list await DispatcherHelper.RunAsync(() => { _listWinners.Add(SelectedWinner); }); // Save winner to file after winners list has been updated SaveSettings(); } // Add any message from winner to overview DispatcherHelper.CheckBeginInvokeOnUI(() => { _listMessagesWinner.Add(e.ChatMessage); }); } // Command structure if (e.ChatMessage.Message.StartsWith("!raffle", StringComparison.InvariantCultureIgnoreCase) // Only moderators and the broadcaster can use the !raffle command /* TODO: Other rights when implemented in the bot */ && (e.ChatMessage.IsModerator || e.ChatMessage.Badges.Exists(x => x.Contains("broadcaster")))) { // split the command on whitespaces to retrieve the arguments of the command string[] cmdArgs = e.ChatMessage.Message.Split((char[])null, 3, StringSplitOptions.RemoveEmptyEntries); // First giveaway module (id = 1) can be adddessed with !raffle and no id. // If module has another id than 1 it needs to be specifically addressed with !raffle<id> string addressing = string.IsNullOrEmpty(cmdArgs[0].Substring(7)) ? "1" : cmdArgs[0].Substring(7); if (addressing != _moduleId.ToString()) { return; } // Module is addressed check what arguments the !raffle command has if (cmdArgs.Length > 2 && cmdArgs[1].Equals("open", StringComparison.InvariantCultureIgnoreCase)) { string[] openArgs = cmdArgs[2].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); switch (openArgs.Length) { // !raffle open <keyword>|<description> // Open a new giveaway with new keyword and description case 2: Open(openArgs[0], openArgs[1]); break; // !raffle open <keyword>|<description>|<run-time-min> // Open a new giveaway with new keyword, description, and overrides runtime case 3: if (!Int32.TryParse(openArgs[2], out int parsedRunTime)) { // Invalid time given, set to disabled open time parsedRunTime = 0; } Open(openArgs[0], openArgs[1], parsedRunTime); break; // !raffle open <keyword>|<description>|<run-time-min>|<response-time-sec> // Open a new giveaway with new keyword, description, overrides runtime, and overrides responsetime case 4: int parsedResponseTime; if (!Int32.TryParse(openArgs[2], out int parsedRunTime2)) { // Invalid number given, set to disabled open time parsedRunTime2 = 0; } if (!Int32.TryParse(openArgs[3], out parsedResponseTime)) { // Invalid number given, set to disable response time parsedResponseTime = 0; } Open(openArgs[0], openArgs[1], parsedRunTime2, parsedResponseTime); break; } } // Single argument used else if (cmdArgs.Length == 2) { if (cmdArgs[1].Equals("open", StringComparison.InvariantCultureIgnoreCase)) { this.Open(); } else if (cmdArgs[1].Equals("reopen", StringComparison.InvariantCultureIgnoreCase)) { this.Open(true); } else if (cmdArgs[1].Equals("close", StringComparison.InvariantCultureIgnoreCase)) { this.Close(); } else if (cmdArgs[1].Equals("draw", StringComparison.InvariantCultureIgnoreCase)) { this.Draw(); } else if (cmdArgs[1].Equals("redraw", StringComparison.InvariantCultureIgnoreCase)) { this.Draw(true); } else if (cmdArgs[1].Equals("clearwinners", StringComparison.InvariantCultureIgnoreCase)) { this.ClearWinners(); } else if (cmdArgs[1].Equals("stoptimer", StringComparison.InvariantCultureIgnoreCase)) { this.StopOpenResponseTimer(); } } } }