Ver código fonte

Made plugins able to access rollbot instance

Kirk Trombley 6 anos atrás
pai
commit
34e8c17e77
3 arquivos alterados com 12 adições e 11 exclusões
  1. 4 3
      src/command_system.py
  2. 6 6
      src/plugins/teamspeak.py
  3. 2 2
      src/rollbot.py

+ 4 - 3
src/command_system.py

@@ -116,8 +116,9 @@ class RollbotResponse:
 
 
 class RollbotPlugin:
-    def __init__(self, command, logger=logging.getLogger(__name__)):
+    def __init__(self, command, bot, logger=logging.getLogger(__name__)):
         self.command = command
+        self.bot = bot
         self.logger = logger
         self.logger.info(f"Intializing {type(self).__name__} matching {command}")
 
@@ -138,8 +139,8 @@ def as_plugin(command):
     else:
         command_name = command.__name__
 
-    def init_standin(self, logger=logging.getLogger(__name__)):
-        RollbotPlugin.__init__(self, command_name, logger)
+    def init_standin(self, bot, logger=logging.getLogger(__name__)):
+        RollbotPlugin.__init__(self, command_name, bot, logger=logger)
 
     def decorator(fn):
         return type(

+ 6 - 6
src/plugins/teamspeak.py

@@ -11,8 +11,8 @@ TS3_LOGIN = ("login %s %s\n" % (_TS3_USER, _TS3_PASS)).encode("utf-8")
 
 
 class teamspeak(RollbotPlugin):
-    def __init__(self, logger=logging.getLogger(__name__)):
-        RollbotPlugin.__init__(self, "teamspeak", logger)
+    def __init__(self, bot, logger=logging.getLogger(__name__)):
+        RollbotPlugin.__init__(self, "teamspeak", bot, logger=logger)
 
     def on_command(self, db, message):
         try:
@@ -52,8 +52,8 @@ class teamspeak(RollbotPlugin):
 
 
 class speamteek(teamspeak):
-    def __init__(self, logger=logging.getLogger(__name__)):
-        RollbotPlugin.__init__(self, "speamteek", logger)
+    def __init__(self, bot, logger=logging.getLogger(__name__)):
+        RollbotPlugin.__init__(self, "speamteek", bot, logger=logger)
 
     def on_command(self, db, message):
         r = super().on_command(db, message)
@@ -63,8 +63,8 @@ class speamteek(teamspeak):
 
 
 class teamscream(teamspeak):
-    def __init__(self, logger=logging.getLogger(__name__)):
-        RollbotPlugin.__init__(self, "teamscream", logger)
+    def __init__(self, bot, logger=logging.getLogger(__name__)):
+        RollbotPlugin.__init__(self, "teamscream", bot, logger=logger)
 
     def on_command(self, db, message):
         r = super().on_command(db, message)

+ 2 - 2
src/rollbot.py

@@ -22,7 +22,7 @@ class Rollbot:
 
         self.logger.info("Loading command plugins")
         for plugin_class in plugin_classes:
-            plugin_instance = plugin_class(logger=logger)
+            plugin_instance = plugin_class(self, logger=logger)
             if plugin_instance.command in self.commands:
                 self.logger.error(f"Duplicate command word '{plugin_instance.command}'")
                 raise ValueError(f"Duplicate command word '{plugin_instance.command}'")
@@ -38,7 +38,7 @@ class Rollbot:
             if cmd in self.commands:
                 self.logger.error(f"Duplicate command word '{cmd}'")
                 raise ValueError(f"Duplicate command word '{cmd}'")
-            self.commands[cmd] = lift_response(cmd, response)(logger=logger)
+            self.commands[cmd] = lift_response(cmd, response)(self, logger=logger)
         self.logger.info(f"Finished loading simple responses, {len(self.commands)} total commands available")
 
         self.logger.info("Loading aliases")