Esempio n. 1
0
@utils.arg_command("add")
def add(args, message):
    nicks = utils.m2list(args)
    if message.sender_nick == ADMIN and MASTER:
        for nick in nicks:
            if nick in pids:
                return f"{message.sender_nick}: {nick} is already in use!"
        for nick in nicks:
            pids[nick] = subprocess.Popen(
                f"python3 /home/mattf/projects/ircbots/cbbot.py {shlex.quote(nick)} '{message.channel}'",
                stdout=subprocess.PIPE,
                shell=True)


##################################################
# RUNNING THE BOT                                #
##################################################


async def onConnect(bot: IrcBot):
    for channel in CHANNELS:
        await bot.join(channel)
    await bot.send_message("Hello everyone !!!")


if __name__ == "__main__":
    utils.setLogging(LEVEL, LOGFILE)
    utils.setPrefix(PREFIX)
    bot = IrcBot(HOST, PORT, NICK, CHANNELS, PASSWORD)
    bot.runWithCallback(onConnect)
Esempio n. 2
0
    def last_modified(r):
        if r.last_modified:
            return datetime.utcnow() - datetime.strptime(
                r.last_modified, '%a, %d %b %Y %H:%M:%S GMT')
        return gh_repotimedelta(r)

    def get_forks(r):
        repos = []
        for fork in itertools.islice(r.get_forks(), MAX_REPOS):
            repos.append(fork)
            try:
                repos += get_forks(fork)
            except GithubException:
                continue
        return repos

    repolist = get_forks(repo)
    rs = sorted(repolist, key=lambda r: r.stargazers_count, reverse=True)
    trs = []
    if len(repolist) < MAX_REPOS:
        trs = [
            r for r in sorted(repolist, key=last_modified)[:GH_LIST_LEN]
            if r not in rs
        ]
    return [ghsearch_format(r) for r in rs[:GH_LIST_LEN] + trs]


if __name__ == "__main__":
    bot = IrcBot(HOST, nick=NICK, channels=CHANNELS)
    bot.run()
Esempio n. 3
0
        return "Check help send"
    if not args[1].isdigit():
        return "Delay argument should be integer and in seconds"
    utils.log("waiting")
    await bot.sleep(int(args[1])) #Wait for the delay

    # Sends the message. The channel can be also a username for private messages
    utils.log("sending")
    await bot.send_message(Message(channel=args[0], message=" ".join(args[2:])))

@utils.arg_command("list", "Lists users on the chat")
async def list_u(bot: IrcBot, args, message):
    names = bot.channel_names[message.channel]
    return f"HELLO {', '.join(names)}"

# Handles user quit or exit chat
@utils.custom_handler(['part', 'quit'])
def onQuit(nick, channel="", text=""):
    return f"Bye {nick}, I will miss you :(  oh it is too late now"

# Handles user join
@utils.custom_handler('join')
def onEnter(nick, channel):
    if nick == "echobot": #Ignore myself ;)
        return None
    return f"Hello {nick} I am glad to see you!!!"

if __name__ == "__main__":
    bot = IrcBot("irc.dot.org.es", nick="echobot", channels=['#bots'])
    bot.run()
Esempio n. 4
0
                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)


##################################################
# RUNNING THE BOT                                #
##################################################

if __name__ == "__main__":
    bot = IrcBot(HOST, PORT, NICK, CHANNELS, PASSWORD, tables=[db_handler])
    bot.runWithCallback(onRun)
Esempio n. 5
0
    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)


##################################################
# RUNNING THE BOT                                #
##################################################

if __name__ == "__main__":
    utils.setLogging(LEVEL, LOGFILE)
    bot = IrcBot(HOST, PORT, NICK, CHANNELS, PASSWORD)
    bot.runWithCallback(mainLoop)
Esempio n. 6
0
    gayColors.remove(k)
    for k in [Color.white, Color.gray, Color.light_gray, Color.black]
]


@utils.regex_cmd_with_messsage("^gay (.+)$", ACCEPT_PRIVATE_MESSAGES)
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]])


@utils.regex_cmd_with_messsage("^sep$", ACCEPT_PRIVATE_MESSAGES)
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),
    ]


##################################################
# RUNNING THE BOT                                #
##################################################

if __name__ == "__main__":
    utils.setLogging(LEVEL, LOGFILE)
    bot = IrcBot(HOST, PORT, NICK, CHANNELS, PASSWORD)
    bot.run()
Esempio n. 7
0
# Simple echo bot example with random color echo because why not
from IrcBot.bot import IrcBot, utils, Color


@utils.arg_command("echo")
def echo(args, message):
    return Color(" ".join(utils.m2list(args)), Color.random())


async def onConnect(bot: IrcBot):
    await bot.join("#bots")


if __name__ == "__main__":
    bot = IrcBot("irc.dot.org.es", nick="echobot")
    bot.runWithCallback(onConnect)

# Type any string starting matching "echo" as a command like '!echo hahaha', !e how are you?' , '!ech ha!'
Esempio n. 8
0
        search_nick = message.sender_nick
    for user in users.data:
        if search_nick == user[table_columns[0]]:
            return_value = ", ".join(
                [f"{u}: {user[u]}" for u in user if not "id" in u])
            break
    return_value = MSGS.nick_not_registerd_error if not return_value else return_value
    return Message(channel=message.sender_nick,
                   sender_nick=message.sender_nick,
                   message=return_value) if PRIVATEONLY_SHOW else return_value


@utils.regex_cmd_with_messsage(getcmd(CMDS.delete), ACCEPT_PRIVATE_MESSAGES)
def delete(m, message):
    nick = message.sender_nick
    for user in users.data:
        if nick == user[table_columns[0]]:
            users.pop(user["id"])
            return MSGS.on_deleted
    return MSGS.nick_not_registerd_error


##################################################
# RUNNING THE BOT                                #
##################################################

if __name__ == "__main__":
    utils.setLogging(LEVEL, LOGFILE)
    bot = IrcBot(HOST, PORT, NICK, CHANNELS, PASSWORD, tables=[users])
    bot.run()
Esempio n. 9
0
@utils.custom_handler("join")
def onEnter(nick, channel):
    print("OnEnter")
    if nick == NICK:
        print("Return by nick")
        return

    if nick not in conversations:
        print("Return by greeting")
        greeting = GREETINGS[random.randint(0, len(GREETINGS) - 1)]
        return f"{nick}: " + greeting

    print("Return by death")
    return (f"{nick}: Hi again! " +
            conversations[nick].log.split("\n")[-1].replace(
                f"{nick}:", "").replace(f"{NICK}:", "").strip())


async def onConnect(bot: IrcBot):
    await bot.join("#bots")
    await bot.send_message("Hello everyone!", "#bots")


if __name__ == "__main__":
    if TEST:
        test()
    else:
        bot = IrcBot("irc.libera.org", nick=NICK)
        bot.runWithCallback(onConnect)
Esempio n. 10
0
        Message(
            m["nick"], message=f"{m['filename']} has been received!", is_private=True
        )
    )


@utils.custom_handler("dccreject")
def on_dcc_reject(**m):
    log(f"Rejected!!! {m=}")


async def on_run(bot: IrcBot):
    log("STARTED!")
    # Startup Setup
    # await bot.sleep(1)
    # await bot.send_raw(f"OPER {NICK} {PASSWORD}")


if __name__ == "__main__":
    bot = IrcBot(
        HOST,
        PORT,
        NICK,
        CHANNELS,
        password=PASSWORD,
        dcc_host=DCC_HOST,
        use_ssl=PORT == 6697,
        tables=[configs],
    )
    bot.runWithCallback(on_run)