Skip to content

Instantly share code, notes, and snippets.

@nvisser
Created April 16, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvisser/57ea7d75e816615742a812099803b7cc to your computer and use it in GitHub Desktop.
Save nvisser/57ea7d75e816615742a812099803b7cc to your computer and use it in GitHub Desktop.
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