-
-
Save nvisser/57ea7d75e816615742a812099803b7cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nl.bcome.moo.plugin.kottube | |
import com.google.common.eventbus.Subscribe | |
import com.google.inject.Inject | |
import nl.bcome.moo.conf.Config | |
import nl.bcome.moo.events.EventListener | |
import nl.bcome.moo.events.EventPrivmsg | |
import nl.bcome.moo.irc.Protocol | |
import org.slf4j.Logger | |
@Suppress("UnstableApiUsage") | |
class EventYouTube : EventListener { | |
@Inject | |
lateinit var protocol: Protocol | |
@Inject | |
lateinit var config: Config | |
private val pattern = """(?:you|hook)tu\.?be(?:\.com)?\/(?:watch)?(?:.+[?&]v=|[?&]v=)?([a-zA-Z0-9_-]{6,11})""".toPattern() | |
@Subscribe | |
fun onPrivmsg(evt: EventPrivmsg) { | |
val matcher = pattern.matcher(evt.message) // This is a test http://youtu.be/VtGYIGimhzA What a cool video | |
if (!matcher.find()) return | |
for (i in 1..matcher.groupCount()) { | |
if (matcher.group(i) == null) continue | |
logger.info(matcher.group(i)) // VtGYIGimhzA | |
} | |
} | |
companion object { | |
@Inject | |
lateinit var logger: Logger | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment