Skip to content
Snippets Groups Projects
Commit 206b8937 authored by Antoine Barbare's avatar Antoine Barbare
Browse files

pica bot

parent 43fb7421
No related branches found
No related tags found
No related merge requests found
FROM python
WORKDIR /bot
COPY picasoft /bot/picasoft
COPY mattermost_bot_settings.py /bot
RUN pip install mattermost_bot && \
apt-get update && \
apt-get install -y python-virtualenv && \
virtualenv venv && \
. venv/bin/activate
ENV BOT_URL="https://team.picasoft.net/api/v3"
#ENV BOT_LOGIN="<account email>"
#ENV BOT_PASSWORD="<account password>"
ENV BOT_TEAM="bot"
ENV PLUGINS='picasoft.plugins'
ENV MATTERMOST_BOT_SETTINGS_MODULE=mattermost_bot_settings
CMD matterbot
import os
BOT_URL = os.environ['BOT_URL']
BOT_LOGIN = os.environ['BOT_LOGIN']
BOT_PASSWORD = os.environ['BOT_PASSWORD']
BOT_TEAM = os.environ['BOT_TEAM']
DEBUG = True
PLUGINS = [plugin for plugin in os.environ['PLUGINS'].split(',')]
VERSION = (0, 0, 1)
def get_version():
return '.'.join(map(str, VERSION))
# -*- coding: utf-8 -*-
import re
import requests
import json
from mattermost_bot.bot import listen_to
@listen_to('\\\link ^(http[s]?://[\S]*) (.*)*$')
def link_display(message, url, display):
payload = {
'lsturl': url,
'format': 'json'
}
r = requests.post('https://lstu.fr/a', data=payload)
r = json.loads(r.text)
message.comment('['+display+']'+'('+r['short']+')')
@listen_to('\\\link ^(http[s]?://[\S]*)$')
def link(message, url):
payload = {
'lsturl': url,
'format': 'json'
}
r = requests.post('https://lstu.fr/a', data=payload)
r = json.loads(r.text)
message.comment(r['short'])
@listen_to('\\\link (.*\\n)*')
def link_multiple(message, opt):
for elt in message.get_message().split('\n'):
mes = elt.replace('\\link ','')
if re.match('^(http[s]?://[\S]*)$', mes):
link(message, mes)
else:
mes=mes.split(' ')
link_display(message, mes[0], ' '.join(mes[1:]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment