GithubHelp home page GithubHelp logo

Comments (3)

unode avatar unode commented on August 30, 2024

How are you starting the bot?

Can you provide a minimal working example?

And in:

    self.thread = threading.Thread(target=run, args=()) 

what is run? Not the same as self.run.

from mmpy_bot.

M4tyr0 avatar M4tyr0 commented on August 30, 2024

Hi,
here is a minimal (not) working example. For security reasons, I removed the API Key and the URL:


import threading
import asyncio
import time

from mmpy_bot import Bot, Settings
from mmpy_bot.plugins import (
    HelpPlugin
)

class MMBot():

    def __init__(self, api_token ):
      self.api_token = api_token
      return
    

    def run_thread(self):       
        # Activate Eventloop for current thread
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)

        self.bot = Bot(
            settings=Settings(
                MATTERMOST_URL = "URL",
                MATTERMOST_PORT = 443,
                BOT_TOKEN = self.api_token, #@cluster-bot
                BOT_TEAM = "test",
                SSL_VERIFY = True,
            ),  # Either specify your settings here or as environment variables.
            plugins=[HelpPlugin()],  # Add your own plugins here.
        )  

        print('Starting Mattermost') 
        self.bot.run()

        self.loop.stop()
        self.loop.close()
        
        print('Mattermost Run exited')
        return


    ########################################################
    def start(self):
        self.thread = threading.Thread(target=self.run_thread, args=())    
        self.thread.start()           

    def stop(self):
        self.bot.stop()        
        self.thread.join()


if __name__ == '__main__':
    print('Create Bot')
    bot = MMBot("API_KEY")

    print('Start Bot:')
    bot.start()

    time.sleep(10)
    bot.stop()

    print('Mattermost Bot loop stopped')

Output:

Create Bot
Start Bot:
[05/13/2024 13:35:29][httpx][INFO] HTTP Request: GET URL/api/v4/users/me "HTTP/1.1 200 OK"
Starting Mattermost
[05/13/2024 13:35:29][mmpy.bot][INFO] Starting bot Bot.
[05/13/2024 13:35:29][mmpy.threadpool][INFO] Scheduler thread started.
[05/13/2024 13:35:29][mattermostautodriver.websocket][INFO] Websocket authentification OK
[05/13/2024 13:35:39][mmpy.bot][INFO] Stopping bot.
[05/13/2024 13:35:39][mmpy.threadpool][INFO] Stopping threadpool, waiting for threads...
[05/13/2024 13:35:39][mmpy.threadpool][INFO] Scheduler thread stopped.
[05/13/2024 13:35:39][mmpy.threadpool][INFO] Threadpool stopped.

from mmpy_bot.

unode avatar unode commented on August 30, 2024

Thanks, I was able to replicate the error.

Seems like there are multiple bugs at play. One fix is now in #518 and will be merged in the future. This allows the bot to stop but there's a more complicated issue behind.

At the core of mattermostautodriver the driver currently blocks until a new message is received. This means that there is (in the worst case) a 5 minute delay (timeout) between the bot trying to stop and actually exiting. Worst case because with the patch in #518 the bot will exit if a message is sent by Mattermost before this.

from mmpy_bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.