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

Commit 42f253e

Browse files
committed
Fix twitch channel auto-formatting
Prefixes twitch channels with a #, if missing and lowercases them as required for the twitch IRC chat.
1 parent ac09a8c commit 42f253e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,27 @@ class TwitchChatConnector(override val sourceIdentifier: String) extends Connect
3030
}
3131

3232
def joinChannel(channel: String): Unit = {
33-
bot.send().joinChannel(channel)
34-
channels += channel
33+
val formattedChan = formatChannel(channel)
34+
bot.send().joinChannel(formattedChan)
35+
channels += formattedChan
3536
}
3637

3738
def sendChatMessage(channel: String, chatMessage: String): Unit = {
38-
if (!isJoined(channel)) throw new IllegalArgumentException(s"you must join the '$channel' channel, before you can send messages to it")
39-
bot.send().message(channel, chatMessage)
39+
val formattedChan = formatChannel(channel)
40+
if (!isJoined(formattedChan)) throw new IllegalArgumentException(s"you must join the '$channel' channel, before you can send messages to it")
41+
bot.send().message(formattedChan, chatMessage)
4042
}
4143

4244
override def getUniqueTypeString: String = this.getClass.getName
4345

44-
def isJoined(channel: String): Boolean = channels.contains(channel)
46+
def isJoined(channel: String): Boolean = channels.contains(formatChannel(channel))
47+
48+
/**
49+
* Ensures that the channel is in following format: "#lowercasename"
50+
* @param chan the unmodified channel
51+
* @return the channel in the correct format, changes nothing if already correct
52+
*/
53+
private def formatChannel(chan: String): String = s"#${chan.stripPrefix("#").toLowerCase}"
4554

4655
private def getConfig: Configuration = {
4756

0 commit comments

Comments
 (0)