from ttapi import Bot AUTH = 'HDuKXnXcExdxcpjGuVVOuSEJ' USERID = '511479b5eb35c11c9a3b65e1' ROOMID = '5114792feb35c11c9a3b65e0' bot = Bot(AUTH, USERID, ROOMID) def speak(data): name = data['name'] text = data['text'] if text == '/hello': bot.speak('Hey! How are you %s ?' % name) bot.on('speak', speak) bot.start()
from sys import exit import json import re import sqlite3 as sql # There should be a file in the same directory as the bot # that is named myConfig.py. This file shold contain some # variables that we need to connect to tt.fm # For example: # myUserID = 'XXXXXX' # myAuthKet = 'XXXXXX' # defaultRoom = 'XXXXXX' # ownerID = 'XXXXXX' # dbFile = '<BotName>.sqlite' bot = Bot(myAuthKey, myUserID, defaultRoom) # Define callbacks def roomChanged(data): global theUsersList global theBopList global curSongID global curDjID global theOpList global maxDjCount global roomDJs global roomOwner roomInfo = data['room'] roomMeta = roomInfo['metadata'] curDjID = roomMeta['current_dj']
# -*- coding: iso-8859-15 -*- import twitter import re import settings # this is a relative import. Not sure it works in all versions of python, but seems okay in 2.7.x from ttapi import Bot from random import choice, shuffle ADDRESSING_REQUIRED = True ADDRESSING_PATTERNS = ( r'@?%s[,:;]?\s+(.*)' % settings.TURNTABLE['name'].lower(), r'(.*),?\s+@?%s[\.!\?]?' % settings.TURNTABLE['name'].lower(), ) # Initialize Turntable bot tt_bot = Bot(settings.TURNTABLE['auth'], settings.TURNTABLE['user'], settings.TURNTABLE['room']) # Connect to Twitter account, if settings are in place if hasattr(settings, 'TWITTER'): tw_bot = twitter.Api(**settings.TWITTER) # These globals serve as a short term database. RECENT_SONGS = [] BOPPING = False # Utility function def add_current_song(data): "This function adds the current song to queue. Expects to receive data from tt_bot.roomInfo()" current_song = data['room']['metadata']['songlog'][-1] tt_bot.playlistAdd(current_song['_id'], 999999) # add to bottom of queue