Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 9596d25

Browse files
committed
Add a method to the TwitchChatInput to ignore messages from the same account
1 parent 2c0ed9b commit 9596d25

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/scala/org/codeoverflow/chatoverflow/requirement/service/twitch/chat/impl/TwitchChatInputImpl.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon
3030
private val emoticonRegex = """(\d+)-(\d+)""".r
3131

3232
private var currentChannel: Option[String] = None
33+
private var ignoreOwnMessages = false
3334

3435
private val onMessageFn = onMessage _
3536
private val onUnknownFn = onUnknown _
@@ -41,7 +42,9 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon
4142
}
4243

4344
private def onMessage(event: MessageEvent): Unit = {
44-
if (currentChannel.isDefined && event.getChannelSource == currentChannel.get) {
45+
if (currentChannel.isDefined && event.getChannelSource == currentChannel.get
46+
&& (!ignoreOwnMessages || event.getUser.getNick.toLowerCase != getUsername)) {
47+
4548
val message = event.getMessage
4649
val color = if (event.getV3Tags.get("color").contains("#")) event.getV3Tags.get("color") else ""
4750
val subscriber = event.getV3Tags.get("subscriber") == "1"
@@ -105,6 +108,8 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon
105108

106109
override def getUsername: String = sourceConnector.get.getUsername
107110

111+
override def ignoreOwnMessages(ignore: Boolean): Unit = this.ignoreOwnMessages = ignore
112+
108113
/**
109114
* Stops the input, called before source connector will shutdown
110115
*

0 commit comments

Comments
 (0)