Beispiel #1
0
def main():
    configfp = open('config.json')
    cfg = json.load(configfp)
    USERNAME, PASSWORD, SERVER = cfg["username"], cfg["password"], cfg[
        "server"]

    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)

    hottopic_handler = MCommandHandler("hottopics", hottopic_callback)
    bot.add_handler(hottopic_handler)

    pins_handler = MCommandHandler("pins", pins_callback)
    bot.add_handler(pins_handler)

    lcpu_event_handler = MCommandHandler("event", lcpu_event_callback)
    bot.add_handler(lcpu_event_handler)

    bot.add_handler(MCommandHandler("readpost", readpost_callback))

    # Start polling
    bot.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other
    # threads
    while True:
        sleep(600)
        rooms = bot.client.get_rooms().values()
        do_timer_events(rooms)
Beispiel #2
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
def main():

    # Load configuration
    config = configparser.ConfigParser()
    config.read("config.ini")
    username = config.get("Matrix", "Username")
    password = config.get("Matrix", "Password")
    server = config.get("Matrix", "Homeserver")

    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(username, password, server)

    # Add a regex handler waiting for the echo command
    dish_handler = MCommandHandler("dish", dish_points_callback)
    bot.add_handler(dish_handler)

    help_handler = MCommandHandler("pointshelp", points_help_callback)
    bot.add_handler(help_handler)

    # Start polling
    bot.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other threads
    while True:
        input()
Beispiel #4
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)

    # Set avatar / fix this later
    # bot.set_matrix_avatar(AVATAR_URL)

    # Hello testing handler
    hello_handler = MCommandHandler("hello", hello_callback)
    bot.add_handler(hello_handler)

    # Host inspection handler
    hi_handler = MCommandHandler("hi", hi_callback)
    bot.add_handler(hi_handler)

    # Subdomain inspection handler
    si_handler = MCommandHandler("si", si_callback)
    bot.add_handler(si_handler)

    # Help handler
    help_handler = MCommandHandler("helpmonty", help_callback)
    bot.add_handler(help_handler)

    # POST handler
    post_handler = MCommandHandler("post", post_callback)
    bot.add_handler(post_handler)

    # Start polling
    bot.start_polling()

    # Infinitely read stdin to stall main thread while the bot runs in other threads
    while True:
        input()
def register_bot_callbacks(bot: MatrixBotAPI):
    """
    Define all handlers and register callbacks.

    :param MatrixBotAPI bot: bot instance
    """
    bot.add_handler(MCommandHandler('meh', bot_cmd_meh))
    bot.add_handler(MCommandHandler('fug', bot_cmd_fug))
    bot.add_handler(MCommandHandler('трави', bot_cmd_bashorg))
Beispiel #6
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)

    member_handler = MMemberHandler(member_callback)
    bot.add_handler(member_handler)

    faq_handler = MCommandHandler("faq", faq_callback)
    bot.add_handler(faq_handler)

    faq1_handler = MCommandHandler("фаг", faq_callback)
    bot.add_handler(faq1_handler)

    bot.start_polling()

    while True:
        input()
Beispiel #7
0
def main():
    global bot
    # Load configuration
    config = configparser.ConfigParser()
    config.read("config.ini")
    username = config.get("Matrix", "Username")
    password = config.get("Matrix", "Password")
    server = config.get("Matrix", "Homeserver")

    # Start bot
    bot = MatrixBotAPI(username, password, server)

    m_newpoll_handler = MCommandHandler('newpoll', newpoll_callback)
    bot.add_handler(m_newpoll_handler)

    m_ongoing_poll_handler = AllMessageHandler(ongoing_poll_callback)
    bot.add_handler(m_ongoing_poll_handler)

    m_startpoll_handler = MCommandHandler('startpoll', startpoll_callback)
    bot.add_handler(m_startpoll_handler)

    m_add_response_handler = MCommandHandler('add', add_response_to_poll)
    bot.add_handler(m_add_response_handler)

    m_info_handler = MCommandHandler('info', info_callback)
    bot.add_handler(m_info_handler)

    m_endpoll_handler = MCommandHandler('endpoll', endpoll_callback)
    bot.add_handler(m_endpoll_handler)

    m_results_handler = MCommandHandler('results', results_callback)
    bot.add_handler(m_results_handler)

    m_vote_handler = MCommandHandler('vote', vote_callback)
    bot.add_handler(m_vote_handler)

    m_pollhelp_handler = MCommandHandler('pollhelp', pollhelp_callback)
    bot.add_handler(m_pollhelp_handler)

    m_leave_handler = MCommandHandler('leave', leave_callback)
    bot.add_handler(m_leave_handler)

    bot.start_polling()
    print("Pollbot started!")

    while True:
        try:
            input()
        except EOFError:
            print("EOF access")
    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()
