def move(args): print(args) global stationary_mode if (args['button']['command'] == 'u' and stationary_mode == False): forward() elif (args['button']['command'] == 'd' and stationary_mode == False): backwards() elif (args['button']['command'] == 'l' and stationary_mode == False): left() elif (args['button']['command'] == 'r' and stationary_mode == False): right() elif (args['button']['command'] == 'arm_up' and stationary_mode == False): arm_up() elif (args['button']['command'] == 'arm_down' and stationary_mode == False): arm_down() elif (args['button']['command'] == 'home' and stationary_mode == False): go_home() elif (args['button']['command'] == 'lights_on'): lights_on() elif (args['button']['command'] == 'lights_off'): lights_off() elif (args['button']['command'] == 'clear_buffer'): movements.clear() tts_module.say("Movement buffer cleared.") robot_util.sendChatMessage("Movement buffer cleared.")
def untimeout_user(user): global banned if user in banned: banned.remove(user) log.info("%s timeout expired", user) robot_util.sendChatMessage("{} timeout expired".format(user)) tts.unmute_user_tts(user)
def help_handler(command, args): available = "" user = is_authed(args['sender']) for key in sorted(commands): if commands[key]['perm'] <= user: available = available + " " + key robot_util.sendChatMessage('.Available commands : ' + available)
def ban_handler(command, args): global banned if len(command) > 1: user = command[1] if is_authed(args['sender']): # Moderator banned.append(user) log.info("%s added %s to ban list", args['sender'], user) robot_util.sendChatMessage("{} added to ban list".format(user)) tts.mute_user_tts(user)
def new_voice(command, args): global users user = args['sender'] if len(command) > 1: if command[1] in voices: users[user] = command[1] else: users[user] = random.choice(voices) robot_util.sendChatMessage(".%s your voice is now %s" %(user, users[user]))
def timeout_handler(command, args): global banned if len(command) > 1: user = command[1] if is_authed(args['sender']): # Moderator banned.append(user) schedule.single_task(300, untimeout_user, user) log.info("%s added %s to timeout list", args['sender'], user) robot_util.sendChatMessage("{} timed out".format(user)) tts.mute_user_tts(user)
def new_voice(command, args): global users if (args['anonymous'] != True): user = args['name'] if len(command) > 1: if command[1] in voices: users[user] = command[1] else: users[user] = random.choice(voices) robot_util.sendChatMessage(".%s your voice is now %s" %(user, users[user]))
def untimeout_handler(command, args): global banned if len(command) > 1: user = command[1] if is_authed(args['sender']): # Moderator if user in banned: banned.remove(user) log.info("%s removed %s from timeout list", args['sender'], user) robot_util.sendChatMessage("{} timeout cleared".format(user)) tts.unmute_user_tts(user)
def whitelist_handler(command, args): global whiteList global whiteListCommand if len(command) > 2: if is_authed(args['sender']) == 2: # Owner user = command[2] if command[1] == 'add': whiteList.append(user) log.info("%s added to whitelist", user) robot_util.sendChatMessage( "User {} added to whitelist".format(user)) elif command[1] == 'del': whiteList.remove(user) log.info("%s removed from whitelist", user) robot_util.sendChatMessage( "User {} removed from whitelist".format(user)) elif command[1] == 'command': if len(command) > 3: new_command = command[3] if command[2] == 'add': whiteListCommand.append(new_command) log.info("%s added to command whitelist" % new_command) robot_util.sendChatMessage( "command {} added to whitelist".format( new_command)) elif command[2] == 'del': whiteListCommand.remove(new_command) log.info("%s removed from command whitelist" % new_command) robot_util.sendChatMessage( "command {} removed from whitelist".format( new_command))
def exclusive_handler(command, args): global exclusive global exclusive_user global exclusive_mods log.debug("exclusive_handler : %s %s", command, args) if len(command) >= 2: if is_authed(args['sender']) == 2: # Owner if command[1] == 'off': exclusive = False log.info("Exclusive control disabled") robot_util.sendChatMessage("Exclusive control disabled") return elif len(command) < 3: exclusive_user = command[1] exclusive = True log.info("%s given exclusive control", command[1]) robot_util.sendChatMessage("{} given exclusive control".format( command[1])) return elif (len(command) >= 2) and (command[1] == 'mods'): if command[2] == 'on': exclusive_mods = True log.info("Enabling mod control during exclusive") robot_util.sendChatMessage( "Enabling mod control during exclusive") return elif command[2] == 'off': exclusive_mods = False log.info("Disabling mod control during exclusive") robot_util.sendChatMessage( "Disabling mod control during exclusive") return
def stationary_handler(command, args): global stationary if is_authed(args['sender']) == 2: # Owner if len(command) > 1: if command[1] == 'on': stationary = True elif command[1] == 'off': stationary = False else: stationary = not stationary log.info("stationary is %s", stationary) if stationary: robot_util.sendChatMessage("Stationary mode enabled") else: robot_util.sendChatMessage("Stationary mode disabled")
def tts_handler(command, args): log.debug("tts : %s", tts) if len(command) > 1: if is_authed(args['sender']) == 2: # Owner if command[1] == 'mute': log.info("Owner muted TTS") robot_util.sendChatMessage("TTS muted") tts.mute_tts() return elif command[1] == 'unmute': log.info("Owner unmuted TTS") robot_util.sendChatMessage("TTS unmuted") tts.unmute_tts() return elif command[1] == 'vol': if len(command) > 2: log.info("Owner changed TTS Volume") robot_util.sendChatMessage("Changed TTS volume") tts.volume(command[2]) return
def devmode_handler(command, args): global dev_mode global dev_mode_mods if len(command) > 1: if is_authed(args['sender']) == 2: # Owner if command[1] == 'on': log.info("Owner enabled dev mode") robot_util.sendChatMessage("Local Dev mode enabled") dev_mode = True dev_mode_mods = False elif command[1] == 'off': log.info("Owner disabled dev mode") robot_util.sendChatMessage("Local Dev mode disabled") dev_mode = False elif command[1] == 'mods': log.info("Owner enabled dev mode with mod control") robot_util.sendChatMessage( "Local Dev mode with mod controls enabled") dev_mode = True dev_mode_mods = True log.debug("dev_mode : %s", str(dev_mode)) log.debug("dev_mode_mods : %s", str(dev_mode_mods))
def battery_handler(command, args): global battery robot_util.sendChatMessage("{}%".format(move_handler.get_battery())) move_handler.tts("Battery is {}%".format(move_handler.get_battery()))
def save_handler(command, args): if is_authed(args['sender']) == 2: robot_config.write('controller.conf') robot_util.sendChatMessage('.Config file saved.')
def test_messages(command, args): log.debug(command) log.debug(args) command = args["message"].split(' ')[1:] robot_util.sendChatMessage(command)
def update_handler(command, args): global update_available if extended_command.is_authed(args['sender']) == 2: if len(command) == 1: # just .update if not update_available: if checkForUpdates(): robot_util.sendChatMessage( "{} updates available. Send '.update yes' to apply updates." .format(update_available)) else: robot_util.sendChatMessage( "Robot is already up to date. Nothing to do!") else: robot_util.sendChatMessage( "{} updates available. Send '.update yes' to apply updates." .format(update_available)) else: if command[1] == "yes": if checkLocalChanges(): if doUpdate(): update_fetched = False robot_util.sendChatMessage( 'Update completed. Restart for changes to take effect.' ) else: robot_util.sendChatMessage( 'Update Failed. run "git pull" locally to determine error.' ) else: robot_util.sendChatMessage( 'Automatic Update aborted, you have modified core files.' )