]>
us-delaporte.pagekite.me Git - matrix-goal-bot.git/blob - matrix_goal_bot/bot.py
ade650a6fe154ba02033d59a525984dfd3385885
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
)
95 for line
in result_lines
:
96 message_lines
.append(str(line
))
98 message
= '\n'.join(message_lines
)
100 await self
.bot
.api
.send_text_message(
101 room
.room_id
, message
)
103 except Exception as ex
:
104 logger
.warn(f
'Caught exception: {str(ex)}')
105 dumb_msg_idx
= len(str(ex
)) % len(snark
)
106 dumb_msg
= snark
[dumb_msg_idx
]
107 await self
.bot
.api
.send_text_message(
108 room
.room_id
, dumb_msg
)
110 await self
.bot
.api
.send_text_message(
111 room
.room_id
, str(ex
))
114 async def _handle_match(self
, match
):
115 logger
.debug(f
'Try to match {str(match)}')
117 if match
.command('setup'):
118 result
= self
.data
.setup()
121 if match
.command('add'):
122 new
= ' '.join(match
.args()[1:])
123 goal_id
= self
.data
.add_goal(new
)
124 results
= [f
'Goal added with id {goal_id}']
126 goals
= self
.data
.get_all_goals()
127 results
.append('# Goals list...')
129 results
.append(str(goal
))
133 if match
.command('list'):
134 logger
.debug('Asked to list current goals...')
135 goals
= self
.data
.get_current_goals()
136 results
= ['# Goals list...']
138 results
.append(str(goal
))
142 if match
.command('list.done'):
143 goals
= self
.data
.get_done_goals()
144 results
= ['# Completed Goals...']
146 results
.append(str(goal
))
149 if match
.command('task'):
150 new
= ' '.join(match
.args()[1:])
151 goal_id
= self
.data
.quick_add_task(new
)
152 goal
,tasks
= self
.data
.get_goal(goal_id
)
153 results
= pretty_print(goal
, tasks
)
156 if match
.command('add.vision'):
157 new
= ' '.join(match
.args()[1:])
158 result
= self
.data
.add_vision(new
)
159 return [f
'Vision added with id {result}']
161 if match
.command('print'):
162 if len(match
.args()) > 1:
163 goal_id
= int(match
.args()[1])
165 goal_id
= self
.data
._get
_pref
_goal
_id
()
167 logger
.debug(f
'Searching for goal {goal_id}...')
168 goal
,tasks
= self
.data
.get_goal(goal_id
)
169 results
= pretty_print(goal
, tasks
)
174 if match
.command('print.vision'):
175 get_id
= int(match
.args()[1])
176 vision
,goals
= self
.data
.get_vision(get_id
)
177 results
= pretty_print(vision
, goals
)
180 if match
.command('close'):
181 goal_id
= int(match
.args()[1])
182 vision_id
= self
.data
.complete_goal(goal_id
)
183 vision
,goals
= self
.data
.get_vision(vision_id
)
184 results
= pretty_print(vision
, goals
)
188 if match
.command('clear'):
189 if len(match
.args()) > 1:
190 goal_id
= int(match
.args()[1])
192 goal_id
= self
.data
._get
_pref
_goal
_id
()
193 _
= self
.data
.clear(goal_id
)
195 goal
,tasks
= self
.data
.get_goal(goal_id
)
196 results
= pretty_print(goal
, tasks
)
200 if match
.command('start'):
201 goal_id
= int(match
.args()[1])
202 vision
,goals
= self
.data
.start_goal(goal_id
)
203 results
= pretty_print(vision
, goals
)
206 if match
.command('later'):
207 vision_id
= int(match
.args()[1])
208 self
.data
.put_off_vision(vision_id
)
209 # Want to see what we just cleaned up
210 goals
= self
.data
.get_current_goals()
211 results
= ['# Goals list...']
213 results
.append(str(goal
))
217 if match
.command('close.vision'):
218 vision_id
= int(match
.args()[1])
219 self
.data
.complete_vision(vision_id
)
220 vision
,goals
= self
.data
.get_vision(vision_id
)
221 results
= pretty_print(vision
, goals
)
224 if match
.command('done'):
225 ids
= match
.args()[1:]
227 goal_id
= self
.data
.complete_task(int(task_id
))
228 # Print the goal of the last closed task
229 goal
,tasks
= self
.data
.get_goal(goal_id
)
230 results
= pretty_print(goal
, tasks
)
233 if match
.command('dump'):
234 goals
= self
.data
.get_all_goals()
235 results
= ['# Everything ... ']
237 _
,tasks
= self
.data
.get_goal(goal
.id)
238 details
= pretty_print(goal
, tasks
)
243 if match
.command('list.later'):
244 goals
= self
.data
.get_all_goals()
245 results
= ['# All Goals ... ']
248 if match
.command('visions'):
249 items
= self
.data
.get_all_visions()
250 results
= ['# Visions']
252 results
.append('-- No current visions --')
258 if match
.command('visionless'):
259 items
= self
.data
.visionless()
260 results
= ['# Goals with no vision']
262 results
.append('-- No visionless goals --')
268 if match
.command('wins'):
269 items
= self
.data
.wins()
272 results
.append('-- No wins yet --')
280 if match
.command('set.vision'):
281 goal_id
= int(match
.args()[1])
282 vision_id
= int(match
.args()[2])
283 self
.data
.assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
284 vision
,goals
= self
.data
.get_vision(vision_id
)
285 results
= pretty_print(vision
, goals
)
289 if match
.command('rename'):
290 goal_id
= int(match
.args()[1])
291 name
= ' '.join(match
.args()[2:])
292 self
.data
.rename_goal(goal_id
=goal_id
, name
=name
)
293 goal
,tasks
= self
.data
.get_goal(goal_id
)
294 results
= pretty_print(goal
, tasks
)
297 if match
.command('remove'):
298 task_id
= int(match
.args()[1])
299 result
= self
.data
.remove_task(task_id
)
302 if match
.command('extra.help'):