53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
import mattermostdriver.exceptions
|
|
|
|
from mattermost_client import ChannelApi, MMApi
|
|
|
|
|
|
def send_message(file_id, file_info, message):
|
|
channel_id = file_info["originating_mm_post_channel_id"]
|
|
post_id = file_info["originating_mm_post_id"]
|
|
|
|
# TODO Comment below line, this is for testing purposes
|
|
# channel_id = MMApi().get_channel_id("bestuur-dev")
|
|
channel = ChannelApi(
|
|
channel_id=channel_id,
|
|
user=mattermost.users["flynn"],
|
|
)
|
|
|
|
prefix = ""
|
|
# This is bestuur-INTERN where you can only post when you prefix you message with a '!'
|
|
if file_info["originating_mm_post_channel_id"] == "hrx6pgfswjbttcj8nim3jrwe7w":
|
|
prefix = "! "
|
|
|
|
try:
|
|
channel.create_threaded_post(
|
|
post_id,
|
|
f"{prefix}{message}",
|
|
)
|
|
except mattermostdriver.exceptions.InvalidOrMissingParameters as e:
|
|
# This will occur when we try to react to a file in a channel that is not the same as the originating channel.
|
|
unique_post_url = f"https://mattermost.zeus.gent/zeus/pl/{post_id}"
|
|
channel.create_post(
|
|
f"{unique_post_url}\n\n{message}",
|
|
)
|
|
|
|
|
|
def report_newly_found_file(file_id, file_info):
|
|
message = f"I found a new CodiMD file in this post! Making work of putting it on gitlab :)\n - Requested location in the [drive](https://git.zeus.gent/bestuur/drive): {file_info['metadata']['sync-to']}"
|
|
send_message(file_id, file_info, message)
|
|
|
|
|
|
def report_newly_found_but_invalid_file(file_id, file_info):
|
|
message = """Hi there! :wave:
|
|
I'm your friendly neighbourhood document sync bot.
|
|
I could synchronize this CodiMD file automatically to our Gitlab DRIVE for safekeeping, but the necessary metadata block is not present.
|
|
You can easily add the correct info and I will do the rest of the work for you!
|
|
|
|
Just add the following lines to your file, the location in your file is not important but at the top would be my recommendation.
|
|
|
|
```
|
|
:::spoiler Gitlab sync
|
|
- sync-to: <a valid path on the DRIVE, for ex.: verslagen/21-22/2022-05-13.md>
|
|
:::
|
|
```"""
|
|
send_message(file_id, file_info, message)
|