]>
apps.delaporte.us Git - matrix-goal-bot.git/blob - bot.py
3cba5cfe3938d13b5cea379d5fc19db5078f5056
1 from datetime
import datetime
as dt
5 import simplematrixbotlib
as botlib
7 from goals
.db
import Data
, pretty_print
10 SERVER
= os
.environ
.get('MATRIX_SERVER')
11 BOT_NAME
= os
.environ
.get('GOAL_BOT')
12 BOT_PWD
= os
.environ
.get('GOAL_BOT_PWD')
14 DATE_FORMAT
= '%Y-%m-%d'
17 return dt
.now().strftime(DATE_FORMAT
)
19 creds
= botlib
.Creds(SERVER
, BOT_NAME
, BOT_PWD
)
20 bot
= botlib
.Bot(creds
)
23 logger
= logging
.getLogger(__name__
)
24 logging
.basicConfig(filename
='goals.log', encoding
='utf-8', level
=logging
.DEBUG
)
25 logging
.getLogger('nio').setLevel(logging
.WARNING
)
27 async def do_goal(match
):
37 add-task ID - add a task under the goal specified by ID
38 list - list incomplete goals
39 list-all - list everything
40 list-done - list completed goals
41 print ID - print a goal and all tasks
42 print-vision ID - print a vision and all goals
43 done ID - mark task done by ID
44 goal-done ID - mark goal done by ID
45 set-vision GOAL_ID VISION_ID - associate GOAL_ID with VISION_ID
46 visions - list incomplete visions
52 if match
.command('setup'):
53 result
= Data().setup()
56 if match
.command('add'):
57 new
= ' '.join(match
.args()[1:])
58 result
= Data().add_goal(new
)
59 return [f
'Goal added with id {result}']
61 if match
.command('list'):
62 goals
= Data().get_all_goals()
63 results
= ['# Goals list...']
65 results
.append(str(goal
))
69 if match
.command('list-done'):
70 goals
= Data().get_done_goals()
71 results
= ['# Completed Goals...']
73 results
.append(str(goal
))
77 if match
.command('add-task'):
78 goal_id
= int(match
.args()[1])
79 new
= ' '.join(match
.args()[2:])
80 result
= Data().add_task(goal_id
=goal_id
, name
=new
)
81 return [f
'Added task with id {result}']
83 if match
.command('add-vision'):
84 new
= ' '.join(match
.args()[1:])
85 result
= Data().add_vision(new
)
86 return [f
'Vision added with id {result}']
88 if match
.command('print'):
89 goal_id
= int(match
.args()[1])
90 logger
.debug(f
'Searching for goal {goal_id}...')
91 goal
,tasks
= Data().get_goal(goal_id
)
92 results
= pretty_print(goal
, tasks
)
96 if match
.command('print-vision'):
97 get_id
= int(match
.args()[1])
98 vision
,goals
= Data().get_vision(get_id
)
99 results
= pretty_print(vision
, goals
)
102 if match
.command('goal-done'):
103 goal_id
= int(match
.args()[1])
104 logger
.debug(f
'Searching for goal {goal_id}...')
105 Data().complete_goal(goal_id
)
106 goal
,tasks
= Data().get_goal(goal_id
)
107 results
= pretty_print(goal
, tasks
)
111 if match
.command('done'):
112 task_id
= int(match
.args()[1])
113 goal_id
= Data().complete_task(task_id
)
114 goal
,tasks
= Data().get_goal(goal_id
)
115 results
= pretty_print(goal
, tasks
)
118 if match
.command('list-all'):
119 goals
= Data().get_all_goals()
120 results
= ['Everything is...']
122 _
,tasks
= Data().get_goal(goal
.id)
123 details
= pretty_print(goal
, tasks
)
127 if match
.command('visions'):
128 items
= Data().get_all_visions()
129 results
= ['Visions are']
131 results
.append('-- No current visions --')
138 if match
.command('set-vision'):
139 goal_id
= int(match
.args()[1])
140 vision_id
= int(match
.args()[1])
141 Data().assign_vision(goal_id
, vision_id
)
142 vision
,goals
= Data().get_vision(vision_id
)
143 results
= pretty_print(vision
, goals
)
146 return [do_goal
.__doc
__]
147 except Exception as ex
:
148 return ['Ye cannot get ye flask.']
150 @bot.listener.on_message_event
151 async def goals(room
, message
):
152 match
= botlib
.MessageMatch(room
, message
, bot
, PREFIX
)
154 if not match
.is_not_from_this_bot() and match
.prefix():
158 result_lines
= await do_goal(match
)
159 for line
in result_lines
:
160 await bot
.api
.send_text_message(
161 room
.room_id
, str(line
))