Moved treats to affection plugin.
authorCMDR furrycat <elite@furrycat.net>
Thu, 10 Nov 2016 14:20:48 +0000 (14:20 +0000)
committerCMDR furrycat <elite@furrycat.net>
Thu, 10 Nov 2016 14:21:38 +0000 (14:21 +0000)
app.py
plugin/affection/affection.py [new file with mode: 0644]

diff --git a/app.py b/app.py
index be8068b..d19ba75 100644 (file)
--- a/app.py
+++ b/app.py
@@ -83,11 +83,6 @@ def show_help(message, *args):
       '```time```',
       'Useful for `announce create` or to check in-game time.'
     ]
-  elif command == 'treat':
-    lines = [
-      "You can give me a treat if you like.  I may (or may not) show gratitude.",
-      'Probably not.'
-    ]
   elif command in ['coords', 'close_to', 'distance', 'edts', 'find', 'fuel_usage', 'galmath', 'raikogram']:
     params = modules['edi']
     fn = params['fn']
@@ -175,18 +170,6 @@ def do_commands(message, command, raw, non_admin):
     yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False)
     return
 
-  elif command in ['treat', 'stroke', 'fuss', 'pat']:
-    # treat
-    if command == 'treat':
-      responses = ['om nom nom', '^-^', 'meow!', 'lick']
-    else:
-      responses = ['nuzzle', '^-^', 'meow!', 'mrrp']
-    for response in responses:
-      said = yield from bot.maybe_say(message.channel, response)
-      if said:
-        yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False)
-        return
-
   yield from bot.maybe_say(message.channel, 'purr', wake = False)
   yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False)
 
@@ -233,7 +216,7 @@ modules = {
   'any': {
     'fn': do_commands,
     'args': [True],
-    'commands': ['fuss', 'help', 'stroke', 'time', 'treat', 'pat']
+    'commands': ['help', 'time']
   },
   'edi': {
     'fn': do_edi,
diff --git a/plugin/affection/affection.py b/plugin/affection/affection.py
new file mode 100644 (file)
index 0000000..217b1c8
--- /dev/null
@@ -0,0 +1,54 @@
+import asyncio
+
+from plugins import PluginCommand
+import bot
+
+class Affection(object):
+  def __init__(self):
+    self.eat = ['biscuit', 'catnip', 'food', 'treat']
+    self.fuss = ['fuss', 'love', 'pat', 'pet']
+
+  def description(self):
+    return 'Respond (or not) to displays of affection.'
+
+  def secret_commands(self):
+    return self.eat + self.fuss
+
+  @asyncio.coroutine
+  def handle_command(self, message, command, raw):
+    if command not in self.secret_commands():
+      return PluginCommand.ignored
+    result = yield from self.handle_affection(message, command)
+    if result:
+      return PluginCommand.exclusive
+    else:
+      return PluginCommand.handled
+
+  @asyncio.coroutine
+  def handle_help(self, message, command, *args):
+    if len(args):
+      if command in self.secret_commands():
+        yield from self.help_affection(message, *args)
+        return PluginCommand.handled
+    return PluginCommand.ignored
+
+  @asyncio.coroutine
+  def handle_affection(self, message, command):
+    if command in self.eat:
+      responses = ['om nom nom', '^-^', 'meow!', 'lick']
+    else:
+      responses = ['nuzzle', '^-^', 'meow!', 'mrrp']
+    for response in responses:
+      said = yield from bot.maybe_say(message.channel, response)
+      if said:
+        yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False)
+        return True
+    return False
+
+  @asyncio.coroutine
+  def help_affection(self, message, args):
+    lines = [
+      "You can give me a treat if you like.  I may (or may not) show gratitude.",
+      'Probably not.'
+    ]
+    yield from bot.say_lines(message.channel, many)