コード例 #1
0
ファイル: basic_usage.py プロジェクト: matheusfillipe/ircbot
# Simple echo bot example with random color echo because why not
import logging
from IrcBot.bot import IrcBot, utils, Color, Message

utils.setPrefix("'")
utils.setLogging(logging.DEBUG)
utils.setMaxArguments(25) # Accept 25 command arguments at max

@utils.arg_command("echo", "Echo command", "It will return all passed arguments colored: echo [arg1] [arg2] ....")
def echo(args, message):
    utils.log("echoing")
    return " ".join(utils.m2list(args)) # m2list converts a re.match to a list

@utils.arg_command("rainbow", "Echo but with multiple colors", "rainbow [text]")
def rainbow(args, message):
    utils.log("rainbowing")
    return "".join([Color(char, Color.random()).str for char in " ".join(utils.m2list(args))])

@utils.arg_command("send", "Sends a delayed message to a user or channel", "This command can schedule the sending of a message: send [channel|user] [delay] [message]")
async def send(bot: IrcBot, args, message): # If a handler is async, its first argument will be the bot itself
    args = utils.m2list(args)
    if len(args) < 3:
        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:])))
コード例 #2
0
ファイル: cleverbot.py プロジェクト: matheusfillipe/ircbot
@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)
コード例 #3
0
import itertools
import logging
from IrcBot.bot import IrcBot, utils, Color, Message
from github import Github

NICK = "_githubbot"
HOST = "irc.example.org"
CHANNELS = ["#bots", "#test"]

gh = Github("ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

utils.setPrefix(":")
utils.setLogging(logging.DEBUG)
utils.setMaxArguments(25)  # Accept 25 command arguments at max
utils.setSimplifyCommands(False)


def is_mine(message):
    return message.sender_nick == NICK.split("/")[0]


def shell(cmd):
    try:
        return subprocess.check_output(cmd, shell=True).decode()
    except Exception as e:
        print("Shell command erroed: ", e)
        print(cmd)


@utils.arg_command("gh", "Searches my github repositories", "gh [query]")
def my_search_gh(args, message):