Added functions for cat noises.
authorCMDR furrycat <elite@furrycat.net>
Wed, 26 Oct 2016 20:30:20 +0000 (21:30 +0100)
committerCMDR furrycat <elite@furrycat.net>
Wed, 26 Oct 2016 20:31:42 +0000 (21:31 +0100)
Missing maybe_*(), however.

app.py
cat.py [new file with mode: 0644]
plugins/announcements.py
plugins/feeds.py

diff --git a/app.py b/app.py
index 18f1b3f..e55ef29 100644 (file)
--- a/app.py
+++ b/app.py
@@ -21,6 +21,7 @@ from db import DBConnection
 from enum import Enum
 from plugins import Plugins
 import bot
+import cat
 
 class Identify(Enum):
   member = 1
@@ -382,7 +383,7 @@ def do_commands(message, command, raw, non_admin):
       return
     result = yield from set_avatar(url)
     if not result:
-      yield from bot.say(message.channel, 'yelp!')
+      yield from cat.yelp(message.channel)
       return
 
   elif command == 'bling':
@@ -430,7 +431,7 @@ def do_commands(message, command, raw, non_admin):
     yield from client.send_typing(message.channel)
     data = fn(url)
     if data is None:
-      yield from bot.say(message.channel, 'yelp!')
+      yield from cat.yelp(message.channel)
       return
     yield from client.send_file(message.channel, data, filename = filename + '.png', content = ' '.join(mentions) if mentions is not None else 'purr')
     return
@@ -457,7 +458,7 @@ def do_commands(message, command, raw, non_admin):
   elif command == 'delete':
     # delete
     if message.channel.is_private:
-      yield from bot.say(message.channel, 'hiss', wake = False)
+      yield from cat.hiss(message.channel, wake = False)
       return
 
     args = {}
@@ -557,7 +558,7 @@ def do_edi(message, command, raw, p):
 def do_fork(message, command, raw):
   yield from client.send_typing(message.channel)
   if re.search(r'[^A-Za-z0-9-_."\'\s]', raw):
-    yield from bot.say(message.channel, 'hiss')
+    yield from cat.hiss(message.channel)
     return
   p = pexpect.spawnu('./{}'.format(raw))
   p.expect(pexpect.EOF)
@@ -662,7 +663,7 @@ def builtin_commands(message, command, raw):
           lines.append(name)
       yield from bot.say_many(message.channel, lines)
     else:
-      yield from bot.say(message.channel, '*shrugs*')
+      yield from cat.shrug(message.channel)
     return True
   return False
 
@@ -679,7 +680,7 @@ def process_module(message, command, raw):
   if bot.status() == discord.Status.idle:
     yield from bot.maybe_say(message.channel, 'zzz', wake = False)
   else:
-    yield from bot.maybe_say(message.channel, 'meow!')
+    yield from cat.meow(message.channel)
 
 def channels_to_greet():
   greetings = get_bot_variable('greetings', [])
diff --git a/cat.py b/cat.py
new file mode 100644 (file)
index 0000000..9b3b6d7
--- /dev/null
+++ b/cat.py
@@ -0,0 +1,30 @@
+import asyncio
+import bot
+
+@asyncio.coroutine
+def meow(destination, voice = None, **args):
+  result = yield from bot.say(destination, 'meow!') if destination is not None else True
+  if result and voice is not None:
+    yield from bot.play_sound(voice, 'meow.wav', **args)
+
+@asyncio.coroutine
+def purr(destination, voice = None, **args):
+  result = yield from bot.say(destination, 'purr') if destination is not None else True
+  if result and voice is not None:
+    yield from bot.play_sound(voice, 'purr.wav', **args)
+
+@asyncio.coroutine
+def hiss(destination, **args):
+  yield from bot.say(destination, 'hiss!', **args)
+
+@asyncio.coroutine
+def yelp(destination, **args):
+  yield from bot.say(destination, 'yelp!', **args)
+
+@asyncio.coroutine
+def shrug(destination, **args):
+  yield from bot.say(destination, '*shrugs*', **args)
+
+@asyncio.coroutine
+def zzz(destination, **args):
+  yield from bot.say(destination, 'zzz', **args)
index eb1a00f..224dd53 100644 (file)
@@ -9,6 +9,7 @@ import shlex
 from db import DBConnection
 from plugins import PluginCommand
 import bot
+import cat
 
 class Announcements(DBConnection):
   def __init__(self, filename = None):
@@ -159,7 +160,7 @@ class Announcements(DBConnection):
         log.debug('Member {} with role {} on server {} can create announcements.'.format(member.name, member_role.name, server.name))
         return announcement
 
-    yield from bot.say(channel, 'hiss!')
+    yield from cat.hiss(channel)
     return False
 
   @asyncio.coroutine
@@ -309,7 +310,7 @@ class Announcements(DBConnection):
     if len(results):
       yield from bot.say_many(message.channel, results)
     else:
-      yield from bot.say(message.channel, '*shrugs*')
+      yield from cat.shrug(message.channel)
 
   @asyncio.coroutine
   def show_announcement(self, message, id):
@@ -617,10 +618,10 @@ class Announcements(DBConnection):
       create['id'] = id
       log.info('Created announcement: {}'.format(create))
       yield from bot.say(message.channel, id)
