]>
us-delaporte.pagekite.me Git - matrix-chore-bot.git/blob - matrix_chore_bot/bot.py
067c2f906d196170c07c95456c669484ce0dc74c
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 filter TERM - list all chores that include TERM
51 undo - mark a chore as undone
54 if match
.command('list'):
55 results
= ['## Listing all...']
56 for item
in CHORES
.list():
58 results
.append('-- End of List --')
61 if match
.command('filter'):
62 term
= ' '.join(match
.args()[1:])
63 results
= [f
'## List matching {term}']
64 for item
in CHORES
.filter(term
):
66 results
.append('-- End of List --')
69 if match
.command('setup'):
71 results
.append('Doing chore setup...')
72 result
= CHORES
.setup()
73 results
.append(str(result
))
76 if match
.command('add'):
77 new_chore
= ' '.join(match
.args()[1:])
78 result
= CHORES
.add(new_chore
)
81 if match
.command('check'):
82 chore_id
= match
.args()[1]
83 result
= CHORES
.check(chore_id
)
86 if match
.command('done'):
87 ids
= match
.args()[1:]
90 result
= CHORES
.done(chore_id
)
91 results
.append(result
)
94 if match
.command('undo'):
95 chore_id
= match
.args()[1]
96 result
= CHORES
.undo(chore_id
)
99 if match
.command('remove'):
100 chore_id
= match
.args()[1]
101 result
= CHORES
.remove(chore_id
)
104 return [handle_chore
.__doc
__]