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

Commit

Permalink
Merge pull request #90 from daniel0611/fix/89-handler-called-twice
Browse files Browse the repository at this point in the history
Pass functions to register method from inputs instead of methods
  • Loading branch information
J0B10 committed Jul 13, 2019
2 parents 4de98d7 + 3039885 commit 70956ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Expand Up @@ -12,8 +12,10 @@ import org.codeoverflow.chatoverflow.requirement.service.serial.SerialConnector
@Impl(impl = classOf[SerialInput], connector = classOf[SerialConnector])
class SerialInputImpl extends EventInputImpl[SerialEvent, SerialConnector] with SerialInput with WithLogger {

private val onInputFn = onInput _

override def start(): Boolean = {
sourceConnector.get.addInputListener(onInput)
sourceConnector.get.addInputListener(onInputFn)
true
}

Expand All @@ -27,7 +29,7 @@ class SerialInputImpl extends EventInputImpl[SerialEvent, SerialConnector] with
* @return true if stopping was successful
*/
override def stop(): Boolean = {
sourceConnector.get.removeInputListener(onInput)
sourceConnector.get.removeInputListener(onInputFn)
true
}
}
Expand Up @@ -19,10 +19,14 @@ class TipeestreamEventInputImpl extends EventInputImpl[TipeeestreamEvent, Tipeee
private val DATE_FORMATTER = new DateTimeFormatterBuilder()
.parseCaseInsensitive().append(DateTimeFormatter.ISO_LOCAL_DATE_TIME).appendOffset("+HHMM", "Z").toFormatter

private val onFollowFn = onFollow _
private val onSubscriptionFn = onSubscription _
private val onDonationFn = onDonation _

override def start(): Boolean = {
sourceConnector.get.addFollowEventListener(onFollow)
sourceConnector.get.addSubscriptionEventListener(onSubscription)
sourceConnector.get.addDonationEventListener(onDonation)
sourceConnector.get.addFollowEventListener(onFollowFn)
sourceConnector.get.addSubscriptionEventListener(onSubscriptionFn)
sourceConnector.get.addDonationEventListener(onDonationFn)
true
}

Expand Down Expand Up @@ -84,9 +88,9 @@ class TipeestreamEventInputImpl extends EventInputImpl[TipeeestreamEvent, Tipeee
}

override def stop(): Boolean = {
sourceConnector.get.removeFollowEventListener(onFollow)
sourceConnector.get.removeSubscriptionEventListener(onSubscription)
sourceConnector.get.removeDonationEventListener(onDonation)
sourceConnector.get.removeFollowEventListener(onFollowFn)
sourceConnector.get.removeSubscriptionEventListener(onSubscriptionFn)
sourceConnector.get.removeDonationEventListener(onDonationFn)
true
}
}
Expand Up @@ -9,7 +9,7 @@ import org.codeoverflow.chatoverflow.api.io.dto.chat.{ChatEmoticon, TextChannel}
import org.codeoverflow.chatoverflow.api.io.event.chat.twitch.{TwitchChatMessageReceiveEvent, TwitchEvent, TwitchPrivateChatMessageReceiveEvent}
import org.codeoverflow.chatoverflow.api.io.input.chat._
import org.codeoverflow.chatoverflow.registry.Impl
import org.codeoverflow.chatoverflow.requirement.impl.{EventInputImpl, InputImpl}
import org.codeoverflow.chatoverflow.requirement.impl.EventInputImpl
import org.codeoverflow.chatoverflow.requirement.service.twitch.chat
import org.codeoverflow.chatoverflow.requirement.service.twitch.chat.TwitchChatConnector
import org.pircbotx.hooks.events.{MessageEvent, UnknownEvent}
Expand All @@ -31,9 +31,12 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon

private var currentChannel: Option[String] = None

private val onMessageFn = onMessage _
private val onUnknownFn = onUnknown _

override def start(): Boolean = {
sourceConnector.get.addMessageEventListener(onMessage)
sourceConnector.get.addUnknownEventListener(onUnknown)
sourceConnector.get.addMessageEventListener(onMessageFn)
sourceConnector.get.addUnknownEventListener(onUnknownFn)
true
}

Expand Down Expand Up @@ -105,8 +108,8 @@ class TwitchChatInputImpl extends EventInputImpl[TwitchEvent, chat.TwitchChatCon
* @return true if stopping was successful
*/
override def stop(): Boolean = {
sourceConnector.get.removeMessageEventListener(onMessage)
sourceConnector.get.removeUnknownEventListener(onUnknown)
sourceConnector.get.removeMessageEventListener(onMessageFn)
sourceConnector.get.removeUnknownEventListener(onUnknownFn)
true
}
}

0 comments on commit 70956ce

Please sign in to comment.