]>
us-delaporte.pagekite.me Git - matrix-goal-bot.git/blob - matrix_goal_bot/bot.py
1 from datetime
import datetime
as dt
5 import simplematrixbotlib
as botlib
7 from goals
.db
import Data
, pretty_print
9 SERVER
= os
.environ
.get('MATRIX_SERVER')
10 BOT_NAME
= os
.environ
.get('GOAL_BOT')
11 BOT_PWD
= os
.environ
.get('GOAL_BOT_PWD')
14 creds
= botlib
.Creds(SERVER
, BOT_NAME
, BOT_PWD
)
15 return botlib
.Bot(creds
)
17 DATE_FORMAT
= '%Y-%m-%d'
20 return dt
.now().strftime(DATE_FORMAT
)
24 logger
= logging
.getLogger(__name__
)
25 logging
.basicConfig(filename
='goals.log', encoding
='utf-8', level
=logging
.DEBUG
)
26 logging
.getLogger('nio').setLevel(logging
.WARNING
)
28 async def do_goal(match
):
38 add-task ID - add a task under the goal specified by ID
39 add-vision - add a new vision (collection of goals)
40 close-goal ID - mark goal done by ID
41 close-vision ID - mark vision as complete by ID
42 done ID - mark task done by ID
43 list - list incomplete goals
44 list-all - list everything
45 list-done - list completed goals
46 print GOAL_ID - print a goal and all tasks
47 print-vision ID - print a vision and all goals
48 set-vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID
49 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 goal
,tasks
= Data().get_goal(goal_id
)
82 results
= pretty_print(goal
, tasks
)
84 # return [f'Added task with id {result}']
86 if match
.command('add-vision'):
87 new
= ' '.join(match
.args()[1:])
88 result
= Data().add_vision(new
)
89 return [f
'Vision added with id {result}']
91 if match
.command('print'):
92 goal_id
= int(match
.args()[1])
93 logger
.debug(f
'Searching for goal {goal_id}...')
94 goal
,tasks
= Data().get_goal(goal_id
)
95 results
= pretty_print(goal
, tasks
)
99 if match
.command('print-vision'):
100 get_id
= int(match
.args()[1])
101 vision
,goals
= Data().get_vision(get_id
)
102 results
= pretty_print(vision
, goals
)
105 if match
.command('close-goal'):
106 goal_id
= int(match
.args()[1])
107 vision_id
= Data().complete_goal(goal_id
)
108 vision
,goals
= Data().get_vision(vision_id
)
109 results
= pretty_print(vision
, goals
)
112 if match
.command('close-vision'):
113 vision_id
= int(match
.args()[1])
114 Data().complete_vision(vision_id
)
115 vision
,goals
= Data().get_vision(vision_id
)
116 results
= pretty_print(vision
, goals
)
120 if match
.command('done'):
121 task_id
= int(match
.args()[1])
122 goal_id
= Data().complete_task(task_id
)
123 goal
,tasks
= Data().get_goal(goal_id
)
124 results
= pretty_print(goal
, tasks
)
127 if match
.command('list-all'):
128 goals
= Data().get_all_goals()
129 results
= ['# Everything is...']
131 _
,tasks
= Data().get_goal(goal
.id)
132 details
= pretty_print(goal
, tasks
)
136 if match
.command('visions'):
137 items
= Data().get_all_visions()
138 results
= ['# Visions']
140 results
.append('-- No current visions --')
147 if match
.command('set-vision'):
148 goal_id
= int(match
.args()[1])
149 vision_id
= int(match
.args()[2])
150 Data().assign_vision(goal_id
=goal_id
, vision_id
=vision_id
)
151 vision
,goals
= Data().get_vision(vision_id
)
152 results
= pretty_print(vision
, goals
)
155 return [do_goal
.__doc
__]
157 async def goal_bot(room
, message
):
158 match
= botlib
.MessageMatch(room
, message
, bot
, PREFIX
)
160 if not match
.is_not_from_this_bot() and match
.prefix():
165 result_lines
= await do_goal(match
)
166 for line
in result_lines
:
167 await bot
.api
.send_text_message(
168 room
.room_id
, str(line
))
169 except Exception as ex
:
170 return ['Ye cannot get ye flask.']