]>
apps.delaporte.us Git - matrix-chore-bot.git/blob - matrix_chore_bot/bot.py
c1a76d336464253f3ca51bee7b8f2f48ec9da6e3
10 check - check status of a chore
11 done - mark a chore as done
12 list - print the chore list
13 filter TERM - list all chores that include TERM
14 undo - mark a chore as undone
17 from datetime
import datetime
as dt
21 import simplematrixbotlib
as botlib
23 from .db
import Data
as ChoreData
25 logger
= logging
.getLogger(__name__
)
26 logging
.basicConfig(filename
='matrix-chore-bot.log', encoding
='utf-8', level
=logging
.DEBUG
)
27 logging
.getLogger('nio').setLevel(logging
.WARNING
)
30 def __init__(self
, matrix_server
,
36 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
37 self
.bot
= botlib
.Bot(creds
)
38 self
.prefix
= bot_prefix
39 self
.data
= ChoreData(db_file
=db_file
)
44 async def handle_message(self
, room
, message
):
45 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
47 if not match
.is_not_from_this_bot() and match
.prefix():
52 result_lines
= await self
._handle
_match
(match
)
53 for line
in result_lines
:
54 await self
.bot
.api
.send_text_message(
55 room
.room_id
, str(line
))
56 except Exception as ex
:
57 line
= f
'Ye flask must be load bearing, or something... {str(ex)}'
58 await self
.bot
.api
.send_text_message(
59 room
.room_id
, str(line
))
62 async def _handle_match(self
, match
):
64 if match
.command('list'):
65 results
= ['## Listing all...']
66 for item
in self
.data
.list():
68 results
.append('-- End of List --')
71 if match
.command('filter'):
72 term
= ' '.join(match
.args()[1:])
73 results
= [f
'## List matching {term}']
74 for item
in self
.data
.filter(term
):
76 results
.append('-- End of List --')
79 if match
.command('setup'):
81 results
.append('Doing chore setup...')
82 result
= self
.data
.setup()
83 results
.append(str(result
))
86 if match
.command('add'):
87 new_chore
= ' '.join(match
.args()[1:])
88 result
= self
.data
.add(new_chore
)
91 if match
.command('check'):
92 chore_id
= match
.args()[1]
93 result
= self
.data
.check(chore_id
)
96 if match
.command('done'):
97 ids
= match
.args()[1:]
100 result
= self
.data
.done(chore_id
)
101 results
.append(result
)
104 if match
.command('undo'):
105 chore_id
= match
.args()[1]
106 result
= self
.data
.undo(chore_id
)
109 if match
.command('remove'):
110 chore_id
= match
.args()[1]
111 result
= self
.data
.remove(chore_id
)