]>
apps.delaporte.us Git - matrix-goal-bot.git/blob - matrix_goal_bot/bot.py
9 extra.help - show extended help
11 clear - clear completed tasks under current goal
12 task ID - add a task under the goal specified by ID
13 close ID - mark goal done by ID
14 done ID - mark task done by ID
15 list - list incomplete goals
16 print GOAL_ID - print a goal and all tasks
21 add.vision - add a new vision (collection of goals)
22 close.vision ID - mark vision as complete by ID
23 dump - dump the full data set - BEWARE - so many messages
24 later VISION_ID - put off all goals in VISION for 14 days
25 list.later - list all 'later' goals
26 print.vision ID - print a vision and all goals
27 set.vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID
28 visions - list incomplete visions
29 list.done - list completed goals
30 remove ID - remove a task by ID
31 start GOAL_ID - un-put-off a goal (reverse of later)
32 visionless - list goals with no set vision
33 wins - list recently completed goals
37 from datetime
import datetime
as dt
41 import simplematrixbotlib
as botlib
43 from .db
import Data
, pretty_print
45 DATE_FORMAT
= '%Y-%m-%d'
48 return dt
.now().strftime(DATE_FORMAT
)
50 logger
= logging
.getLogger(__name__
)
53 'Ye cannot get ye flask.',
54 'Ye flask must be load bearing, or something...',
58 'How are you gentlemen?',
59 'All your base are belong to us.',
60 'You have been eaten by a groo.'
64 def __init__(self
, matrix_server
,
70 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
71 self
.bot
= botlib
.Bot(creds
)
72 self
.prefix
= bot_prefix
73 self
.data
= Data(db_file
)
76 logger
.debug('Running goal bot...')
79 async def handle_message(self
, room
, message
):
80 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
82 if not match
.is_not_from_this_bot():
83 # Let's not talk to our-self
86 logger
.debug(f
'Message: {message}')
87 if not match
.prefix():
88 logger
.debug(f
'{message} - did not match {self.prefix}')
92 result_lines
= await self
._handle
_match
(match
)
93 for line
in result_lines
:
94 await self
.bot
.api
.send_text_message(
95 room
.room_id
, str(line
))
96 except Exception as ex
:
97 logger
.warn(f
'Caught exception: {str(ex)}')
98 dumb_msg_idx
= len(str(ex
)) % len(snark
)
99 dumb_msg
= snark
[dumb_msg_idx
]
100 await self
.bot
.api
.send_text_message(
101 room
.room_id
, dumb_msg
)
103 await self
.bot
.api
.send_text_message(
104 room
.room_id
, str(ex
))
107 async def _handle_match(self
, match
):
108 logger
.debug(f
'Try to match {str(match)}')
110 if match
.command('setup'):
111 result
= self
.data
.setup()
114 if match
.command('add'):
115 new
= ' '.join(match
.args()[1:])
116 goal_id
= self
.data
.add_goal(new
)
117 results
= [f
'Goal added with id {goal_id}']
119 goals
= self
.data
.get_all_goals()
120 results
.append('# Goals list...')
122 results
.append(str(goal
))
126 if match
.command('list'):
127 logger
.debug('Asked to list current goals...')
128 goals
= self
.data
.get_current_goals()
129 results
= ['# Goals list...']
131 results
.append(str(goal
))
135 if match
.command('list.done'):
136 goals
= self
.data
.get_done_goals()
137 results
= ['# Completed Goals...']
139 results
.append(str(goal
))
142 if match
.command('task'):
143 new
= ' '.join(match
.args()[1:])
144 goal_id
= self
.data
.quick_add_task(new
)
145 goal
,tasks
= self
.data
.get_goal(goal_id
)
146 results
= pretty_print(goal
, tasks
)
149 if match
.command('add.vision'):
150 new
= ' '.join(match
.args()[1:])
151 result
= self
.data
.add_vision(new
)
152 return [f
'Vision added with id {result}']
154 if match
.command('print'):
155 if len(match
.args()) > 1:
156 goal_id
= int(match
.args()[1])
158 goal_id
= self
.data
._get
_pref
_goal
_id
()
160 logger
.debug(f
'Searching for goal {goal_id}...')
161 goal
,tasks
= self
.data
.get_goal(goal_id
)
162 results
= pretty_print(goal
, tasks
)
167 if match
.command('print.vision'):
168 get_id
= int(match
.args()[1])
169 vision
,goals
= self
.data
.get_vision(get_id
)
170 results
= pretty_print(vision
, goals
)
173 if match
.command('close'):
174 goal_id
= int(match
.args()[1])
175 vision_id
= self
.data
.complete_goal(goal_id
)
176 vision
,goals
= self
.data
.get_vision(vision_id
)
177 results
= pretty_print(vision
, goals
)
181 if match
.command('clear'):
182 if len(match
.args()) > 1:
183 goal_id
= int(match
.args()[1])
185 goal_id
= self
.data
._get
_pref
_goal
_id
()
186 _
= self
.data
.clear(goal_id
)
188 goal
,tasks
= self
.data
.get_goal(goal_id
)
189 results
= pretty_print(goal
, tasks
)
193 if match
.command('start'):
194 goal_id
= int(match
.args()[1])
195 vision
,goals
= self
.data
.start_goal(goal_id
)
196 results
= pretty_print(vision
, goals
)
199 if match
.command('later'):
200 vision_id
= int(match
.args()[1])
201 self
.data
.put_off_vision(vision_id
)
202 # Want to see what we just cleaned up
203 goals
= self
.data
.get_current_goals()
204 results
= ['# Goals list...']
206 results
.append(str(goal
))
210 if match
.command('close.vision'):
211 vision_id
= int(match
.args()[1])
212 self
.data
.complete_vision(vision_id
)
213 vision
,goals
= self
.data
.get_vision(vision_id
)
214 results
= pretty_print(vision
, goals
)
217 if match
.command('done'):
218 ids
= match
.args()[1:]
220 goal_id
= self
.data
.complete_task(int(task_id
))
221 # Print the goal of the last closed task
222 goal
,tasks
= self
.data
.get_goal(goal_id
)
223 results
= pretty_print(goal
, tasks
)
226 if match
.command('dump'):
227 goals
= self
.data
.get_all_goals()
228 results
= ['# Everything ... ']
230 _
,tasks
= self
.data
.get_goal(goal
.id)
231 details
= pretty_print(goal
, tasks
)
236 if match
.command('list.later'):
237 goals
= self
.data
.get_all_goals()
238 results
= ['# All Goals ... ']
241 if match
.command('visions'):
242 items
= self
.data
.get_all_visions()
243 results
= ['# Visions']
245 results
.append('-- No current visions --')
251 if match
.command('visionless'):
252 items
= self
.data
.visionless()
253 results
= ['# Goals with no vision']
255 results
.append('-- No visionless goals --')
261 if match
.command('wins'):
262 items
= self
.data
.wins()
265 results
.append('-- No wins yet --')
273 if match
.command('set.vision'):
274 goal_id
= int(match
.args()[1])
275 vision_id
= int(match
.args()[2])
276 self
.data
.assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
277 vision
,goals
= self
.data
.get_vision(vision_id
)
278 results
= pretty_print(vision
, goals
)
282 if match
.command('rename'):
283 goal_id
= int(match
.args()[1])
284 name
= ' '.join(match
.args()[2:])
285 self
.data
.rename_goal(goal_id
=goal_id
, name
=name
)
286 goal
,tasks
= self
.data
.get_goal(goal_id
)
287 results
= pretty_print(goal
, tasks
)
290 if match
.command('remove'):
291 task_id
= int(match
.args()[1])
292 result
= self
.data
.remove_task(task_id
)
295 if match
.command('extra.help'):