]>
us-delaporte.pagekite.me Git - matrix-goal-bot.git/blob - matrix_goal_bot/bot.py
9 extra.help - show extended help
11 task ID - add a task under the goal specified by ID
12 close.goal ID - mark goal done by ID
13 done ID - mark task done by ID
14 list - list incomplete goals
15 print GOAL_ID - print a goal and all tasks
20 add.vision - add a new vision (collection of goals)
21 close.vision ID - mark vision as complete by ID
22 list.all - list everything
23 print.vision ID - print a vision and all goals
24 set.vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID
25 visions - list incomplete visions
26 list.done - list completed goals
27 visionless - list goals with no set vision
31 from datetime
import datetime
as dt
35 import simplematrixbotlib
as botlib
37 from .db
import Data
, pretty_print
39 DATE_FORMAT
= '%Y-%m-%d'
42 return dt
.now().strftime(DATE_FORMAT
)
44 logger
= logging
.getLogger(__name__
)
47 'Ye cannot get ye flask.',
48 'Ye flask must be load bearing, or something...',
52 'How are you gentlemen?',
53 'All your base are belong to us.',
54 'You have been eaten by a groo.'
58 def __init__(self
, matrix_server
,
64 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
65 self
.bot
= botlib
.Bot(creds
)
66 self
.prefix
= bot_prefix
67 self
.data
= Data(db_file
)
70 logger
.debug('Running goal bot...')
73 async def handle_message(self
, room
, message
):
74 logger
.debug(f
'Message: {message}')
75 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
77 if not match
.is_not_from_this_bot() and match
.prefix():
78 logger
.debug(f
'Message: {message} was not for this bot.')
81 if not match
.prefix():
82 logger
.debug(f
'{message} - did not match {self.prefix}')
86 result_lines
= await self
._handle
_match
(match
)
87 for line
in result_lines
:
88 await self
.bot
.api
.send_text_message(
89 room
.room_id
, str(line
))
90 except Exception as ex
:
91 logger
.warn(f
'Caught exception: {str(ex)}')
92 dumb_msg_idx
= len(str(ex
)) % len(snark
)
93 dumb_msg
= snark
[dumb_msg_idx
]
94 await self
.bot
.api
.send_text_message(
95 room
.room_id
, dumb_msg
)
97 await self
.bot
.api
.send_text_message(
98 room
.room_id
, str(ex
))
101 async def _handle_match(self
, match
):
102 logger
.debug(f
'Try to match {str(match)}')
104 if match
.command('setup'):
105 result
= self
.data
.setup()
108 if match
.command('add'):
109 new
= ' '.join(match
.args()[1:])
110 result
= self
.data
.add_goal(new
)
111 return [f
'Goal added with id {result}']
113 if match
.command('list'):
114 logger
.debug('Asked to list goals...')
115 goals
= self
.data
.get_all_goals()
116 results
= ['# Goals list...']
118 results
.append(str(goal
))
122 if match
.command('list.done'):
123 goals
= self
.data
.get_done_goals()
124 results
= ['# Completed Goals...']
126 results
.append(str(goal
))
129 if match
.command('task'):
130 new
= ' '.join(match
.args()[1:])
131 goal_id
= self
.data
.quick_add_task(new
)
132 goal
,tasks
= self
.data
.get_goal(goal_id
)
133 results
= pretty_print(goal
, tasks
)
136 if match
.command('add.vision'):
137 new
= ' '.join(match
.args()[1:])
138 result
= self
.data
.add_vision(new
)
139 return [f
'Vision added with id {result}']
141 if match
.command('print'):
142 if len(match
.args()) > 1:
143 goal_id
= int(match
.args()[1])
145 goal_id
= self
.data
._get
_pref
_goal
_id
()
147 logger
.debug(f
'Searching for goal {goal_id}...')
148 goal
,tasks
= self
.data
.get_goal(goal_id
)
149 results
= pretty_print(goal
, tasks
)
154 if match
.command('print.vision'):
155 get_id
= int(match
.args()[1])
156 vision
,goals
= self
.data
.get_vision(get_id
)
157 results
= pretty_print(vision
, goals
)
160 if match
.command('close.goal'):
161 goal_id
= int(match
.args()[1])
162 vision_id
= self
.data
.complete_goal(goal_id
)
163 vision
,goals
= self
.data
.get_vision(vision_id
)
164 results
= pretty_print(vision
, goals
)
167 if match
.command('close.vision'):
168 vision_id
= int(match
.args()[1])
169 self
.data
.complete_vision(vision_id
)
170 vision
,goals
= self
.data
.get_vision(vision_id
)
171 results
= pretty_print(vision
, goals
)
174 if match
.command('done'):
175 ids
= match
.args()[1:]
177 goal_id
= self
.data
.complete_task(int(task_id
))
178 # Print the goal of the last closed task
179 goal
,tasks
= self
.data
.get_goal(goal_id
)
180 results
= pretty_print(goal
, tasks
)
183 if match
.command('list.all'):
184 goals
= self
.data
.get_all_goals()
185 results
= ['# Everything is...']
187 _
,tasks
= self
.data
.get_goal(goal
.id)
188 details
= pretty_print(goal
, tasks
)
192 if match
.command('visions'):
193 items
= self
.data
.get_all_visions()
194 results
= ['# Visions']
196 results
.append('-- No current visions --')
202 if match
.command('visionless'):
203 items
= self
.data
.visionless()
204 results
= ['# Goals with no vision']
206 results
.append('-- No visionless goals --')
212 if match
.command('set.vision'):
213 goal_id
= int(match
.args()[1])
214 vision_id
= int(match
.args()[2])
215 self
.data
.assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
216 vision
,goals
= self
.data
.get_vision(vision_id
)
217 results
= pretty_print(vision
, goals
)
221 if match
.command('rename'):
222 goal_id
= int(match
.args()[1])
223 name
= ' '.join(match
.args()[2:])
224 self
.data
.rename_goal(goal_id
=goal_id
, name
=name
)
225 goal
,tasks
= self
.data
.get_goal(goal_id
)
226 results
= pretty_print(goal
, tasks
)
229 if match
.command('remove'):
230 task_id
= int(match
.args()[1])
231 result
= self
.data
.remove_task(task_id
)
234 if match
.command('extra.help'):