]>
us-delaporte.pagekite.me Git - matrix-goal-bot.git/blob - bot.py
d57358d09a4df26dc55ab9a92475ea595e50ec64
1 from datetime
import datetime
as dt
5 import simplematrixbotlib
as botlib
7 from goals
.db
import Data
, pretty_print
10 SERVER
= os
.environ
.get('MATRIX_SERVER')
11 BOT_NAME
= os
.environ
.get('GOAL_BOT')
12 BOT_PWD
= os
.environ
.get('GOAL_BOT_PWD')
14 DATE_FORMAT
= '%Y-%m-%d'
17 return dt
.now().strftime(DATE_FORMAT
)
19 creds
= botlib
.Creds(SERVER
, BOT_NAME
, BOT_PWD
)
20 bot
= botlib
.Bot(creds
)
23 logger
= logging
.getLogger(__name__
)
24 logging
.basicConfig(filename
='goals.log', encoding
='utf-8', level
=logging
.DEBUG
)
25 logging
.getLogger('nio').setLevel(logging
.WARNING
)
27 async def do_goal(match
):
37 add-task ID - add a task under the goal specified by ID
38 add-vision - add a new vision (collection of goals)
39 close-goal ID - mark goal done by ID
40 close-vision ID - mark vision as complete by ID
41 done ID - mark task done by ID
42 list - list incomplete goals
43 list-all - list everything
44 list-done - list completed goals
45 print GOAL_ID - print a goal and all tasks
46 print-vision ID - print a vision and all goals
47 set-vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID
48 visions - list incomplete visions
51 if match
.command('setup'):
52 result
= Data().setup()
55 if match
.command('add'):
56 new
= ' '.join(match
.args()[1:])
57 result
= Data().add_goal(new
)
58 return [f
'Goal added with id {result}']
60 if match
.command('list'):
61 goals
= Data().get_all_goals()
62 results
= ['# Goals list...']
64 results
.append(str(goal
))
68 if match
.command('list-done'):
69 goals
= Data().get_done_goals()
70 results
= ['# Completed Goals...']
72 results
.append(str(goal
))
76 if match
.command('add-task'):
77 goal_id
= int(match
.args()[1])
78 new
= ' '.join(match
.args()[2:])
79 result
= Data().add_task(goal_id
=goal_id
, name
=new
)
80 goal
,tasks
= Data().get_goal(goal_id
)
81 results
= pretty_print(goal
, tasks
)
83 # return [f'Added task with id {result}']
85 if match
.command('add-vision'):
86 new
= ' '.join(match
.args()[1:])
87 result
= Data().add_vision(new
)
88 return [f
'Vision added with id {result}']
90 if match
.command('print'):
91 goal_id
= int(match
.args()[1])
92 logger
.debug(f
'Searching for goal {goal_id}...')
93 goal
,tasks
= Data().get_goal(goal_id
)
94 results
= pretty_print(goal
, tasks
)
98 if match
.command('print-vision'):
99 get_id
= int(match
.args()[1])
100 vision
,goals
= Data().get_vision(get_id
)
101 results
= pretty_print(vision
, goals
)
104 if match
.command('close-goal'):
105 goal_id
= int(match
.args()[1])
106 vision_id
= Data().complete_goal(goal_id
)
107 vision
,goals
= Data().get_vision(vision_id
)
108 results
= pretty_print(vision
, goals
)
111 if match
.command('close-vision'):
112 vision_id
= int(match
.args()[1])
113 Data().complete_vision(vision_id
)
114 vision
,goals
= Data().get_vision(vision_id
)
115 results
= pretty_print(vision
, goals
)
119 if match
.command('done'):
120 task_id
= int(match
.args()[1])
121 goal_id
= Data().complete_task(task_id
)
122 goal
,tasks
= Data().get_goal(goal_id
)
123 results
= pretty_print(goal
, tasks
)
126 if match
.command('list-all'):
127 goals
= Data().get_all_goals()
128 results
= ['# Everything is...']
130 _
,tasks
= Data().get_goal(goal
.id)
131 details
= pretty_print(goal
, tasks
)
135 if match
.command('visions'):
136 items
= Data().get_all_visions()
137 results
= ['# Visions']
139 results
.append('-- No current visions --')
146 if match
.command('set-vision'):
147 goal_id
= int(match
.args()[1])
148 vision_id
= int(match
.args()[2])
149 Data().assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
150 vision
,goals
= Data().get_vision(vision_id
)
151 results
= pretty_print(vision
, goals
)
154 return [do_goal
.__doc
__]
156 @bot.listener.on_message_event
157 async def goals(room
, message
):
158 match
= botlib
.MessageMatch(room
, message
, bot
, PREFIX
)
160 if not match
.is_not_from_this_bot() and match
.prefix():
165 result_lines
= await do_goal(match
)
166 for line
in result_lines
:
167 await bot
.api
.send_text_message(
168 room
.room_id
, str(line
))
169 except Exception as ex
:
170 return ['Ye cannot get ye flask.']