Update website and e-mail info
[jabberbot/examples.git] / examples / tunes.py
blobc1e6328d6f8cedbe2ddb8c2e2787da11acc6a315
1 # Tunes: Example XEP-0118 (User Tune) user.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Homepage: http://thp.io/2007/python-jabberbot/
18 """
19 When the bot is connected, use commands like:
21 set artist Metallica
22 set title Bad Seed
24 The bot will update its tune and log the outgoing packet to stdout.
25 """
27 import sys
28 from jabberbot import JabberBot, botcmd
30 class Tunes(JabberBot):
31 def __init__(self, username, password):
32 JabberBot.__init__(self, username, password)
33 self.track = { 'file': 'test.mp3' }
35 @botcmd
36 def set(self, message, args):
37 'set track properties'
38 args = args.strip().split(' ')
39 if len(args) < 2 or args[0] not in ('artist', 'title', 'album', 'source', 'pos', 'track', 'time', 'uri'):
40 return 'Usage: set {artist|title|album|source|pos|track|time|uri} value'
41 self.track[args[0]] = ' '.join(args[1:])
42 self.send_tune(self.track, True)
44 if __name__ == '__main__':
45 if len(sys.argv) < 3:
46 print 'Usage: %s login@host password' % sys.argv[0]
47 sys.exit(1)
48 bot = Tunes(sys.argv[1], sys.argv[2])
49 bot.serve_forever()