/// <summary> /// Processes the received text packet. /// </summary> /// <param name="packetMessage">The receive text packet</param> /// <returns>An awaitable task</returns> protected override Task ProcessReceivedPacket(string packetMessage) { if (!string.IsNullOrEmpty(packetMessage)) { ClientResponsePacketModel packet = new ClientResponsePacketModel(packetMessage); if (packet.IsReplyEvent) { if (this.replyIDListeners.ContainsKey(packet.NormalRef)) { this.replyIDListeners[packet.NormalRef] = packet; } } if (this.chatSubscriptions.Contains(packet.Topic)) { ChatMessagePacketModel message = new ChatMessagePacketModel(packetMessage); this.OnChatMessageReceived?.Invoke(this, message); } else if (this.channelSubscriptions.Contains(packet.Topic)) { ChannelUpdatePacketModel channelUpdate = new ChannelUpdatePacketModel(packetMessage); this.OnChannelUpdated?.Invoke(this, channelUpdate); } else if (this.followSubscriptions.Contains(packet.Topic)) { FollowPacketModel follow = new FollowPacketModel(packetMessage); this.OnFollowOccurred?.Invoke(this, follow); } } return(Task.FromResult(0)); }
public TwitchChatMessageViewModel(ChatMessagePacketModel message, UserViewModel user) : base(message.ID, StreamingPlatformTypeEnum.Twitch, user) { this.User.SetTwitchChatDetails(message); foreach (var kvp in message.EmotesDictionary) { if (!messageEmotesHashSet.Contains(kvp.Key) && kvp.Value.Count > 0) { long emoteID = kvp.Key; Tuple <int, int> instance = kvp.Value.FirstOrDefault(); if (0 <= instance.Item1 && instance.Item1 < message.Message.Length && 0 <= instance.Item2 && instance.Item2 < message.Message.Length) { string emoteCode = message.Message.Substring(instance.Item1, instance.Item2 - instance.Item1 + 1); messageEmotesCache[emoteCode] = new TwitchChatEmoteViewModel(emoteID.ToString(), emoteCode); messageEmotesHashSet.Add(kvp.Key); } } } this.HasBits = (int.TryParse(message.Bits, out int bits) && bits > 0); this.IsHighlightedMessage = message.RawPacket.Tags.ContainsKey(TagMessageID) && message.RawPacket.Tags[TagMessageID].Equals(MessageIDHighlightedMessage); if (message.Message.StartsWith(SlashMeAction) && message.Message.Last() == SOHCharacter) { this.IsSlashMe = true; string text = message.Message.Replace(SlashMeAction, string.Empty); this.ProcessMessageContents(text.Substring(0, text.Length - 1)); } else { this.ProcessMessageContents(message.Message); } }
private async void UserClient_OnMessageReceived(object sender, ChatMessagePacketModel message) { if (message != null && !string.IsNullOrEmpty(message.Message)) { if (!string.IsNullOrEmpty(message.UserLogin) && message.UserLogin.Equals("jtv")) { if (Regex.IsMatch(message.Message, TwitchChatService.HostChatMessageRegexPattern)) { Logger.Log(LogLevel.Debug, JSONSerializerHelper.SerializeToString(message)); string hoster = message.Message.Substring(0, message.Message.IndexOf(' ')); UserViewModel user = ChannelSession.Services.User.GetUserByUsername(hoster, StreamingPlatformTypeEnum.Twitch); if (user == null) { UserModel twitchUser = await ChannelSession.TwitchUserConnection.GetNewAPIUserByLogin(hoster); if (twitchUser != null) { user = await ChannelSession.Services.User.AddOrUpdateUser(twitchUser); } } if (user != null) { EventTrigger trigger = new EventTrigger(EventTypeEnum.TwitchChannelHosted, user); if (ChannelSession.Services.Events.CanPerformEvent(trigger)) { foreach (CurrencyModel currency in ChannelSession.Settings.Currency.Values.ToList()) { currency.AddAmount(user.Data, currency.OnHostBonus); } GlobalEvents.HostOccurred(user); await ChannelSession.Services.Events.PerformEvent(trigger); await ChannelSession.Services.Alerts.AddAlert(new AlertChatMessageViewModel(StreamingPlatformTypeEnum.Twitch, user, string.Format("{0} hosted the channel", user.Username), ChannelSession.Settings.AlertHostColor)); } } } } else { UserViewModel user = ChannelSession.Services.User.GetUserByTwitchID(message.UserID); if (user == null) { UserModel twitchUser = await ChannelSession.TwitchUserConnection.GetNewAPIUserByLogin(message.UserLogin); if (twitchUser != null) { user = await ChannelSession.Services.User.AddOrUpdateUser(twitchUser); } } this.OnMessageOccurred(this, new TwitchChatMessageViewModel(message, user)); } } }
public UserViewModel(ChatMessagePacketModel twitchMessage) { this.SetUserData(twitchID: twitchMessage.UserID); this.TwitchID = twitchMessage.UserID; this.TwitchUsername = twitchMessage.UserLogin; this.TwitchDisplayName = (!string.IsNullOrEmpty(twitchMessage.UserDisplayName)) ? twitchMessage.UserDisplayName : this.TwitchUsername; this.SetTwitchRoles(); }
public static async Task <UserViewModel> Create(ChatMessagePacketModel twitchMessage) { UserViewModel user = await UserViewModel.Create(StreamingPlatformTypeEnum.Twitch, twitchMessage.UserID); user.TwitchID = twitchMessage.UserID; user.TwitchUsername = twitchMessage.UserLogin; user.TwitchDisplayName = (!string.IsNullOrEmpty(twitchMessage.UserDisplayName)) ? twitchMessage.UserDisplayName : user.TwitchUsername; user.SetTwitchRoles(); user.SetTwitchChatDetails(twitchMessage); ChannelSession.Settings.SetUserData(user.Data); return(user); }
private async void UserClient_OnMessageReceived(object sender, ChatMessagePacketModel message) { if (message != null && !string.IsNullOrEmpty(message.Message)) { if (!string.IsNullOrEmpty(message.UserLogin) && message.UserLogin.Equals("jtv")) { if (Regex.IsMatch(message.Message, TwitchChatService.HostChatMessageRegexPattern)) { Logger.Log(LogLevel.Debug, JSONSerializerHelper.SerializeToString(message)); string hosterUsername = message.Message.Substring(0, message.Message.IndexOf(' ')); UserViewModel user = await ChannelSession.Services.User.GetUserFullSearch(StreamingPlatformTypeEnum.Twitch, userID : null, hosterUsername); if (user != null) { await ChannelSession.Services.User.AddOrUpdateActiveUser(user); CommandParametersModel parameters = new CommandParametersModel(user); if (ChannelSession.Services.Events.CanPerformEvent(EventTypeEnum.TwitchChannelHosted, parameters)) { foreach (CurrencyModel currency in ChannelSession.Settings.Currency.Values.ToList()) { currency.AddAmount(user.Data, currency.OnHostBonus); } GlobalEvents.HostOccurred(user); await ChannelSession.Services.Events.PerformEvent(EventTypeEnum.TwitchChannelHosted, parameters); await ChannelSession.Services.Alerts.AddAlert(new AlertChatMessageViewModel(StreamingPlatformTypeEnum.Twitch, user, string.Format("{0} hosted the channel", user.FullDisplayName), ChannelSession.Settings.AlertHostColor)); } } } } else { UserViewModel user = await ChannelSession.Services.User.GetUserFullSearch(StreamingPlatformTypeEnum.Twitch, message.UserID, message.UserLogin); this.OnMessageOccurred(this, new TwitchChatMessageViewModel(message, user)); } } }
public void SetTwitchChatDetails(ChatMessagePacketModel message) { this.SetTwitchChatDetails(message.UserDisplayName, message.BadgeDictionary, message.BadgeInfoDictionary, message.Color); }
private static void Chat_OnMessageReceived(object sender, ChatMessagePacketModel packet) { System.Console.WriteLine(string.Format("{0}: {1}", packet.UserDisplayName, packet.Message)); }
private static void Client_OnChatMessageReceived(object sender, ChatMessagePacketModel message) { System.Console.WriteLine(string.Format("{0}: {1}", message.User?.displayname, message.Message)); }