]>
apps.delaporte.us Git - matrix-chore-bot.git/blob - matrix_chore_bot/bot.py
1 from datetime
import datetime
as dt
5 import simplematrixbotlib
as botlib
7 from .db
import Data
as ChoreData
9 SERVER
= os
.environ
.get('MATRIX_SERVER')
10 BOT_NAME
= os
.environ
.get('MATRIX_BOT')
11 BOT_PWD
= os
.environ
.get('MATRIX_BOT_PWD')
15 logger
= logging
.getLogger(__name__
)
16 logging
.basicConfig(filename
='matrix-chore-bot.log', encoding
='utf-8', level
=logging
.DEBUG
)
17 logging
.getLogger('nio').setLevel(logging
.WARNING
)
19 async def chore_bot(room
, message
, bot
, prefix
='!chore'):
20 match
= botlib
.MessageMatch(room
, message
, bot
, prefix
)
22 if not match
.is_not_from_this_bot() and match
.prefix():
27 result_lines
= await handle_chore(match
)
28 for line
in result_lines
:
29 await bot
.api
.send_text_message(
30 room
.room_id
, str(line
))
31 except Exception as ex
:
32 line
= f
'Ye flask must be load bearing, or something... {str(ex)}'
33 await bot
.api
.send_text_message(
34 room
.room_id
, str(line
))
37 async def handle_chore(match
):
47 check - check status of a chore
48 done - mark a chore as done
49 list - print the chore list
50 undo - mark a chore as undone
53 if match
.command('list'):
54 results
= ['## Listing chores...']
55 for item
in CHORES
.list():
57 results
.append('-- End of List --')
60 if match
.command('setup'):
62 results
.append('Doing chore setup...')
63 result
= CHORES
.setup()
64 results
.append(str(result
))
67 if match
.command('add'):
68 new_chore
= ' '.join(match
.args()[1:])
69 result
= CHORES
.add(new_chore
)
72 if match
.command('check'):
73 chore_id
= match
.args()[1]
74 result
= CHORES
.check(chore_id
)
77 if match
.command('done'):
78 chore_id
= match
.args()[1]
79 result
= CHORES
.done(chore_id
)
82 if match
.command('undo'):
83 chore_id
= match
.args()[1]
84 result
= CHORES
.undo(chore_id
)
87 if match
.command('remove'):
88 chore_id
= match
.args()[1]
89 result
= CHORES
.remove(chore_id
)
92 return [handle_chore
.__doc
__]