Exemplo n.º 1
0
 async def test_parse_str(self):
     topic = """
         @quote('foo')
         @doublequote("foo")
         @noquote(foo)
     """
     c = parse_directives(topic)
     assert parse_single(next(c)[1]) == "foo"
     assert parse_single(next(c)[1]) == "foo"
     assert parse_single(next(c)[1]) == "foo"
Exemplo n.º 2
0
 async def test_parse_single(self):
     topic = """
         @int(123)
         @float(4.56)
         @bool(true)
         @string("foo")
     """
     c = parse_directives(topic)
     assert parse_single(next(c)[1]) == 123
     assert parse_single(next(c)[1]) == 4.56
     assert parse_single(next(c)[1])
     assert parse_single(next(c)[1]) == "foo"
Exemplo n.º 3
0
    def overflow(self, props: str):
        props = directives.parse_single(props)
        if type(props) is not bool:
            self.issue("You must provide either True or False.")
            return

        self.vOverflow = props
Exemplo n.º 4
0
    def name(self, props: str):
        props = directives.parse_single(props)
        if type(props) is not str:
            self.issue("You must provide a value, Ex: `'Game night!'`")
            return

        self.vName = props
Exemplo n.º 5
0
    def teams(self, props: str):
        props = directives.parse_single(props)
        if type(props) is not list:
            self.issue("You must provide a list of teams. Ex: `[4, 4]`")
            return

        if any(type(p) is not int for p in props):
            self.issue("You must provide a list of teams. Ex: `[4, 4]`")
            return

        self.vTeams = props
Exemplo n.º 6
0
    def broadcast(self, props: str):
        props = directives.parse_single(props)
        if type(props) is str:
            destinations = list(props)
        elif type(props) is list:
            destinations = props
        else:
            self.issue("You must provide the channel name(s)")
            return

        all_channels = self.bot.get_all_channels()
        for dest in destinations:
            matching = list(filter(lambda c: c.name == dest, all_channels))
            if not len(matching):
                self.issue(f"'{dest}' is not a visible text channel")

            for channel in matching:
                if not isinstance(channel, TextChannel):
                    self.issue(f"'{dest}' is not a text channel")
                else:
                    self.vBroadcastChannels.append(channel)
Exemplo n.º 7
0
    async def test_parse_bool(self):
        topic = """
            @TRUE(TRUE)
            @True(True)
            @true(true)
            @FALSE(FALSE)
            @False(False)
            @false(false)
        """
        c = parse_directives(topic)
        v = parse_single(next(c)[1])
        assert type(v) is bool and v
        v = parse_single(next(c)[1])
        assert type(v) is bool and v
        v = parse_single(next(c)[1])
        assert type(v) is bool and v

        v = parse_single(next(c)[1])
        assert type(v) is bool and not v
        v = parse_single(next(c)[1])
        assert type(v) is bool and not v
        v = parse_single(next(c)[1])
        assert type(v) is bool and not v