Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def handle_chat_message(args):
log.info("chat message received: %s", args)
if ext_chat:
extended_command.handler(args)
rawMessage = args['message']
withoutName = rawMessage.split(']')[1:]
message = "".join(withoutName)
try:
if message[1] == ".":
exit()
else:
tts.say(message, args)
except IndexError:
exit()
coz.set_head_light(enable=is_headlight_on)
time.sleep(0.35)
#animations from example
elif command.isdigit():
coz.play_anim(name=default_anims_for_keys[int(command)]).wait_for_completed()
#things to say with TTS disabled
elif command == 'sayhi':
tts.say( "hi! I'm cozmo!" )
elif command == 'saywatch':
tts.say( "watch this" )
elif command == 'saylove':
tts.say( "i love you" )
elif command == 'saybye':
tts.say( "bye" )
elif command == 'sayhappy':
tts.say( "I'm happy" )
elif command == 'saysad':
tts.say( "I'm sad" )
elif command == 'sayhowru':
tts.say( "how are you?" )
#cube controls
elif command == "lightcubes":
print( "lighting cubes" )
light_cubes( coz )
elif command == "dimcubes":
print( "dimming cubes" )
dim_cubes( coz )
#sing song example
elif profile.data['stt'] == 'telegram':
def handle(msg):
chat_id = msg['chat']['id']
username = msg['chat']['username']
command = msg['text'].lower().replace("'", "")
if username == profile.data['telegram_username']:
print(profile.data['va_name'] +
" thinks you said '" + command + "'")
return command
else:
error_msg = 'You are not authorised to use this bot.'
bot.sendMessage(chat_id, error_msg)
if profile.data['telegram_token'] == 'xxxx':
tts('Please enter a Telegram token or configure a different ' +
'STT in the profile.json file.')
quit()
else:
bot = telepot.Bot(profile.data['telegram_token'])
bot.notifyOnMessage(handle)
while True:
time.sleep(10)
def internetStatus_task():
global bootMessage
global lastInternetStatus
internetStatus = isInternetConnected()
if internetStatus != lastInternetStatus:
if internetStatus:
tts.say(bootMessage)
log.info("internet connected")
else:
log.info("missing internet connection")
tts.say("missing internet connection")
lastInternetStatus = internetStatus
def reportNeedToCharge():
if not isCharging():
if chargeValue <= 25:
tts.say("need to charge")
def anon_handler(command, args):
global anon_control
if len(command) > 1:
if is_authed(args['name']): # Moderator
log.info("anon chat command called by %s", args['name'])
if command[1] == 'on':
log.info("Anon control / TTS enabled")
anon_control = True
tts.unmute_anon_tts()
robot_util.setAnonControl(True, robot_id, api_key)
elif command[1] == 'off':
log.info("Anon control / TTS disabled");
anon_control = False
tts.mute_anon_tts()
robot_util.setAnonControl(False, robot_id, api_key)
elif len(command) > 3:
if command[1] == 'control':
if command[2] == 'on':
log.info("Anon control enabled")
anon_control = True
robot_util.setAnonControl(True, robot_id, api_key)
elif command[2] == 'off':
log.info("Anon control disabled")
anon_control = False
robot_util.setAnonControl(False, robot_id, api_key)
def download_file(filesystem,ident,save_type):
"""Attempt to download all files for a given savefile"""
log=tts.logger()
log.info("Downloading %s file %s (from %s)" % (save_type.name,ident,filesystem))
filename=filesystem.get_json_filename_for_type(ident,save_type)
if not filename:
log.error("Unable to find data file.")
return False
try:
data=load_json_file(filename)
except IOError as e:
log.error("Unable to read data file %s (%s)" % (filename,e))
return False
if not data:
log.error("Unable to read data file %s" % filename)
return False
save=tts.Save(savedata=data,
filename=filename,
def setup(robot_config):
global forward_speed
global turn_speed
global coz
global volume
global charge_high
global charge_low
global stay_on_dock
coz = tts.tts_module.getCozmo()
mod_utils.repeat_task(30, check_battery, coz)
if robot_config.has_section('cozmo'):
forward_speed = robot_config.getint('cozmo', 'forward_speed')
turn_speed = robot_config.getint('cozmo', 'turn_speed')
volume = robot_config.getint('cozmo', 'volume')
charge_high = robot_config.getfloat('cozmo', 'charge_high')
charge_low = robot_config.getfloat('cozmo', 'charge_low')
stay_on_dock = robot_config.getfloat('cozmo', 'stay_on_dock')
if robot_config.getboolean('tts', 'ext_chat'): #ext_chat enabled, add motor commands
extended_command.add_command('.anim', play_anim)
extended_command.add_command('.forward_speed', set_forward_speed)
extended_command.add_command('.turn_speed', set_turn_speed)
extended_command.add_command('.vol', set_volume)
extended_command.add_command('.charge', set_charging)
def load_json_file(filename):
log=tts.logger()
if not filename:
log.warn("load_json_file called without filename")
return None
if not os.path.isfile(filename):
log.error("Unable to find requested file %s" % filename)
return None
log.info("loading json file %s" % filename)
encodings = ['utf-8', 'windows-1250', 'windows-1252', 'ansi']
data=None
for encoding in encodings:
try:
data=codecs.open(filename,'r',encoding).read()
except UnicodeDecodeError as e:
log.debug("Unable to parse in encoding %s." % encoding)
else:
log.debug("loaded using encoding %s." % encoding)
def tts_handler(command, args):
log.debug("tts : %s", tts)
if len(command) > 1:
if is_authed(args['name']) == 2: # Owner
if command[1] == 'mute':
log.info("Owner muted TTS")
tts.mute_tts()
return
elif command[1] == 'unmute':
log.info("Owner unmuted TTS")
tts.unmute_tts()
return
elif command[1] == 'vol':
if len(command) > 2:
log.info("Owner changed TTS Volume")
tts.volume(command[2])
return