]> git.somenet.org - pub/jan/mattermost.git/blob - somebot/modules/WSWikiUpload.py
TODO [somebot] WS:WikiUpload
[pub/jan/mattermost.git] / somebot / modules / WSWikiUpload.py
1 # Mattermost Bot.
2 #  Copyright (c) 2016-2020 by Someone <someone@somenet.org> (aka. Jan Vales <jan@jvales.net>)
3 #  published under MIT-License
4
5 import json
6
7
8 from AbstractWSHandler import *
9 class WSWikiUpload(AbstractWSHandler):
10     NAME = "wikiupload"
11
12     def on_WS_EVENT(self, data):
13         if data["event"] != "posted" or 'file_ids' not in data['data']['post']:
14             return
15
16         data['data']['post']=json.loads(data['data']['post'])
17
18         msg  = "``BOT-AUTODELETE-FAST``\nIs das n file, das retainenswert is?"
19         att = [{
20               "text": "Als uploader_in kannst du das File mit einem Click auf Upload! ins Wiki hochladen",
21               "actions": [
22                 {
23                   "name": "Retainenswert",
24                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_yes" } }
25                 }, {
26                   "name": "Blödsinn",
27                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_no" } }
28                 }, {
29                   "name": "Upload (Uploader_in only)",
30                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_upload" } }
31                 }, {
32                   "name": "Nicht retainenswert (Uploader_in only)",
33                   "integration": { "url": self.URL+"/interactive", "context": { "action": "click_nope" } }
34                 }
35               ]
36             },
37           ]
38
39         self.bot.api.create_post(data['data']['post']['channel_id'], msg, props={"from_webhook":"true", "attachments":att}, root_id=data['data']['post']['id'])
40
41
42
43     def on_POST_interactive(self, request, data):
44         import pprint
45         pprint.pprint(request)
46         pprint.pprint(data)
47
48         if data["context"]["action"] == "click_nope":
49             request.respond(200, {"update":{"message":"``BOT-AUTODELETE-FAST`` Uploader_in hat gegen einen wiki-upload entschieden. :(", "props":{}}})
50
51         elif data["context"]["action"] == "click_upload":
52             request.respond(200, {"ephemeral_text": "Du bist leider ned der/die uploader_in :("})
53
54         elif data["context"]["action"] == "click_yes":
55             request.respond(200, {"ephemeral_text": "Deine Stimme wurde gezählt - vielleicht TODO"})
56
57         elif data["context"]["action"] == "click_no":
58             request.respond(200, {"ephemeral_text": "Deine Stimme wurde gezählt - vielleicht TODO"})
59