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

Pass functions to register method from inputs instead of methods #90

Merged
merged 1 commit into from
Jul 13, 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 @@ -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
}
}
Original file line number Diff line number Diff line change
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
}
}
Original file line number Diff line number Diff line change
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
}
}