-      yield from bot.play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False)
+      yield from cat.purr(None, bot.voice_channel_for_user(message.author), join = False)
     else:
       log.info('Failed to create announcement: {}'.format(create))
-      yield from bot.say(message.channel, 'yelp!')
+      yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def edit_existing_announcement(self, message, raw):
@@ -641,10 +642,10 @@ class Announcements(DBConnection):
     if self.update_announcement(client, id, **update):
       log.info('Edited announcement {}: {}'.format(id, update))
       yield from bot.say(message.channel, ', '.join([announcement_key(k) for k in update]))
-      yield from bot.play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False)
+      yield from cat.purr(None, bot.voice_channel_for_user(message.author), join = False)
     else:
       log.info('Failed to edit announcement {}: {}'.format(id, update))
-      yield from bot.say(message.channel, 'yelp!')
+      yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def delete_existing_announcement(self, message, id):
@@ -656,9 +657,9 @@ class Announcements(DBConnection):
     else:
       log.info('Deleting announcement {}'.format(id))
       if self.delete_announcement(client, id):
-        yield from bot.say(message.channel, 'purr')
+        yield from cat.purr(message.channel)
       else:
-        yield from bot.say(message.channel, 'yelp!')
+        yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def schedule_announcement(self, message, id, **args):
@@ -684,9 +685,9 @@ class Announcements(DBConnection):
     else:
       log.info('Updating announcement {}: {}'.format(id, update))
       if self.update_announcement(client, id, **update):
-        yield from bot.say(message.channel, 'purr')
+        yield from cat.purr(message.channel)
       else:
-        yield from bot.say(message.channel, 'yelp!')
+        yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def manage_announcements(self, message, command, raw):
@@ -705,7 +706,7 @@ class Announcements(DBConnection):
         yield from self.help_announcements(message)
         return
       else:
-        yield from bot.say(message.channel, 'yelp!')
+        yield from cat.yelp(message.channel)
         return
 
     if command == 'show':
index 0a514fd..7fba7ac 100644 (file)
@@ -11,6 +11,7 @@ import time
 from db import DBConnection
 from plugins import PluginCommand
 import bot
+import cat
 
 rsstime = multiprocessing.Value('i', 600)
 
@@ -211,7 +212,7 @@ class Feeds(DBConnection):
         yield from self.help_feeds(message)
         return
       else:
-        yield from bot.say(message.channel, 'yelp!')
+        yield from cat.yelp(message.channel)
         return
 
     if command == 'show':
@@ -264,7 +265,7 @@ class Feeds(DBConnection):
           log.debug('Member {} with role {} on server {} can manage feeds.'.format(member.name, member_role.name, server.name))
           return feed
 
-    yield from bot.say(channel, 'hiss!')
+    yield from cat.hiss(channel)
     return False
 
   @asyncio.coroutine
@@ -288,7 +289,7 @@ class Feeds(DBConnection):
     if len(results):
       yield from bot.say_many(message.channel, results)
     else:
-      yield from bot.say(message.channel, '*shrugs*')
+      yield from cat.shrug(message.channel)
 
   @asyncio.coroutine
   def show_feed(self, message, id):
@@ -442,10 +443,10 @@ class Feeds(DBConnection):
       create['id'] = id
       log.info('Created feed: {}'.format(create))
       yield from bot.say(message.channel, id)
-      yield from play_sound(voice_channel_for_user(message.author), 'purr.wav', join = False)
+      yield from cat.purr(None, voice_channel_for_user(message.author), join = False)
     else:
       log.info('Failed to create feed: {}'.format(create))
-      yield from bot.say(message.channel, 'yelp!')
+      yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def edit_existing_feed(self, message, *args):
@@ -466,10 +467,10 @@ class Feeds(DBConnection):
     if self.update_feed(client, id, **update):
       log.info('Edited feed {}: {}'.format(id, update))
       yield from bot.say(message.channel, ', '.join([self.feed_key(k) for k in update]))
-      yield from play_sound(voice_channel_for_user(message.author), 'purr.wav', join = False)
+      yield from cat.purr(None, voice_channel_for_user(message.author), join = False)
     else:
       log.info('Failed to edit feed {}: {}'.format(id, update))
-      yield from bot.say(message.channel, 'yelp!')
+      yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def delete_existing_feed(self, message, id):
@@ -481,9 +482,9 @@ class Feeds(DBConnection):
     else:
       log.info('Deleting feed {}'.format(id))
       if self.delete_feed(client, id):
-        yield from bot.say(message.channel, 'purr')
+        yield from cat.purr(message.channel)
       else:
-        yield from bot.say(message.channel, 'yelp!')
+        yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def schedule_feed(self, message, id, **args):
@@ -505,9 +506,9 @@ class Feeds(DBConnection):
     else:
       log.info('Updating feed {}: {}'.format(id, update))
       if self.update_feed(client, id, **update):
-        yield from bot.say(message.channel, 'purr')
+        yield from cat.purr(message.channel)
       else:
-        yield from bot.say(message.channel, 'yelp!')
+        yield from cat.yelp(message.channel)
 
   @asyncio.coroutine
   def help_feeds(self, message, command = None):