]>
us-delaporte.pagekite.me Git - matrix-fridge-bot.git/blob - matrix_chore_bot/bot.py
2484c462ba6f6ec7ec642393b6c3efe05b6e7a66
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
.getLogger('nio').setLevel(logging
.WARNING
)
29 def __init__(self
, matrix_server
,
35 logging
.basicConfig(filename
='matrix-chore-bot.log', encoding
='utf-8', level
=logging
.DEBUG
)
38 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
39 self
.bot
= botlib
.Bot(creds
)
40 self
.prefix
= bot_prefix
41 self
.data
= ChoreData(db_file
=db_file
)
46 async def handle_message(self
, room
, message
):
47 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
49 if not match
.is_not_from_this_bot() and match
.prefix():
54 result_lines
= await self
._handle
_match
(match
)
55 for line
in result_lines
:
56 await self
.bot
.api
.send_text_message(
57 room
.room_id
, str(line
))
58 except Exception as ex
:
59 line
= f
'Ye flask must be load bearing, or something... {str(ex)}'
60 await self
.bot
.api
.send_text_message(
61 room
.room_id
, str(line
))
64 async def _handle_match(self
, match
):
66 if match
.command('list'):
67 results
= ['## Listing all...']
68 for item
in self
.data
.list():
70 results
.append('-- End of List --')
73 if match
.command('filter'):
74 term
= ' '.join(match
.args()[1:])
75 results
= [f
'## List matching {term}']
76 for item
in self
.data
.filter(term
):
78 results
.append('-- End of List --')
81 if match
.command('setup'):
83 results
.append('Doing chore setup...')
84 result
= self
.data
.setup()
85 results
.append(str(result
))
88 if match
.command('add'):
89 new_chore
= ' '.join(match
.args()[1:])
90 result
= self
.data
.add(new_chore
)
93 if match
.command('check'):
94 chore_id
= match
.args()[1]
95 result
= self
.data
.check(chore_id
)
98 if match
.command('done'):
99 ids
= match
.args()[1:]
102 result
= self
.data
.done(chore_id
)
103 results
.append(result
)
106 if match
.command('undo'):
107 chore_id
= match
.args()[1]
108 result
= self
.data
.undo(chore_id
)
111 if match
.command('remove'):
112 chore_id
= match
.args()[1]
113 result
= self
.data
.remove(chore_id
)