From e1af52377ce183e9b96c6ad94839d5b6e3c2da45 Mon Sep 17 00:00:00 2001 From: ekardnam Date: Sat, 20 Jul 2019 08:12:16 +0200 Subject: [PATCH] Plugin manager plugin listing --- .../coreplugins/PluginManagerPlugin.scala | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/scala/org/congressodeiradicali/karlmarx/coreplugins/PluginManagerPlugin.scala b/src/main/scala/org/congressodeiradicali/karlmarx/coreplugins/PluginManagerPlugin.scala index 8252794..63c0e52 100644 --- a/src/main/scala/org/congressodeiradicali/karlmarx/coreplugins/PluginManagerPlugin.scala +++ b/src/main/scala/org/congressodeiradicali/karlmarx/coreplugins/PluginManagerPlugin.scala @@ -19,7 +19,7 @@ package org.congressodeiradicali.karlmarx.coreplugins import com.bot4s.telegram.api.declarative.{CommandFilterMagnet, CommandImplicits} import com.bot4s.telegram.models.Message -import org.congressodeiradicali.karlmarx.{Bot, LocalizableString} +import org.congressodeiradicali.karlmarx.{Bot, LocalizableString, Plugin} import scala.concurrent.{ExecutionContext, Future} @@ -28,6 +28,8 @@ class PluginManagerPlugin(bot: Bot) extends CorePlugin with CommandImplicits { // Todo: disable it when reasonable enabled = true + private implicit val ec: ExecutionContext = ExecutionContext.global + override val name = "Plugin Manager" override val description = "Manages other plugins" @@ -53,7 +55,7 @@ class PluginManagerPlugin(bot: Bot) extends CorePlugin with CommandImplicits { else LocalizableString.NO_SUCH_PLUGIN - Future { Some(bot.localize(response)) }(ExecutionContext.global) + Future { Some(bot.localize(response)) } }, stringToCommandFilter("disable") -> { (_: Message, argv: Array[String]) => @@ -63,13 +65,26 @@ class PluginManagerPlugin(bot: Bot) extends CorePlugin with CommandImplicits { else LocalizableString.NO_SUCH_PLUGIN - Future { Some(bot.localize(response)) }(ExecutionContext.global) + Future { Some(bot.localize(response)) } + }, + + stringToCommandFilter("listplugins") -> { (_, _) => + Future { + Some( + bot.plugins.values.map { plugin => + s"${plugin.identifier}: ${plugin.name}. ${plugin.description}. License: ${plugin.license}. Author: ${plugin.author}" + }.mkString("\n") + ) + } + }, + + stringToCommandFilter("listenabled") -> { (_, _) => + Future { + Some( + bot.plugins.values.filter(_.enabled).map(_.identifier).mkString("\n") + ) + } }, - /* - stringToCommandFilter("plugins") -> { (_: Message, _: Array[String]) => - Future { Some(bot.plugins.values.map("- " + _.name).mkString("\n")) }(ExecutionContext.global) - } - */ ) override var messageHandlers: List[MessageHandler] = List() }