LazySusan is a pluginable bot for turntable.fm.
-
Install the package
pip install lazysusan
-
Copy
lazysusan-sample.ini
tolazysusan.ini
. -
Update lazysusan.ini to include your connection information as per these instructions.
-
Launch lazysusan
lazysusan
In your lazysusan.ini
you can add additional configuration sections and
select one of those selections when you start lazysusan. Say for example you
want to only load the echo
plugin. You might define the following section:
[echo_only]
plugins: simple.Echo
Then launch lazysusan via:
lazysusan -c echo_only
Here we will describe how to write the plugins sample.Sample
and
sample.CommandSample
.
You can save this file in any directory, just remember the path to the file.
from lazysusan.plugins import CommandPlugin, Plugin
class Sample(Plugin):
"""A plugin that outputs information about the songs that begin playing."""
def __init__(self, *args, **kwargs):
super(Sample, self).__init__(*args, **kwargs)
print('Sample loaded!')
self.register('newsong', self.handle_newsong)
def handle_newsong(self, data):
song_info = data['room']['metadata']['current_song']
print('{0} started playing playing "{1}" by {2}'
.format(song_info['djname'], song_info['metadata']['song'],
song_info['metadata']['artist']))
class CommandSample(CommandPlugin):
"""A plugin to demonstrate how to create commands."""
COMMANDS = {'/test': 'test'}
def __init__(self, *args, **kwargs):
super(CommandSample, self).__init__(*args, **kwargs)
print('CommandSample loaded!')
def test(self, message, data):
"""The help message for the command /test."""
print('The test command was called')
plugins: sample.Sample
sample.CommandSample
lazysusan -p /path/to/plugin/directory
First send the message /commands
to the bot via pm (or room chat) and verify
that /test
is included in the list.
Then send /test
and notice that the message The test command was called
should appear in your terminal.
Finally you should see messages in your terminal when new songs start playing.