Beispiel #9
0
def main():
    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(USERNAME, PASSWORD, SERVER)

    for x in dict(config.items("TEXT_COMMANDS")):
        text_handler = MCommandHandler(x, text_callback)
        bot.add_handler(text_handler)

    photo_handler = MCommandHandler("photo", photo_callback)
    bot.add_handler(photo_handler)

    reinit_handler = MCommandHandler("reinit", reinit)
    bot.add_handler(reinit_handler)

    helpfile_handler = MCommandHandler("help", helpfile_callback)
    bot.add_handler(helpfile_handler)

    # Start polling
    bot.start_polling()
    print("Polling started")

    while True:
        input()
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()
Beispiel #11
0
def main():
    # Load configuration
    config = configparser.ConfigParser()
    config.read("config.ini")
    username = config.get("Matrix", "Username")
    password = config.get("Matrix", "Password")
    server = config.get("Matrix", "Homeserver")

    # Start bot
    bot = MatrixBotAPI(username, password, server)

    m_newpoll_handler = MCommandHandler('newpoll', newpoll_callback)
    bot.add_handler(m_newpoll_handler)

    m_ongoing_poll_handler = AllMessageHandler(ongoing_poll_callback)
    bot.add_handler(m_ongoing_poll_handler)

    m_startpoll_handler = MCommandHandler('startpoll', startpoll_callback)
    bot.add_handler(m_startpoll_handler)

    m_info_handler = MCommandHandler('info', info_callback)
    bot.add_handler(m_info_handler)

    m_endpoll_handler = MCommandHandler('endpoll', endpoll_callback)
    bot.add_handler(m_endpoll_handler)

    m_results_handler = MCommandHandler('results', results_callback)
    bot.add_handler(m_results_handler)

    m_vote_handler = MCommandHandler('vote', vote_callback)
    bot.add_handler(m_vote_handler)

    m_pollhelp_handler = MCommandHandler('pollhelp', pollhelp_callback)
    bot.add_handler(m_pollhelp_handler)


    bot.start_polling()
    print("Pollbot started!")
    def sig_handle(signo, frame):
        global BOT_CONT
        print ("Gracefully shutting down")
        BOT_CONT = False
    signal.signal(signal.SIGINT, sig_handle)
    while BOT_CONT:
        signal.pause()
Beispiel #12
0
def main():
    # Load configuration
    config = configparser.ConfigParser()
    config.read("config.ini")
    username = config.get("Matrix", "Username")
    password = config.get("Matrix", "Password")
    server = config.get("Matrix", "Homeserver")

    # Start bot
    bot = MatrixBotAPI(username, password, server)

    m_newmotion_handler = MCommandHandler('motion', newmotion_callback)
    bot.add_handler(m_newmotion_handler)

    m_ongoing_motion_handler = AllMessageHandler(ongoing_motion_callback)
    bot.add_handler(m_ongoing_motion_handler)

    m_startmotion_handler = MCommandHandler('startmotion', startmotion_callback)
    bot.add_handler(m_startmotion_handler)

    m_info_handler = MCommandHandler('info', info_callback)
    bot.add_handler(m_info_handler)

    m_endmotion_handler = MCommandHandler('endmotion', endmotion_callback)
    bot.add_handler(m_endmotion_handler)

    m_results_handler = MCommandHandler('results', results_callback)
    bot.add_handler(m_results_handler)

    m_vote_handler = MCommandHandler('vote', vote_callback)
    bot.add_handler(m_vote_handler)

    m_motionhelp_handler = MCommandHandler('motionhelp', motionhelp_callback)
    bot.add_handler(m_motionhelp_handler)


    bot.start_polling()
    print("Motionbot started!")

    while True:
        input()
def run_bot(modules):
    global bot

    # Create an instance of the MatrixBotAPI
    bot = MatrixBotAPI(os.environ['MATRIX_USERNAME'],
                       os.environ['MATRIX_PASSWORD'],
                       os.environ['MATRIX_SERVER'])

    # Add some helper functions:
    # Sends a message to notifyroom
    def send_notification(self, notification, notifyroom):
        room = self.get_room(notifyroom)
        room.send_text(notification)

    # Lookup room object for room id. Bot must be present in room.
    def get_room(self, room_id):
        print('Looking up room ', room_id, '...')
        for id, room in bot.client.get_rooms().items():
            if room_id in room.aliases:
                return room
        print('Error finding room', room_id, ' - is bot present on it?')

    bot.send_notification = types.MethodType(send_notification, bot)
    bot.get_room = types.MethodType(get_room, bot)

    # Add a handler waiting for any command
    modular_handler = MCommandHandler("", modular_callback)
    bot.add_handler(modular_handler)

    # Store modules in bot to be accessible from other modules
    bot.modules = modules

    print('Starting modules..')
    # Call matrix_start on each module
    for modulename, moduleobject in modules.items():
        if "matrix_start" in dir(moduleobject):
            try:
                moduleobject.matrix_start(bot)
            except:
                traceback.print_exc(file=sys.stderr)

    # Start polling
    bot.start_polling()

    bot.running = True
    signal.signal(signal.SIGINT, signal_handler)
    print('Bot running, press Ctrl-C to quit..')
    # Wait until ctrl-c is pressed
    pollcount = 0
    while bot.running:
        for modulename, moduleobject in modules.items():
            if "matrix_poll" in dir(moduleobject):
                try:
                    moduleobject.matrix_poll(bot, pollcount)
                except:
                    traceback.print_exc(file=sys.stderr)

        time.sleep(10)
        pollcount = pollcount + 1

    # Call matrix_stop on each module
    for modulename, moduleobject in modules.items():
        if "matrix_stop" in dir(moduleobject):
            try:
                moduleobject.matrix_stop(bot)
            except:
                traceback.print_exc(file=sys.stderr)