private void MessagesListView_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                MessagesContextMenuStrip.Items.Clear();

                ListViewItem item = MessagesListView.GetItemAt(e.X, e.Y);
                if (item != null)
                {
                    OnNotificationArgs message = (OnNotificationArgs)item.Tag;

                    foreach (string url in message.Urls)
                    {
                        ToolStripMenuItem menuItem = new ToolStripMenuItem {
                            Tag   = url,
                            Image = Properties.Resources.BrowserLink_16x,
                            Text  = url.Truncate(50, Truncator.FixedLength, TruncateFrom.Right)
                        };
                        menuItem.Click += DynamicMenuItem_Click;

                        MessagesContextMenuStrip.Items.Add(menuItem);
                    }
                }

                if (MessagesContextMenuStrip.Items.Count > 0)
                {
                    MessagesContextMenuStrip.Show(MessagesListView, e.Location);
                }
            }
        }
        private void UpdateMessage(ListViewItem item)
        {
            OnNotificationArgs message = (OnNotificationArgs)item.Tag;

            item.Text = message.DateTime.Humanize(false);

            if (!message.ContainsUrls)
            {
                double oldSeconds = (DateTime.Now - message.DateTime).TotalSeconds;
                if (oldSeconds <= 15)
                {
                }
                else if (oldSeconds <= 25)
                {
                    item.BackColor = Color.FromArgb(198, 255, 179);
                }
                else if (oldSeconds <= 35)
                {
                    item.BackColor = Color.FromArgb(236, 255, 230);
                }
                else
                {
                    item.BackColor = MessagesListView.BackColor;
                }
            }
        }
        private void NotificationsClient_Notification(object sender, OnNotificationArgs e)
        {
            ListViewItem itemDateTime = new ListViewItem {
                Tag      = e,
                ImageKey = e.Type.GetAttribute <ImageKeyAttribute>().ImageKey,
                UseItemStyleForSubItems = true,
                BackColor = (e.ContainsUrls) ? Color.FromArgb(179, 209, 255) : Color.FromArgb(140, 255, 102),
                Text      = e.DateTime.Humanize(false),
            };

            ListViewItem.ListViewSubItem itemFrom = new ListViewItem.ListViewSubItem {
                Text = e.From
            };
            itemDateTime.SubItems.Add(itemFrom);

            ListViewItem.ListViewSubItem itemMessage = new ListViewItem.ListViewSubItem {
                Text = e.Message
            };
            itemDateTime.SubItems.Add(itemMessage);

            Invoke(new Action(() => {
                MessagesListView.BeginUpdate();

                if (MessagesListView.Items.Count >= SettingsManager.Configuration.Notifications.MaximumNotifications)
                {
                    MessagesListView.Items.RemoveAt(MessagesListView.Items.Count - 1);;
                }

                MessagesListView.Items.Insert(0, itemDateTime);
                MessagesListView.EndUpdate();
            }));
        }
Beispiel #4
0
        private void TwitchClient_OnWhisperReceived(object sender, OnWhisperReceivedArgs e)
        {
            // If sender is allowed
            if (!UserFilter.IsUserAllowed(e.WhisperMessage.Username, e.WhisperMessage.UserType))
            {
                return;
            }

            OnNotificationArgs notificationArgs = new OnNotificationArgs(DateTime.Now, e.WhisperMessage.DisplayName, e.WhisperMessage.Message, NotificationType.Whisper, e.WhisperMessage.Message.GetUrls());

            OnNotification(notificationArgs);
        }
Beispiel #5
0
 protected void OnNotification(OnNotificationArgs e) => Notification?.Invoke(this, e);
Beispiel #6
0
        private void TwitchClient_OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            // If sender is allowed
            if (!UserFilter.IsUserAllowed(e.ChatMessage.Username, e.ChatMessage.UserType))
            {
                return;
            }

            // If message is allowed
            if (!MessageFilter.IsMessageAllowed(e.ChatMessage.Message))
            {
                return;
            }

            // If only show mentions is enabled
            if (SettingsManager.Configuration.Notifications.OnlyShowMentions)
            {
                if (e.ChatMessage.Message.IndexOf($"@{AuthorizedUser.DisplayName}", StringComparison.OrdinalIgnoreCase) < 0)
                {
                    return;
                }
            }

            // If message is a recent duplicate, skip
            if (IsRepeatMessage(e.ChatMessage))
            {
                return;
            }
            SetLastMessage(e.ChatMessage);

            // Store the message and trim it
            string message = e.ChatMessage.Message.Trim();

            // If the message starts with a exclamation point, skip. It is probability a command for a bot
            if (message.StartsWith("!"))
            {
                return;
            }

            // If the message starts with a colon, remove the colon. It is from /me
            if (message.StartsWith(":"))
            {
                message = message.Remove(0, 1).Trim();
            }

            // Remove all channel emotes
            message = string.Join(" ", message.Split(' ').Except(e.ChatMessage.EmoteSet.Emotes.Select(x => x.Name).ToArray()));

            // Remove all BetterTTV emotes
            message = string.Join(" ", message.Split(' ').Except(_BetterTTVEmotes));

            // Remove all FrankerFaceZ emotes
            message = string.Join(" ", message.Split(' ').Except(_FrankerFaceZEmotes));

            // If message is empty, skip
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            OnNotificationArgs notificationArgs = new OnNotificationArgs(DateTime.Now, e.ChatMessage.DisplayName, message, GetNotificationType(e.ChatMessage.UserType), message.GetUrls());

            OnNotification(notificationArgs);
        }