]>
us-delaporte.pagekite.me Git - matrix-goal-bot.git/blob - matrix_goal_bot/bot.py
ec3e97d377579869ccf0ba3538f3eb4f6c897ddb
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 GOAL_ID - put off goal 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
36 from datetime
import datetime
as dt
40 import simplematrixbotlib
as botlib
42 from .db
import Data
, pretty_print
44 DATE_FORMAT
= '%Y-%m-%d'
47 return dt
.now().strftime(DATE_FORMAT
)
49 logger
= logging
.getLogger(__name__
)
52 'Ye cannot get ye flask.',
53 'Ye flask must be load bearing, or something...',
57 'How are you gentlemen?',
58 'All your base are belong to us.',
59 'You have been eaten by a groo.'
63 def __init__(self
, matrix_server
,
69 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
70 self
.bot
= botlib
.Bot(creds
)
71 self
.prefix
= bot_prefix
72 self
.data
= Data(db_file
)
75 logger
.debug('Running goal bot...')
78 async def handle_message(self
, room
, message
):
79 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
81 if not match
.is_not_from_this_bot():
82 # Let's not talk to our-self
85 logger
.debug(f
'Message: {message}')
86 if not match
.prefix():
87 logger
.debug(f
'{message} - did not match {self.prefix}')
91 result_lines
= await self
._handle
_match
(match
)
92 for line
in result_lines
:
93 await self
.bot
.api
.send_text_message(
94 room
.room_id
, str(line
))
95 except Exception as ex
:
96 logger
.warn(f
'Caught exception: {str(ex)}')
97 dumb_msg_idx
= len(str(ex
)) % len(snark
)
98 dumb_msg
= snark
[dumb_msg_idx
]
99 await self
.bot
.api
.send_text_message(
100 room
.room_id
, dumb_msg
)
102 await self
.bot
.api
.send_text_message(
103 room
.room_id
, str(ex
))
106 async def _handle_match(self
, match
):
107 logger
.debug(f
'Try to match {str(match)}')
109 if match
.command('setup'):
110 result
= self
.data
.setup()
113 if match
.command('add'):
114 new
= ' '.join(match
.args()[1:])
115 goal_id
= self
.data
.add_goal(new
)
116 results
= [f
'Goal added with id {goal_id}']
118 goals
= self
.data
.get_all_goals()
119 results
.append('# Goals list...')
121 results
.append(str(goal
))
125 if match
.command('list'):
126 logger
.debug('Asked to list current goals...')
127 goals
= self
.data
.get_current_goals()
128 results
= ['# Goals list...']
130 results
.append(str(goal
))
134 if match
.command('list.done'):
135 goals
= self
.data
.get_done_goals()
136 results
= ['# Completed Goals...']
138 results
.append(str(goal
))
141 if match
.command('task'):
142 new
= ' '.join(match
.args()[1:])
143 goal_id
= self
.data
.quick_add_task(new
)
144 goal
,tasks
= self
.data
.get_goal(goal_id
)
145 results
= pretty_print(goal
, tasks
)
148 if match
.command('add.vision'):
149 new
= ' '.join(match
.args()[1:])
150 result
= self
.data
.add_vision(new
)
151 return [f
'Vision added with id {result}']
153 if match
.command('print'):
154 if len(match
.args()) > 1:
155 goal_id
= int(match
.args()[1])
157 goal_id
= self
.data
._get
_pref
_goal
_id
()
159 logger
.debug(f
'Searching for goal {goal_id}...')
160 goal
,tasks
= self
.data
.get_goal(goal_id
)
161 results
= pretty_print(goal
, tasks
)
166 if match
.command('print.vision'):
167 get_id
= int(match
.args()[1])
168 vision
,goals
= self
.data
.get_vision(get_id
)
169 results
= pretty_print(vision
, goals
)
172 if match
.command('close'):
173 goal_id
= int(match
.args()[1])
174 vision_id
= self
.data
.complete_goal(goal_id
)
175 vision
,goals
= self
.data
.get_vision(vision_id
)
176 results
= pretty_print(vision
, goals
)
180 if match
.command('clear'):
181 if len(match
.args()) > 1:
182 goal_id
= int(match
.args()[1])
184 goal_id
= self
.data
._get
_pref
_goal
_id
()
185 _
= self
.data
.clear(goal_id
)
187 goal
,tasks
= self
.data
.get_goal(goal_id
)
188 results
= pretty_print(goal
, tasks
)
192 if match
.command('start'):
193 goal_id
= int(match
.args()[1])
194 vision
,goals
= self
.data
.start_goal(goal_id
)
195 results
= pretty_print(vision
, goals
)
198 if match
.command('later'):
199 goal_id
= int(match
.args()[1])
200 vision_id
= self
.data
.put_off_goal(goal_id
)
201 vision
,goals
= self
.data
.get_vision(vision_id
)
202 results
= pretty_print(vision
, goals
)
206 if match
.command('close.vision'):
207 vision_id
= int(match
.args()[1])
208 self
.data
.complete_vision(vision_id
)
209 vision
,goals
= self
.data
.get_vision(vision_id
)
210 results
= pretty_print(vision
, goals
)
213 if match
.command('done'):
214 ids
= match
.args()[1:]
216 goal_id
= self
.data
.complete_task(int(task_id
))
217 # Print the goal of the last closed task
218 goal
,tasks
= self
.data
.get_goal(goal_id
)
219 results
= pretty_print(goal
, tasks
)
222 if match
.command('dump'):
223 goals
= self
.data
.get_all_goals()
224 results
= ['# Everything ... ']
226 _
,tasks
= self
.data
.get_goal(goal
.id)
227 details
= pretty_print(goal
, tasks
)
232 if match
.command('list.later'):
233 goals
= self
.data
.get_all_goals()
234 results
= ['# All Goals ... ']
237 if match
.command('visions'):
238 items
= self
.data
.get_all_visions()
239 results
= ['# Visions']
241 results
.append('-- No current visions --')
247 if match
.command('visionless'):
248 items
= self
.data
.visionless()
249 results
= ['# Goals with no vision']
251 results
.append('-- No visionless goals --')
257 if match
.command('set.vision'):
258 goal_id
= int(match
.args()[1])
259 vision_id
= int(match
.args()[2])
260 self
.data
.assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
261 vision
,goals
= self
.data
.get_vision(vision_id
)
262 results
= pretty_print(vision
, goals
)
266 if match
.command('rename'):
267 goal_id
= int(match
.args()[1])
268 name
= ' '.join(match
.args()[2:])
269 self
.data
.rename_goal(goal_id
=goal_id
, name
=name
)
270 goal
,tasks
= self
.data
.get_goal(goal_id
)
271 results
= pretty_print(goal
, tasks
)
274 if match
.command('remove'):
275 task_id
= int(match
.args()[1])
276 result
= self
.data
.remove_task(task_id
)
279 if match
.command('extra.help'):