def generate_events(self, mongo_interface, user): clips = sorted( [(c[NAME], c[IDENTIFIER]) for c in mongo_interface.get_clips(self.tag)] ) names = [] ids = [] for name, identifier in clips: names.append(name) ids.append(identifier) starting_char = [n[0] for n in names] elems_map = dict() for i in range(0, len(starting_char)): elems = elems_map.get(starting_char[i], []) elem = "".join(["(", ids[i], "): ", names[i]]) elems.append(elem) elems_map[starting_char[i]] = elems tables_map = dict() for k in elems_map: table = "<table><tr>" elems = elems_map.get(k) for i, elem in enumerate(elems): if (i + 1) % 5 == 0: table = table + "</tr><tr>" table = table + "".join(["<td>", elem, "</td>"]) table = table + "</tr></table>" tables_map[k] = table html = "" for k in tables_map: table = tables_map[k] html = html + "".join(["<h4>", k, "</h4>", "<ul>", table, "</ul>"]) event = [UserTextEvent(html, user)] if html == "": if self.tag is None: event = [ChannelTextEvent("No clips found in Mongo!!!")] else: event = [ UserTextEvent( "".join(["No clips found with tag: ", self.tag]), user ) ] return event
def test_accept_events(): mumble = MockMumbleWrapper(None, None) manager = TextMessageManager(mumble) assert manager.accept(UserTextEvent(None, None)) assert manager.accept(ChannelTextEvent(None, None)) assert not manager.accept(Event("data"))
def generate_events(self, mongo_interface, user): subclasses = Command.__subclasses__() text = "<br>" + "<br><br>".join([x.help() for x in subclasses]) print(text) # return [UserTextEvent(text, user)] return [UserTextEvent(text, user)]
def test_process_user_text_event(): user = MockUserWrapper("USER") mumble = MockMumbleWrapper(user, None) manager = TextMessageManager(mumble) event = UserTextEvent("MyMessage", user) manager.process(event) assert user.text_data == "MyMessage"
def test_event_from_list_command(): mock_mongo_interface = mock.create_autospec(MongoInterface) mock_mongo_interface.get_clips.return_value = [ { IDENTIFIER: "0", NAME: "awesome" }, { IDENTIFIER: "1", NAME: "bingo" }, ] command = ListCommand(None) event = command.generate_events(mock_mongo_interface, None) expected_html = "".join([ H4, "a", H4_END, UL, TABLE, TR, TD, "(0): awesome", TD_END, TR_END, TABLE_END, UL_END, H4, "b", H4_END, UL, TABLE, TR, TD, "(1): bingo", TD_END, TR_END, TABLE_END, UL_END, ]) expected_event = [UserTextEvent(expected_html, None)] assert event == expected_event
def test_event_from_ignore_command(): command = IgnoreCommand() events = command.generate_events(None, None) assert events == [UserTextEvent(None, None)]
def test_event_from_invalid_command(): command = InvalidCommand() events = command.generate_events(None, None) assert events == [UserTextEvent(None, None)]
def generate_events(self, mongo_interface, user): return [UserTextEvent(self.data, user)]
def generate_events(self, mongo_interface, user): parser = argparse.ArgumentParser(prefix_chars="@") parser.add_argument("@minSpeed") parser.add_argument("@maxSpeed") parser.add_argument("@clips") parser.add_argument("@pitchDownLimit") parser.add_argument("@pitchUpLimit") num_requested = int(self.data[0]) args = parser.parse_args(self.data[1:]) min_speed = args.minSpeed max_speed = args.maxSpeed clips_csv = args.clips pitch_down_limit = args.pitchDownLimit pitch_up_limit = args.pitchUpLimit if min_speed is None: min_speed = "1x" if max_speed is None: max_speed = "1x" if pitch_down_limit is None: pitch_down_limit = "0s" if pitch_up_limit is None: pitch_up_limit = "0s" if clips_csv is None: clips = mongo_interface.get_all_file_names() else: clips = clips_csv.split(",") chosen = [] speeds = [] semitone_shifts = [] if 0 < num_requested < 26: for i in range(0, int(num_requested)): chosen.append(random.choice(clips)) speed = round( random.uniform(float(min_speed[:-1]), float(max_speed[:-1])), 2 ) speeds.append("".join([str(speed), "x"])) pitch_shift = random.randint( int(pitch_down_limit[:-1]), int(pitch_up_limit[:-1]) ) semitone_shifts.append("".join([str(pitch_shift), "s"])) command = ["To repeat this random selection:", "/pmb"] for sp, shift, selected in zip(speeds, semitone_shifts, chosen): command.append("".join([str(round(float(sp[:-1]), 2)), "x"])) command.append("".join([str(shift[:-1]), "s"])) command.append(selected) text_output = " ".join(command) else: text_output = "".join( [ str(num_requested), " is not in the range (0, 10). Request a number in that range.", ] ) print( "".join( [ "files:{", str(chosen), "}\nspeeds:{", str(speeds), "}\nshifts:{", str(semitone_shifts), "}", ] ) ) return [ UserTextEvent(text_output, user), AudioEvent(chosen, speeds, semitone_shifts), ]