Esempio n. 1
0
async def onRun(bot: IrcBot):
    log("Loading ongoing games...")
    load_games()
    log("Done loading ongoing games!")
    if isinstance(bot.channels, list):
        for channel in bot.channels:
            await bot.send_message(
                Color("CHESS BOT INITIALIZED", Color.light_green,
                      Color.black).str,
                channel,
            )
    else:
        await bot.send_message(
            Color("CHESS BOT INITIALIZED", Color.light_green, Color.black).str)

    while True:
        for nick in botState.invites:
            for channel in botState.invites[nick]:
                for against_nick in deepcopy(botState.invites[nick][channel]):
                    now = datetime.now().timestamp()
                    if (now - botState.invites[nick][channel][against_nick] >
                            EXPIRE_INVITE_IN):
                        botState.invites[nick][channel].pop(against_nick)
                        await bot.send_message(
                            f"<{against_nick}> Your game request to {nick} has expired!",
                            channel,
                        )
        await bot.sleep(0.5)
Esempio n. 2
0
def separator(args, message):
    # you can also retunr a Color object or a list of colors
    return [
        Color(" " * 120, bg=Color.purple),
        Color(" " * 120, bg=Color.white),
        Color(" " * 120, bg=Color.light_green),
        Color(" " * 120, bg=Color.red),
    ]
Esempio n. 3
0
    def utf8_board(self, nick):
        self.loadprefs()
        R = []
        bgi = 1
        row = 8
        label = self.prefs[nick]["label"]
        BG = self.prefs[nick]["bg"]
        FG = self.prefs[nick]["fg"]
        bmode = self.prefs[nick]["bmode"]
        layout = (self.BMODES["normal"]
                  if bmode not in self.BMODES else self.BMODES[bmode])
        b_map = deepcopy(remap)
        b_map.update(layout.get("remap"))

        # Create colored UTF8 board from ASCII board
        R.append(label)
        for l in str(self.board).split("\n"):
            colors = []
            for c in l:
                if not c.upper() in b_map:
                    continue
                piece_type = "pawns" if b_map[
                    c.upper()] == b_map["P"] else "pieces"
                spacing = layout[piece_type]
                if c.upper() == c:
                    piece = Color(
                        f"{' '*spacing[0]}{b_map[c.upper()]}{' '*spacing[1]}",
                        bg=BG[bgi],
                        fg=FG[0] if c != "." else BG[bgi],
                    )
                else:
                    piece = Color(
                        f"{' '*spacing[0]}{b_map[c.upper()]}{' '*spacing[1]}",
                        bg=BG[bgi],
                        fg=FG[1] if c != "." else BG[bgi],
                    )
                colors.append(piece)
                bgi = not bgi
            bgi = not bgi
            colors[-1].str = colors[-1].str[:-1]
            sep = " \003 "
            R.append(
                str(row) + " " + "".join([c.str
                                          for c in colors]) + sep + str(row))
            row -= 1
        R.append(label)
        return R
Esempio n. 4
0
def colors(args, message):
    av_colors_str = f"<{message.nick}> The available colors are: " + ", ".join(
        Color.colors())
    pieces_str = "pieces"
    board_str = "board"
    usage_str = (
        f"<{message.nick}> Usage: colors [{pieces_str}|{board_str}] [color1] [color2]"
    )
    if not args[1]:
        return av_colors_str
    args = [args[i] for i in range(1, 4)]
    a = False

    prefs = get_data(message.nick)
    prefs = json.loads(prefs["prefs"]) if prefs else DEFAULT_PREF
    FG = prefs["fg"]
    BG = prefs["bg"]

    if args[0] == "classic":
        BG = [Color.maroon, Color.gray]
        FG = [Color.white, Color.black]
        a = True
    if args[0] == "modern":
        BG = [Color.purple, Color.red]
        FG = [Color.white, Color.yellow]
        a = True
    if not a:
        if len(args) != 3:
            return usage_str
        elm, c1, c2 = args
        if not c1 in Color.colors() or not c2 in Color.colors():
            return [f"({message.nick}) Invalid colors!", av_colors_str]
        if elm == pieces_str:
            FG = [getattr(Color, c) for c in [c1, c2]]
        elif elm == board_str:
            BG = [getattr(Color, c) for c in [c2, c1]]
        else:
            return usage_str

    set_prefs(message.nick, fg=FG, bg=BG)
    game: Game = botState.get_selected_game(message.nick, message.channel)
    return (["The color preference was set!"] +
            game.utf8_board(message.nick) if game else [])
Esempio n. 5
0
async def mainLoop(bot: IrcBot):
    global waitForStart
    await bot.send_message(Color("HELLO!!!!!", Color.red, Color.black))
    while True:
        l = 1
        r = 14
        w = 15
        c = True  # Direction (true = right)
        while not waitForStart:
            await bot.send_message(
                Color(l * "  ", bg=Color.red).str +
                Color("          ", bg=Color.black).str +
                Color(r * "  ", bg=Color.red).str)
            if c:
                l += 1
                r = w - l
            else:
                l -= 1
                r = w - l
            if l == w or l == 1:
                c = not c
            await bot.sleep(.5)
        await bot.sleep(1)
Esempio n. 6
0
def rainbow(args, message):
    utils.log("rainbowing")
    return "".join([Color(char, Color.random()).str for char in " ".join(utils.m2list(args))])
Esempio n. 7
0
def gay(args, message):
    # use .text or .str to extract string values
    return "".join([Color(c, random.choice(gayColors)).str for c in args[1]])
Esempio n. 8
0
def echo(args, message):
    return Color(" ".join(utils.m2list(args)), Color.random())
Esempio n. 9
0
def colorize(text):
    # use hash and colors to colorize text
    _hash = int(md5(text.strip().encode()).hexdigest(), 16)
    return Color(text, COLORS[_hash % len(COLORS)]).str + Color.esc
Esempio n. 10
0
def red(txt: str) -> str:
    return Color(txt, fg=Color.red).str + Color("", fg=Color.esc).str