def start_keeping_alive_client_query(): if bot.silent: sys.stdout = open(FileSystem.get_log_file_path(), "a") sys.stderr = open(FileSystem.get_log_file_path(), "a") while bot.running: time.sleep(200) with bot.clientQueryLock: client_query.sendKeepAlive()
def start_checking_for_terminal_command(): if bot.silent: sys.stdout = open(FileSystem.get_log_file_path(), "a") sys.stderr = open(FileSystem.get_log_file_path(), "a") while bot.running: string = input() command = parse_command(string) with bot.lock: handle_command(command)
def start_checking_for_teamspeak_command(): if bot.silent: sys.stdout = open(FileSystem.get_log_file_path(), "a") sys.stderr = open(FileSystem.get_log_file_path(), "a") client_query.registerForTextEvents() while bot.running: string = client_query.listenForTextEvents() if string is not None: command = cli.parse_command(string) with bot.lock: cli.handle_command(command, prefix=Prefixes.TeamSpeak)
def read_data(): global api_key global nickname global server_address global team_speak_path try: json_file = open(FileSystem.get_config_file_path()) data = json.load(json_file) with JSONData.read(data, JSONFields.ApiKey) as json_field: api_key = json_field with JSONData.read(data, JSONFields.Nickname) as json_field: nickname = json_field with JSONData.read(data, JSONFields.ServerAddress) as json_field: server_address = json_field with JSONData.read(data, JSONFields.TeamSpeakPath) as json_field: team_speak_path = json_field return True except: print("couldn't read config file") print("trying to create a ts3 clientquery config file") try: json_file = open(FileSystem.get_config_file_path(), "w") data = { JSONFields.ApiKey: "<YOURAPIKEY>", JSONFields.Nickname: "Musicbot", JSONFields.ServerAddress: "", JSONFields.TeamSpeakPath: "" } json.dump(data, json_file, indent=4) print( "created a config.json file in " + FileSystem.get_data_folder_path() + "you'll have to enter a ts3clientquery api key which can be found in your teamspeak client at: " "tools - options - addons - clientquery - settings. optionally you can change the nickname and " "specify a default server address and a teamspeak path to automatically start teamspeak.") except FileExistsError: print("couldn't create config file") return False
def run(args=Modules.TeamSpeak + Modules.CLI): global lock global clientQueryLock global debug global silent if Modules.SILENT in args: silent = True sys.stdout = open(FileSystem.get_log_file_path(), "a") sys.stderr = open(FileSystem.get_log_file_path(), "a") print("####################\nstarting...") if not create_vlc_player(): print("error while connecting to vlc exiting") exit() read_data() lock = threading.Lock() clientQueryLock = threading.Lock() main_thread = add_thread(target=main_loop) add_thread(target=frequently_write_data, daemon=True) if Modules.CLI in args: modules.append(cli) if Modules.TeamSpeak in args: modules.append(teamspeak) if Modules.ZMQ in args: modules.append(zmqserver) if Modules.Debug in args: print("running in debug mode") debug = True for m in modules: m.run() start_threads() report("ready")
def read_data(): global playlists global index global lastPosition global repeatSong try: with open(FileSystem.get_data_file_path()) as json_file: data = json.load(json_file) with JSONData.read(data, JSONFields.Playlists) as json_playlists: for p in json_playlists: playlists.append(Playlist.json_to_playlist(p)) with JSONData.read(data, JSONFields.SongQueue) as json_song_queue: for s in json_song_queue: songQueue.append(Song.json_to_song(s)) with JSONData.read(data, JSONFields.Index) as json_field: index = json_field if json_field >= len(songQueue) and json_field != 0: index = len(songQueue) - 1 with JSONData.read(data, JSONFields.Position) as json_field: lastPosition = json_field with JSONData.read(data, JSONFields.RepeatSong) as json_field: repeatSong = json_field return True except: report("couldn't read config file") report("trying to create the conifg folder") try: os.mkdir(FileSystem.get_data_folder_path()) except FileExistsError: report("config folder existed") return False
def write_data(): data = { JSONFields.Playlists: [], JSONFields.SongQueue: [], JSONFields.Index: index, JSONFields.Position: player.get_position(), JSONFields.RepeatSong: repeatSong } for p in playlists: data[JSONFields.Playlists].append(p.to_json()) for s in songQueue: data[JSONFields.SongQueue].append(s.to_json()) try: with open(FileSystem.get_data_file_path(), "w") as jsonfile: json.dump(data, jsonfile, indent=4) except: print("couldn't write data")
def start_teamspeak(team_speak_path): out = sys.stdout if bot.silent: out = open(FileSystem.get_log_file_path(), "a") subprocess.call(team_speak_path, shell=True, stdout=out, stderr=out)