async def ducksay(self, ctx: Context, message: str) -> None: """Duck says what?""" MAX_LEN = 50 data = message.split(' ') res = [] curr = "" for val in data: new = curr + ' ' + val if curr else curr + val if len(new) >= MAX_LEN: res.append(curr) curr = "" new = curr + val curr = new if curr: res.append(curr) max_len = len(zz.of(res).max(len)) if len(res) > 1: delim = zz.empty().chain(zz.of(["/\\"]), zz.repeat("||", n=len(res) - 2), zz.of(["\\/"])) else: delim = zz.repeat("<>") final = '' final += "```\n" final += " " + "_" * (max_len + 2) + " \n" for d, elem in zip(delim, res): elem += " " * (max_len - len(elem)) final += d[0] + " " + elem + " " + d[1] + "\n" final += " " + "-" * (max_len + 2) + " \n" final += " \\\n" final += " \\\n" final += " \\ >()_\n" final += " (__)__ _\n" final += "```" await ctx.send(final)
def _read_adv(arg: str) -> Optional[Tuple[Oper[Union[int, str]], str]]: test0 = _read_number(arg) if test0: n0, arg1 = test0 n = n0.n else: n = 2 arg1 = arg if n <= 0: return None if _read_prefix(arg1, '!'): op = max elif _read_prefix(arg1, '?'): op = min else: return None arg1 = arg1[1:] test = _read_term(arg1) if test: inner, arg2 = test return Oper(zz.repeat(inner, n=n).list(), op), arg2 else: return None
def test_repeat_2(self): iterable = zz.repeat(12, n=2) self.assertEqual(list(iterable), [12, 12])
def test_repeat_1(self): iterable = zz.repeat(12).take(2) self.assertEqual(list(iterable), [12, 12])
def test_zipup_5(self): # Make sure it works in the infinite case iterable = zz.zipup(zz.repeat(1), zz.repeat(2)) self.assertEqual(iterable.take(2).list(), [(1, 2), (1, 2)])
def test_zipup_3(self): # Make sure it truncates on the left iterable = zz.zipup(zz.repeat(1), ["foo", "bar"]) self.assertEqual(iterable.list(), [(1, "foo"), (1, "bar")])
def test_zipup_2(self): # Make sure it truncates on the right iterable = zz.zipup(["foo", "bar"], zz.repeat(1)) self.assertEqual(iterable.list(), [("foo", 1), ("bar", 1)])
def test_each_2(self): def f(x): raise SampleError("This error should not be raised") with self.assertRaises(SampleError): zz.repeat(0).each(f)
def test_all_5(self): # Short-circuits on infinite sequences self.assertFalse(zz.repeat(False).all())
def test_take_4(self): # Works on infinite lists self.assertEqual(zz.repeat(7).take(2).list(), [7, 7])
def test_zip_8(self): iterable = zz.repeat(1).zip(zz.repeat(2)) self.assertEqual(iterable.take(2).list(), [(1, 2), (1, 2)])
def test_starmap_2(self): # starmap should be lazy self.assertEqual(zz.repeat((1, 1)).starmap(operator.add).take(3).list(), [2, 2, 2])