]>
apps.delaporte.us Git - matrix-chore-bot.git/blob - matrix_chore_bot/bot.py
a0a3256d025fc3b21640acadfb56ecf0c5f34f75
1 from datetime
import datetime
as dt
5 import simplematrixbotlib
as botlib
9 SERVER
= os
.environ
.get('MATRIX_SERVER')
10 BOT_NAME
= os
.environ
.get('MATRIX_BOT')
11 BOT_PWD
= os
.environ
.get('MATRIX_BOT_PWD')
14 creds
= botlib
.Creds(SERVER
, BOT_NAME
, BOT_PWD
)
15 return botlib
.Bot(creds
)
17 logger
= logging
.getLogger(__name__
)
18 logging
.basicConfig(filename
='matrix-chore-bot.log', encoding
='utf-8', level
=logging
.DEBUG
)
19 logging
.getLogger('nio').setLevel(logging
.WARNING
)
21 @bot.listener.on_message_event
22 async def chore_bot(room
, message
, bot
):
23 match
= botlib
.MessageMatch(room
, message
, bot
, '!chore')
25 if not match
.is_not_from_this_bot() and match
.prefix():
30 result_lines
= await handle_chore(match
)
31 for line
in result_lines
:
32 await bot
.api
.send_text_message(
33 room
.room_id
, str(line
))
34 except Exception as ex
:
35 line
= 'Ye cannot get ye flask.'
36 await bot
.api
.send_text_message(
37 room
.room_id
, str(line
))
40 async def handle_chore(match
):
50 check - check status of a chore
51 done - mark a chore as done
52 list - print the chore list
53 undo - mark a chore as undone
56 if match
.command('list'):
57 results
= ['## Listing chores...']
58 for item
in CHORES
.list():
60 results
.append('-- End of List --')
63 if match
.command('setup'):
65 results
.append('Doing chore setup...')
66 result
= CHORES
.setup()
67 results
.append(str(result
))
70 if match
.command('add'):
71 new_chore
= ' '.join(match
.args()[1:])
72 result
= CHORES
.add(new_chore
)
75 if match
.command('check'):
76 chore_id
= match
.args()[1]
77 result
= CHORES
.check(chore_id
)
80 if match
.command('done'):
81 chore_id
= match
.args()[1]
82 result
= CHORES
.done(chore_id
)
85 if match
.command('undo'):
86 chore_id
= match
.args()[1]
87 result
= CHORES
.undo(chore_id
)
90 if match
.command('remove'):
91 chore_id
= match
.args()[1]
92 result
= CHORES
.remove(chore_id
)
95 return [handle_chore
.__doc
__]