Browse Source

Revert "Merge branch 'feature/dynamic-plugin' of kirkleon/rollbot3 into master"

This reverts commit 0a13d79099ee432c77db9915afd39cb7965ab608, reversing
changes made to 27c3d441f20d8425177443a39b3399354a281f0a.
Kirk Trombley 6 years ago
parent
commit
7248066e73
9 changed files with 108 additions and 111 deletions
  1. 4 74
      config/config.toml
  2. 1 0
      src/app.py
  3. 3 1
      src/plugins/__init__.py
  4. 0 35
      src/plugins/dynamic.py
  5. 16 0
      src/plugins/meme.py
  6. 10 0
      src/plugins/simple.py
  7. 19 0
      src/plugins/the_guy.py
  8. 39 0
      src/plugins/the_house.py
  9. 16 1
      src/rollbot.py

+ 4 - 74
config/config.toml

@@ -9,11 +9,12 @@ horoscope = "inspire"
 lomg = "bump"
 mute = "bump"
 
-[dynamic.simple_responses]
+[responses]
 info = """
 Hello!
 I am Rollbot 3.0 - a simple chatbot built in Python.
-I am licensed as open source under the MIT license."""
+I am licensed as open source under the MIT license.
+"""
 thanks = "You're welcome!"
 guess = "Rollbot's back - tell a friend!"
 unmeme = "get a job"
@@ -22,78 +23,7 @@ bump = "Bumping the chat!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\
 vore = "What? No"
 break = "I'm too robust for that!"
 yiff = "Sorry - I don't think I understand the command '!yiff'... I'll talk to Ivan and get back to you!"
-f = """
-FFFFFFFFFFFFFFFFFFFFF
-FFFFFFFFFFFFFFFFFFFFF
-FFFFFFFFFFFFFFFFFFFFF
-FFFFFFF
-FFFFFFF
-FFFFFFF
-FFFFFFFFFFFFFF
-FFFFFFFFFFFFFF
-FFFFFFFFFFFFFF
-FFFFFFF
-FFFFFFF
-FFFFFFF
-FFFFFFF
-FFFFFFF"""
-hey = """
-🖕     😎
-🐛💤👔🐛
-        ⛽  👢
-       ⚡8=👊=D💦
-   🎸     🌽
-👢           👢"""
-
-[dynamic.echo_responses]
-echo = "'{}'"
-appreciate = """
-┏┓
-┃┃╱╲ In this
-┃╱╱╲╲ house
-╱╱╭╮╲╲ we love
-▔▏┗┛▕▔ & appreciate
-╱▔▔▔▔▔▔▔▔▔▔╲
-{}
-╱╱┏┳┓╭╮┏┳┓ ╲╲
-▔▏┗┻┛┃┃┗┻┛▕▔"""
-stfu = """
-┏┓
-┃┃╱╲ Shut
-┃╱╱╲╲ The
-╱╱╭╮╲╲ Fuck
-▔▏┗┛▕▔ Up
-╱▔▔▔▔▔▔▔▔▔▔╲
-{}
-╱╱┏┳┓╭╮┏┳┓ ╲╲
-▔▏┗┻┛┃┃┗┻┛▕▔"""
-
-[dynamic.choice_responses]
-
-    [[dynamic.choice_responses.greet]]
-    value = "Hi!"
-
-    [[dynamic.choice_responses.greet]]
-    value = "Hello!"
-
-    [[dynamic.choice_responses.greet]]
-    value = "안녕하세요"
-
-    [[dynamic.choice_responses.greet]]
-    value = "こんにちは"
-
-    [[dynamic.choice_responses.greet]]
-    value = "你好"
-
-    [[dynamic.choice_responses.greet]]
-    value = "👋"
-
-    [[dynamic.choice_responses.meme]]
-    value = "fuck off"
-    weight = 19
-
-    [[dynamic.choice_responses.meme]]
-    value = "I love you"
+f = "FFFFFFFFFFFFFFFFFFFFF\nFFFFFFFFFFFFFFFFFFFFF\nFFFFFFFFFFFFFFFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFFFFFFFFF\nFFFFFFFFFFFFFF\nFFFFFFFFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF\nFFFFFFF"
 
 [teamspeak]
 host = "kirkleon.ddns.net"

+ 1 - 0
src/app.py

@@ -36,6 +36,7 @@ rollbot = Rollbot(
     logger=app.logger,
     plugin_classes=find_all_subclasses(RollbotPlugin),
     aliases=get_config("aliases"),
+    responses=get_config("responses"),
     lookup=BOTS_LOOKUP,
     sleep_time=float(get_config("sleep_time")),
     callback=post_message,

+ 3 - 1
src/plugins/__init__.py

@@ -1,8 +1,10 @@
 import plugins.roll
 import plugins.querying
 import plugins.seychelles
+import plugins.the_guy
 import plugins.session
 import plugins.simple
 import plugins.curse
 import plugins.teamspeak
-import plugins.dynamic
+import plugins.the_house
+import plugins.meme

+ 0 - 35
src/plugins/dynamic.py

@@ -1,35 +0,0 @@
-import random
-
-from config import get_config
-from command_system import as_plugin, RollbotResponse
-
-
-def lift_simple_response(call, response):
-    @as_plugin(call)
-    def response_func(db, msg):
-        return RollbotResponse(msg, txt=response)
-
-
-def lift_echo_response(call, response):
-    @as_plugin(call)
-    def response_func(db, msg):
-        return RollbotResponse(msg, txt=response.format(msg.raw_args or ""))
-
-
-def lift_choice_response(call, options):
-    @as_plugin(call)
-    def response_func(db, msg):
-        return RollbotResponse(msg, txt=random.choice(options))
-
-
-dynamic = get_config("dynamic")
-
-for cmd, response in dynamic["simple_responses"].items():
-    lift_simple_response(cmd, response)
-
-for cmd, response in dynamic["echo_responses"].items():
-    lift_echo_response(cmd, response)
-
-for cmd, options in dynamic["choice_responses"].items():
-    opts = [y for x in ([o["value"]] * o.get("weight", 1) for o in options) for y in x]
-    lift_choice_response(cmd, opts)

+ 16 - 0
src/plugins/meme.py

@@ -0,0 +1,16 @@
+import random
+
+from command_system import as_plugin, RollbotResponse
+
+@as_plugin
+def meme(db, message):
+
+        diceroll = random.randint(1,20)
+        good = "I love you."
+        bad = "fuck off"
+
+        if diceroll == 20:
+            return RollbotResponse(message, txt=good)
+
+        else:
+            return RollbotResponse(message, txt=bad)

+ 10 - 0
src/plugins/simple.py

@@ -13,6 +13,16 @@ def debug(db, message):
     return RollbotResponse(message, txt=str(message))
 
 
+@as_plugin
+def echo(db, message):
+    return RollbotResponse(message, txt="'%s' - %s" % (message.raw_args, message.name))
+
+
+@as_plugin
+def greet(db, message):
+    return RollbotResponse(message, txt=random.choice(("Hi!", "Hello!", "안녕하세요", "こんにちは", "你好", "👋")))
+
+
 @as_plugin
 def console(db, message):
     argstr = message.raw_args

+ 19 - 0
src/plugins/the_guy.py

@@ -0,0 +1,19 @@
+from command_system import RollbotResponse, RollbotFailure, as_plugin
+
+
+THE_GUY = """\
+🖕     😎
+🐛💤👔🐛
+        ⛽  👢
+       ⚡8=👊=D💦
+   🎸     🌽
+👢           👢
+"""
+
+
+@as_plugin("hey")
+def the_guy(db, msg):
+    for x, y in zip(msg.args(), ("can", "i", "have", "the", "guy")):
+        if x.lower() != y:
+            return RollbotResponse(msg, failure=RollbotFailure.INVALID_ARGUMENTS)
+    return RollbotResponse(msg, txt=THE_GUY)

+ 39 - 0
src/plugins/the_house.py

@@ -0,0 +1,39 @@
+from command_system import RollbotResponse, RollbotFailure, as_plugin
+
+housetop = """\
+┏┓
+┃┃╱╲ In this
+┃╱╱╲╲ house
+╱╱╭╮╲╲ we love
+▔▏┗┛▕▔ & appreciate
+╱▔▔▔▔▔▔▔▔▔▔╲
+"""
+
+stfutop = """\
+┏┓
+┃┃╱╲ Shut
+┃╱╱╲╲ The
+╱╱╭╮╲╲ Fuck
+▔▏┗┛▕▔  Up
+╱▔▔▔▔▔▔▔▔▔▔╲
+"""
+
+housebot = """
+╱╱┏┳┓╭╮┏┳┓ ╲╲
+▔▏┗┻┛┃┃┗┻┛▕▔
+"""
+
+@as_plugin("appreciate")
+def the_house(db, msg):
+    
+    thehouse = housetop + ' '.join(list(msg.args(normalize=False))) + housebot
+
+    return RollbotResponse(msg, txt=thehouse)
+
+@as_plugin("stfu")
+def shut_up(db, msg):
+
+    shutup = stfutop + ' '.join(list(msg.args(normalize=False))) + housebot
+
+    return RollbotResponse(msg, txt=shutup)
+

+ 16 - 1
src/rollbot.py

@@ -4,8 +4,15 @@ import time
 from command_system import RollbotResponse, RollbotFailure, as_plugin
 
 
+def lift_response(call, response):
+    @as_plugin(call)
+    def response_func(db, msg):
+        return RollbotResponse(msg, txt=response)
+    return response_func
+
+
 class Rollbot:
-    def __init__(self, logger=logging.getLogger(__name__), plugin_classes={}, aliases={}, lookup={}, sleep_time=0.0, session_factory=None, callback=None):
+    def __init__(self, logger=logging.getLogger(__name__), plugin_classes={}, aliases={}, responses={}, lookup={}, sleep_time=0.0, session_factory=None, callback=None):
         self.logger = logger
         self.session_factory = session_factory or (lambda: None)
         self.callback = callback or (lambda txt, gid: self.logger.info(f"Responding to {gid} with {txt}"))
@@ -26,6 +33,14 @@ class Rollbot:
                 self.to_stop.add(plugin_instance)
         self.logger.info(f"Finished loading plugins, {len(self.commands)} commands found")
 
+        self.logger.info("Loading simple responses")
+        for cmd, response in responses.items():
+            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.logger.info(f"Finished loading simple responses, {len(self.commands)} total commands available")
+
         self.logger.info("Loading aliases")
         for alias, cmd in aliases.items():
             if cmd not in self.commands: