1
+ import json
2
+ import requests
3
+ import sys
4
+ import os
5
+ from os .path import dirname , abspath
6
+ d = dirname (dirname (abspath (__file__ )))
7
+ sys .path .append (os .path .join (d , "config" ))
8
+ import config as Config
9
+
10
+ headers = {'X-API-KEY' : Config .FLOWINTEL_API_KEY }
11
+
12
+ def request_post_flowintel (url , data , content_type = 'application/json' ):
13
+ headers ["Content-Type" ] = content_type
14
+ res = requests .post (f"{ Config .FLOWINTEL_URL } /api/case/{ url } " , json = data , headers = headers )
15
+ return res
16
+
17
+ def request_get_flowintel (url ):
18
+ res = requests .get (f"{ Config .FLOWINTEL_URL } /api/case/{ url } " , headers = headers )
19
+ return res
20
+
21
+
22
+ async def modify_case (bot , match , message , room , type ):
23
+ """Modify title or description of a case"""
24
+ args_list = match .args ()[1 :]
25
+ case_id = match .args ()[0 ]
26
+
27
+ data = {type : " " .join (arg for arg in args_list )}
28
+ res = request_post_flowintel (f"{ case_id } /edit" , data )
29
+ if "message" in res .json ():
30
+ loc_message = res .json ()["message" ]
31
+ else :
32
+ loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
33
+ last_command = message
34
+ await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
35
+ return last_command
36
+
37
+
38
+ async def case_check (bot , match , message , room ):
39
+ """All ckeck for case part"""
40
+ last_command = ""
41
+ if match .command ("create_case" ):
42
+ data = {"title" : " " .join (arg for arg in match .args ())}
43
+ res = request_post_flowintel ("create" , data )
44
+ if "message" in res .json ():
45
+ loc_message = res .json ()["message" ]
46
+ else :
47
+ loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
48
+ last_command = message
49
+ await bot .api .send_text_message (room .room_id , loc_message , reply_to = message .event_id )
50
+
51
+ if match .command ("case_title" ):
52
+ data = {"title" : " " .join (arg for arg in match .args ())}
53
+ res = request_post_flowintel ("title" , data )
54
+ if "message" in res .json ():
55
+ loc_message = res .json ()["message" ]
56
+ else :
57
+ loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
58
+ last_command = message
59
+ await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
60
+
61
+ if match .command ("case_id" ):
62
+ res = request_get_flowintel (match .args ()[0 ])
63
+ if "message" in res .json ():
64
+ loc_message = res .json ()["message" ]
65
+ else :
66
+ loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
67
+ last_command = message
68
+ await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
69
+
70
+ if match .command ("modify_title" ):
71
+ last_command = modify_case (bot , match , message , room , "title" )
72
+
73
+ if match .command ("modify_description" ):
74
+ last_command = modify_case (bot , match , message , room , "description" )
75
+
76
+ if match .command ("complete_case" ):
77
+ res = request_get_flowintel (f"{ match .args ()[0 ]} /complete" )
78
+ if "message" in res .json ():
79
+ loc_message = res .json ()["message" ]
80
+ else :
81
+ loc_message = f"```JSON\n { json .dumps (res .json (), indent = 2 )} \n ```"
82
+ last_command = message
83
+ await bot .api .send_markdown_message (room .room_id , loc_message , reply_to = message .event_id )
84
+
85
+
86
+
87
+ if last_command :
88
+ return last_command
0 commit comments