Newer
Older
yuyuko-bot / src / main / scala / listeners / Messages.scala
@Илья Панфёров Илья Панфёров on 15 Jul 851 bytes fix: Update yuyuko
package social.gensokyo.discordbot
package listeners

import ackcord.{ APIMessage, DiscordClient, EventListener, EventsController, TextChannelEventListenerMessage }
import ackcord.requests.{ CreateMessage, CreateMessageData, Requests }
import akka.NotUsed
import constants.YuyukoReplies

class Messages(requests: Requests)(implicit client: DiscordClient) extends EventsController(requests) {
  val onUserMessage: EventListener[APIMessage.MessageCreate, NotUsed] = TextChannelEvent.on[APIMessage.MessageCreate].withRequestOpt { m =>
    m.event.message.content match {
      case text if text.toLowerCase().contains("yuyuko") =>
        YuyukoReplies.getLine.map { line =>
          CreateMessage(m.channel.id, CreateMessageData(
            content = line,
            replyTo = Option(m.event.message.id)))
        }
      case _ => None
    }
  }
}