def generate_events(self, mongo_interface, user):
        parser = argparse.ArgumentParser(prefix_chars="@")
        parser.add_argument("@list", action="store_true")
        parser.add_argument("@song")
        parser.add_argument("@clip")
        parser.add_argument("@speed")
        parser.add_argument("@pitch")
        parser.add_argument("@num_bars")
        parser.add_argument("@volume")

        args = parser.parse_args(self.data[0:])

        if args.list:
            # List clips
            return [ListMusicEvent(None)]

        else:
            song = None
            if args.song is None:
                return [ChannelTextEvent("No song specified!")]
            else:
                song = args.song

            clip = None
            if args.clip is None:
                return [ChannelTextEvent("No clip specified!")]
            else:
                clip = args.clip

            speed = 1 if args.speed is None else float(args.speed[:-1])
            pitch = 0 if args.pitch is None else int(args.pitch[:-1])
            volume = 1 if args.volume is None else float(args.volume)
            num_bars = None if args.num_bars is None else int(args.num_bars)

            return [MusicEvent(clip, song, speed, pitch, num_bars, volume)]
    def generate_events(self, mongo_interface, user):
        volume = float(self.data)

        mongo_interface.set_volume(volume)
        return [
            ChannelTextEvent("".join(["The bot's volume has been set to: ", self.data]))
        ]
示例#3
0
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"))
示例#4
0
def test_process_channel_text_event():
    channels = {"channel": MockChannelWrapper()}
    mumble = MockMumbleWrapper(None, channels)
    manager = TextMessageManager(mumble)
    event = ChannelTextEvent("MyMessage", "channel")

    manager.process(event)

    assert channels["channel"].data == "MyMessage"
    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 generate_events(self, mongo_interface, user):
        new_clips = mongo_interface.add_new_clips()

        print("loaded")

        clips_formatted = []
        for identifier, name in new_clips:
            clips_formatted.append(" -> ".join([identifier, name]))

        text_output = ", ".join(clips_formatted)

        return [
            ChannelTextEvent(
                "".join(["The following clips have been loaded: ", text_output])
            )
        ]
    def generate_events(self, mongo_interface, user):
        if isinstance(self, TagCommand):
            tagging_function = mongo_interface.tag
            output_start = 'The following files have now been tagged with "'
        elif isinstance(self, UntagCommand):
            tagging_function = mongo_interface.untag
            output_start = 'The following files have now been untagged with "'
        else:
            raise TypeError("AbstractTagCommand is not of a known subclass")

        tag = self.data[0]
        files = self.data[1:]
        tagging_function(files, tag)

        text_output = "".join(
            [
                output_start,
                tag,
                '": ',
                ",".join(files),
            ]
        )
        return [ChannelTextEvent(text_output)]
 def generate_events(self, mongo_interface, user):
     chosen = random.choice(self.GAME_MODES)
     return [ChannelTextEvent(chosen, channel_name=os.getenv(ROOT_CHANNEL))]