alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
317 stars 97 forks source link

Using getProfile when replying to PMs (Python) #62

Closed BenTheHokie closed 12 years ago

BenTheHokie commented 12 years ago

I may be asking not exactly in the right place, but suppose I wanted to be able to return the username of any user by using getProfile and then reply in a PM e.g.:

user:    username of 4f66952ba3f751581d025a4d
bot:     The username of the user is John Doe.

How would I go about doing this?

Thanks and pardon my lack of experience ~ LSK

alaingilbert commented 12 years ago
from ttapi import Bot 
import re

bot = Bot('xxx', 'xxx', 'xxx')

def pmmed(data):
   user = data['senderid']
   requested_id = re.search('^/username (.+)$', data['text']).group(1)

   def profile(data):
      bot.pm('The username of the user is %s' % data['name'], user)
   bot.getProfile(requested_id, profile)

bot.on('pmmed', pmmed)

bot.start()
user: /username 4f66952ba3f751581d025a4d
bot: The username of the user is Gilbert19

;)

BenTheHokie commented 12 years ago

Now I could also do this with a Twitter Profile or something like:

     def profileTwitter(data):
          bot.pm('The Twitter profile of the user is %s.' % data['twitter'],user)
     bot.getProfile(requested_id, profileTwitter)

etc.

Correct?