Comments (3)
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.
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.
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)
- RuntimeError: this event loop is already running. HOT 9
- No connection with docker image 2.0.0 and MM7.1.3 HOT 2
- Improvement: Add `type` optional param for `create_post(...)` function HOT 7
- Unable to run concurrent asyncio processes HOT 5
- [Question] Register plugins at runtime HOT 1
- Scheduled responses to channel instead of reply HOT 5
- How to send files to bot directly for some postpone processing? HOT 3
- HTTP/1.1 404 Not Found : Wrong api endpoint HOT 4
- dev requirements inside main project HOT 3
- [Feature Request] Handler for message editions HOT 1
- Need to fix issue flagged when using latest Pytype HOT 2
- Websocket HOT 3
- Legal way to get raw events HOT 6
- Mandatory MATTERMOST_PORT breaks MATTERMOST_URL with subpaths HOT 2
- Disable httpx logging? HOT 2
- Reading previously sent messages HOT 1
- Bot fails to respond with copied ping if username is capitalized HOT 2
- Import plugins from separate files
- How to get displayed channel name HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mmpy_bot.