]>
us-delaporte.pagekite.me 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 later GOAL_ID - put off goal for 14 days
24 list.all - list everything
25 print.vision ID - print a vision and all goals
26 set.vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID
27 visions - list incomplete visions
28 list.done - list completed goals
29 remove ID - remove a task by ID
30 start GOAL_ID - un-put-off a goal (reverse of later)
31 visionless - list goals with no set vision
35 from datetime
import datetime
as dt
39 import simplematrixbotlib
as botlib
41 from .db
import Data
, pretty_print
43 DATE_FORMAT
= '%Y-%m-%d'
46 return dt
.now().strftime(DATE_FORMAT
)
48 logger
= logging
.getLogger(__name__
)
51 'Ye cannot get ye flask.',
52 'Ye flask must be load bearing, or something...',
56 'How are you gentlemen?',
57 'All your base are belong to us.',
58 'You have been eaten by a groo.'
62 def __init__(self
, matrix_server
,
68 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
69 self
.bot
= botlib
.Bot(creds
)
70 self
.prefix
= bot_prefix
71 self
.data
= Data(db_file
)
74 logger
.debug('Running goal bot...')
77 async def handle_message(self
, room
, message
):
78 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
80 if not match
.is_not_from_this_bot():
81 # Let's not talk to our-self
84 logger
.debug(f
'Message: {message}')
85 if not match
.prefix():
86 logger
.debug(f
'{message} - did not match {self.prefix}')
90 result_lines
= await self
._handle
_match
(match
)
91 for line
in result_lines
:
92 await self
.bot
.api
.send_text_message(
93 room
.room_id
, str(line
))
94 except Exception as ex
:
95 logger
.warn(f
'Caught exception: {str(ex)}')
96 dumb_msg_idx
= len(str(ex
)) % len(snark
)
97 dumb_msg
= snark
[dumb_msg_idx
]
98 await self
.bot
.api
.send_text_message(
99 room
.room_id
, dumb_msg
)
101 await self
.bot
.api
.send_text_message(
102 room
.room_id
, str(ex
))
105 async def _handle_match(self
, match
):
106 logger
.debug(f
'Try to match {str(match)}')
108 if match
.command('setup'):
109 result
= self
.data
.setup()
112 if match
.command('add'):
113 new
= ' '.join(match
.args()[1:])
114 goal_id
= self
.data
.add_goal(new
)
115 results
= [f
'Goal added with id {goal_id}']
117 goals
= self
.data
.get_all_goals()
118 results
.append('# Goals list...')
120 results
.append(str(goal
))
124 if match
.command('list'):
125 logger
.debug('Asked to list current goals...')
126 goals
= self
.data
.get_current_goals()
127 results
= ['# Goals list...']
129 results
.append(str(goal
))
133 if match
.command('list.done'):
134 goals
= self
.data
.get_done_goals()
135 results
= ['# Completed Goals...']
137 results
.append(str(goal
))
140 if match
.command('task'):
141 new
= ' '.join(match
.args()[1:])
142 goal_id
= self
.data
.quick_add_task(new
)
143 goal
,tasks
= self
.data
.get_goal(goal_id
)
144 results
= pretty_print(goal
, tasks
)
147 if match
.command('add.vision'):
148 new
= ' '.join(match
.args()[1:])
149 result
= self
.data
.add_vision(new
)
150 return [f
'Vision added with id {result}']
152 if match
.command('print'):
153 if len(match
.args()) > 1:
154 goal_id
= int(match
.args()[1])
156 goal_id
= self
.data
._get
_pref
_goal
_id
()
158 logger
.debug(f
'Searching for goal {goal_id}...')
159 goal
,tasks
= self
.data
.get_goal(goal_id
)
160 results
= pretty_print(goal
, tasks
)
165 if match
.command('print.vision'):
166 get_id
= int(match
.args()[1])
167 vision
,goals
= self
.data
.get_vision(get_id
)
168 results
= pretty_print(vision
, goals
)
171 if match
.command('close'):
172 goal_id
= int(match
.args()[1])
173 vision_id
= self
.data
.complete_goal(goal_id
)
174 vision
,goals
= self
.data
.get_vision(vision_id
)
175 results
= pretty_print(vision
, goals
)
179 if match
.command('clear'):
180 if len(match
.args()) > 1:
181 goal_id
= int(match
.args()[1])
183 goal_id
= self
.data
._get
_pref
_goal
_id
()
184 _
= self
.data
.clear(goal_id
)
186 goal
,tasks
= self
.data
.get_goal(goal_id
)
187 results
= pretty_print(goal
, tasks
)
191 if match
.command('start'):
192 goal_id
= int(match
.args()[1])
193 vision_id
= self
.data
.start_goal(goal_id
)
194 vision
,goals
= self
.data
.get_vision(vision_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('list.all'):
223 goals
= self
.data
.get_all_goals()
224 results
= ['# Everything is...']
226 _
,tasks
= self
.data
.get_goal(goal
.id)
227 details
= pretty_print(goal
, tasks
)
231 if match
.command('visions'):
232 items
= self
.data
.get_all_visions()
233 results
= ['# Visions']
235 results
.append('-- No current visions --')
241 if match
.command('visionless'):
242 items
= self
.data
.visionless()
243 results
= ['# Goals with no vision']
245 results
.append('-- No visionless goals --')
251 if match
.command('set.vision'):
252 goal_id
= int(match
.args()[1])
253 vision_id
= int(match
.args()[2])
254 self
.data
.assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
255 vision
,goals
= self
.data
.get_vision(vision_id
)
256 results
= pretty_print(vision
, goals
)
260 if match
.command('rename'):
261 goal_id
= int(match
.args()[1])
262 name
= ' '.join(match
.args()[2:])
263 self
.data
.rename_goal(goal_id
=goal_id
, name
=name
)
264 goal
,tasks
= self
.data
.get_goal(goal_id
)
265 results
= pretty_print(goal
, tasks
)
268 if match
.command('remove'):
269 task_id
= int(match
.args()[1])
270 result
= self
.data
.remove_task(task_id
)
273 if match
.command('extra.help'):