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"
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"
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
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
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
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)
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