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

Add a method to the Twitch chat to get the username and ignore own messages #106

Merged
merged 2 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TwitchChatConnectListener(fn: (Boolean, String) => Unit) extends ListenerA
override def onEvent(event: Event): Unit = {
event match {
case _: ConnectEvent => fn(true, "")
case e: ConnectAttemptFailedEvent => fn(false, "couldn't connect to irc chat server")
case _: ConnectAttemptFailedEvent => fn(false, "couldn't connect to irc chat server")
case e: NoticeEvent =>
if (e.getNotice.contains("authentication failed")) {
fn(false, "authentication failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class TwitchChatConnector(override val sourceIdentifier: String) extends Connect

def isJoined(channel: String): Boolean = channels.contains(channel)

def getUsername: String = bot.getNick

private def getConfig: Configuration = {

if (credentials.isDefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon
private val emoticonRegex = """(\d+)-(\d+)""".r

private var currentChannel: Option[String] = None
private var ignoreOwnMessages = false

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

private def onMessage(event: MessageEvent): Unit = {
if (currentChannel.isDefined && event.getChannelSource == currentChannel.get) {
if (currentChannel.isDefined && event.getChannelSource == currentChannel.get
&& (!ignoreOwnMessages || event.getUser.getNick.toLowerCase != getUsername)) {

val message = event.getMessage
val color = if (event.getV3Tags.get("color").contains("#")) event.getV3Tags.get("color") else ""
val subscriber = event.getV3Tags.get("subscriber") == "1"
Expand Down Expand Up @@ -103,6 +106,10 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon
if (!sourceConnector.get.isJoined(currentChannel.get)) sourceConnector.get.joinChannel(currentChannel.get)
}

override def getUsername: String = sourceConnector.get.getUsername

override def ignoreOwnMessages(ignore: Boolean): Unit = this.ignoreOwnMessages = ignore

/**
* Stops the input, called before source connector will shutdown
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class TwitchChatOutputImpl extends OutputImpl[chat.TwitchChatConnector] with Twi
if (!sourceConnector.get.isJoined(currentChannel.get)) sourceConnector.get.joinChannel(currentChannel.get)
}

override def getUsername: String = sourceConnector.get.getUsername

/**
* Stops the output, called before source connector will shutdown
*
Expand Down