/// <summary> /// Handles banning users that user non-ascii characters. /// </summary> /// <param name="config">The configuration for the twitch chat.</param> /// <param name="client">The twitch client.</param> /// <param name="messageInfo">The information on the chat message.</param> /// <returns>True if the message should be passed on, false if it should be discarded.</returns> public bool Handle(TwitchChatConfiguration config, TwitchClient client, OnMessageReceivedArgs messageInfo) { string chatMessage = messageInfo.ChatMessage.Message; // First convert each character into their hex-sequence representation in Unicode. This will catch both // characters outside of the ASCII character set (> 127) and non-emojis. We only allow ASCII characters // and emojis. var convertedMessageCharacters = UnicodeUtilities.ConvertToUnicodeNumber(chatMessage); foreach (var character in convertedMessageCharacters) { // If there is no space, then just evaluate the single character. if (!character.Contains(" ")) { var num = int.Parse(character, NumberStyles.HexNumber); if (num > 127 && !UnicodeUtilities.IsEmoji(character)) { return(false); } continue; } // If there is a space, it can only possibly be an emoji to be valid. if (!UnicodeUtilities.IsEmoji(character)) { return(false); } } return(true); }
/// <summary> /// Handles banning the "Wanna become famous" bot message. /// </summary> /// <param name="config">The configuration for the twitch chat.</param> /// <param name="client">The twitch client.</param> /// <param name="messageInfo">The information on the chat message.</param> /// <returns>True if the message should be passed on, false if it should be discarded.</returns> public bool Handle(TwitchChatConfiguration config, TwitchClient client, OnMessageReceivedArgs messageInfo) { if (string.IsNullOrWhiteSpace(config.AccountUsername) || string.IsNullOrWhiteSpace(config.TwitchChannel)) { return(true); } string chatMessage = messageInfo.ChatMessage.Message; if ( ( chatMessage.Contains("Wanna become famous?", StringComparison.InvariantCultureIgnoreCase) || chatMessage.Contains("Want to become famous?", StringComparison.InvariantCultureIgnoreCase) ) && ( Regex.IsMatch(chatMessage, Constants.REGEX_URL) || chatMessage.Contains("Buy", StringComparison.InvariantCultureIgnoreCase) && chatMessage.Contains("followers", StringComparison.InvariantCultureIgnoreCase) && chatMessage.Contains("viewers", StringComparison.InvariantCultureIgnoreCase) )) { return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="AdminFiltersViewModel" /> class. /// </summary> /// <param name="config">The twitch configuration.</param> public AdminFiltersViewModel(TwitchChatConfiguration config) : this() { this.config = config; this.title = $"Admin Filters: {config.TwitchChannel}"; this.LookupBotsInFollowerListUser = this.config.TwitchChannel; this.PropertyChanged += this.OnPropertyChanged; }
/// <summary> /// Initializes a new instance of the <see cref="TwitchChatConfigViewModel" /> class. /// </summary> /// <param name="config">The twitch chat configuration to base the row on.</param> public TwitchChatConfigViewModel(TwitchChatConfiguration config) : this() { this.PropertyChanged -= this.OnPropertyChanged; this.chatConfig = config; this.CopyFromConfig(config); this.PropertyChanged += this.OnPropertyChanged; }
/// <summary> /// Initializes a new instance of the <see cref="AdminFiltersViewModel" /> class. /// </summary> public AdminFiltersViewModel() { // This is for the designer. this.config = new TwitchChatConfiguration(); this.title = "Admin Filters"; }