Add PluginManager

This commit is contained in:
CapacitorSet 2019-07-07 13:10:48 +02:00
parent c82e325d28
commit 5e90a873b0
2 changed files with 21 additions and 1 deletions

View file

@ -51,7 +51,7 @@ class Bot(val token: String) extends TelegramBot
} { _ => false }
}
var plugins: List[Plugin] = List[Plugin]()
var plugins: List[Plugin] = List[Plugin](new PluginManagerPlugin(localizer, this))
def runAgainst(handlerPair: Plugin#HandlerPair, botUser: Option[User], cmd: Command): Boolean = {
handlerPair._1

View file

@ -0,0 +1,20 @@
package org.congressodeiradicali.karlmarx
import com.bot4s.telegram.api.declarative.{CommandFilterMagnet, CommandImplicits}
import scala.concurrent.{ExecutionContext, Future}
class PluginManagerPlugin(localizer: Localizer, bot: Bot) extends Plugin with CommandImplicits {
override var handlers: Map[CommandFilterMagnet, Handler] = Map {
stringToCommandFilter("enable") -> { msg =>
val response = msg.text.map {
case "echo" => Some(new EchoPlugin(localizer, bot))
case "ban" => Some(new BanPlugin(localizer, bot))
case _ => None
}.map {
case Some(plugin) => bot.plugins :+= plugin; "Added."
}
Future { response }(ExecutionContext.global)
}
}
}