Пример #1
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)
    #general_command_handler = MRegexHandler(";", commandHandler)

    # Add a regex handler waiting for the word Hi
    hi_handler = MRegexHandler("Hi", hi_callback)
    bot.add_handler(hi_handler)

    # Add a regex handler waiting for the echo command
    echo_handler = MCommandHandler("echo", echo_callback)
    bot.add_handler(echo_handler)

    # Add a regex handler waiting for the die roll command
    dieroll_handler = MCommandHandler("d", dieroll_callback)
    bot.add_handler(dieroll_handler)

    wikipedia_handle = MCommandHandler("wikipedia",wikipedia_callback)
    bot.add_handler(wikipedia_handle)
    # Start polling
    bot.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other threads
    while True:
        abc = "abc" # MODIFIED
Пример #2
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(Config.BOT_USER_NAME, Config.BOT_PASS_WORD,
                       Config.BOT_SERVER_URL)

    # Add a regex handler waiting for the user text
    bot.add_handler(MRegexHandler(".*", echo_callback))

    # Start polling
    bot.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other threads
    while True:
        input()
Пример #3
0
def main():
    # Create an instance of the MatrixBotAPI
    logging.debug('matrix config:\n%s', matrix_config)
    homeserver = "https://{server}:{port}".format(
        server=matrix_config['homeserver'], port=int(matrix_config['port']))
    bot = MatrixBotAPI(matrix_config['username'], matrix_config['password'],
                       homeserver)

    # Add a !zabbix handler
    zabbix_handler = MRegexHandler("^!zabbix", zabbix_callback)
    bot.add_handler(zabbix_handler)

    # Add a !dnsjedi handler
    dnsjedi_handler = MRegexHandler("^!dnsjedi", dnsjedi_callback)
    bot.add_handler(dnsjedi_handler)

    # Start polling
    while True:
        thread = bot.start_polling()
        thread.join()
        logging.warning(
            'thread died, waiting five seconds before connecting again...')
        time.sleep(5)
Пример #4
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)

    # Add a regex handler waiting for the ! symbol at the beginning of the
    # message.
    tick_handler = MRegexHandler("^!.*", tick_callback)
    bot.add_handler(tick_handler)

    # Start polling.
    bot.start_polling()

    # Infinite sleep while the bot runs in other threads.
    while True:
        time.sleep(1)
Пример #5
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)

    # Add a regex handler waiting for the word Hi
    hi_handler = MRegexHandler("Hi", hi_callback)
    bot.add_handler(hi_handler)

    # Add a regex handler waiting for the echo command
    echo_handler = MCommandHandler("echo", echo_callback)
    bot.add_handler(echo_handler)

    # Start polling
    bot.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other threads
    while True:
        input()
    def __init__(self, server, username, password):
        # This is a bit broken. We don't want to hardcode any room, so set this as soon as we get the first message.
        # The bot is talking to that room then
        self.primary_room = None

        self.receive_handler = None
        self.reset_handler = None

        self.bot = MatrixBotAPI(username, password, server.rstrip("/"))

        # Add a regex handler for every message
        msg_handler = MRegexHandler("^(?!\\!).+", self.__msg_callback)
        self.bot.add_handler(msg_handler)
        reset_handler = MCommandHandler("reset", self.__reset_callback)
        self.bot.add_handler(reset_handler)
        preset_handler = MCommandHandler("preset", self.__preset_callback)
        self.bot.add_handler(preset_handler)

        self.bot.start_polling()
Пример #7
0
def main():
    """Main function.
    """
    zabbix.logging = logging
    matrix.logging = logging
    config['config'] = args['config']

    # Create an instance of the MatrixBotAPI
    homeserver = "https://{server}:{port}".format(
        server=matrix_config['homeserver'], port=int(matrix_config['port']))
    rooms = list(config['zabbix-bot'].keys())
    token = None
    username = matrix_config['username']
    if 'token' in matrix_config:
        token = matrix_config['token']
        username = matrix_config['user_id']

    bot = MatrixBotAPI(
        username,
        matrix_config['password'],
        homeserver,
        rooms=rooms,
        token=token,
    )

    # Add a !zabbix handler
    zabbix_handler = MRegexHandler("^!zabbix", zabbix_callback)
    bot.add_handler(zabbix_handler)

    # Start polling
    while True:
        thread = bot.start_polling()
        thread.join()
        logging.warning(
            'thread died, waiting five seconds before connecting again...')
        time.sleep(5)
Пример #8
0
def main():
    profiles = Profile.select()
    for profile in profiles:
        cookies = json.loads(
            profile.cookies_json) if profile.cookies_json else None
        conn = UmsConnection(profile.phone_number, profile.password, cookies)
        CONNECTIONS.append((profile, conn))

    hi_handler = MRegexHandler("hi", hi_callback)
    BOT.add_handler(hi_handler)

    help_handler = MRegexHandler("^(help|h)$", help_callback)
    BOT.add_handler(help_handler)

    list_chats_handler = MRegexHandler("^list$", list_chats_callback)
    BOT.add_handler(list_chats_handler)

    print_chat_handler = MRegexHandler("^print [\w\.\+]+ ?\d*$",
                                       print_chat_callback)
    BOT.add_handler(print_chat_handler)

    add_or_update_profile_handler = MRegexHandler(
        "^profile \w+ \d+ \w+$", add_or_update_profile_callback)
    BOT.add_handler(add_or_update_profile_handler)

    list_profiles_handler = MRegexHandler("^profiles$", list_profiles_callback)
    BOT.add_handler(list_profiles_handler)

    get_current_profile_handler = MRegexHandler("^profile$",
                                                get_current_profile_callback)
    BOT.add_handler(get_current_profile_handler)

    select_profile_handler = MRegexHandler("^select \w+$",
                                           select_profile_callback)
    BOT.add_handler(select_profile_handler)

    remove_profile_handler = MRegexHandler("^remove \w+$",
                                           remove_profile_callback)
    BOT.add_handler(remove_profile_handler)

    enter_captcha_handler = MRegexHandler("^captcha \w+$",
                                          enter_captcha_callback)
    BOT.add_handler(enter_captcha_handler)

    get_captcha_handler = MRegexHandler("^captcha$", get_captcha_callback)
    BOT.add_handler(get_captcha_handler)

    BOT.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other threads
    while True:
        input()
Пример #9
0

def alsobot_test_callback(room, event):
    server = MinecraftServer(MINECRAFTSERVERNAME)
    status = server.status()
    info_string = "The server has {0} players and replied in {1} ms".format(
        status.players.online, status.latency)
    room.send_text(info_string)


if __name__ == '__main__':
    USERNAME = os.getenv('ALSOBOTUSER', "")
    PASSWORD = os.getenv('ALSOBOTPASSWORD', "")
    SERVER = os.getenv('ALSOBOTSERVER', "")
    MINECRAFTSERVER = os.getenv('ALSOBOTMINECRAFTSERVER', "")
    if (USERNAME or PASSWORD or SERVER or ALSOBOTMINECRAFTSERVER) == "":
        #print("{} {} {}".format(USERNAME, PASSWORD, SERVER))
        print(
            "Set ALSOBOTUSER, ALSOBOTPASSWORD, ALSOBOTSERVER, or ALSOBOTMINECRAFTSERVER environment variables!"
        )
        sys.exit()

    matrix_bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)
    alsobot = Alsobot(MINECRAFTSERVER)
    alsobot_test_handler = MRegexHandler("alsobot", alsobot.default_response)
    matrix_bot.add_handler(alsobot_test_handler)
    matrix_bot.start_polling()

    while True:
        input()