]>
us-delaporte.pagekite.me Git - matrix-chore-bot.git/blob - matrix_chore_bot/bot.py
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 'Ye cannot get ye flask.',
30 'Ye flask must be load bearing, or something...',
34 'How are you gentlemen?',
35 'All your base are belong to us.',
36 'You have been eaten by a groo.'
42 def __init__(self
, matrix_server
,
48 logging
.basicConfig(filename
='matrix-chore-bot.log', encoding
='utf-8', level
=logging
.DEBUG
)
51 creds
= botlib
.Creds(matrix_server
, bot_name
, bot_pwd
)
52 self
.bot
= botlib
.Bot(creds
)
53 self
.prefix
= bot_prefix
54 self
.data
= ChoreData(db_file
=db_file
)
59 async def handle_message(self
, room
, message
):
60 match
= botlib
.MessageMatch(room
, message
, self
.bot
, self
.prefix
)
62 if not match
.is_not_from_this_bot() and match
.prefix():
67 result_lines
= await self
._handle
_match
(match
)
68 for line
in result_lines
:
69 await self
.bot
.api
.send_text_message(
70 room
.room_id
, str(line
))
72 except Exception as ex
:
73 logger
.warn(f
'Caught exception: {str(ex)}')
74 dumb_msg_idx
= len(str(ex
)) % len(snark
)
75 dumb_msg
= snark
[dumb_msg_idx
]
76 await self
.bot
.api
.send_text_message(
77 room
.room_id
, dumb_msg
)
79 await self
.bot
.api
.send_text_message(
80 room
.room_id
, str(ex
))
82 except Exception as ex
:
83 line
= f
'Ye flask must be load bearing, or something... {str(ex)}'
84 await self
.bot
.api
.send_text_message(
85 room
.room_id
, str(line
))
88 async def _handle_match(self
, match
):
90 if match
.command('list'):
91 results
= ['## Listing all...']
92 for item
in self
.data
.list():
94 results
.append('-- End of List --')
97 if match
.command('filter'):
98 term
= ' '.join(match
.args()[1:])
99 results
= [f
'## List matching {term}']
100 for item
in self
.data
.filter(term
):
102 results
.append('-- End of List --')
105 if match
.command('setup'):
107 results
.append('Doing chore setup...')
108 result
= self
.data
.setup()
109 results
.append(str(result
))
112 if match
.command('add'):
113 new_chore
= ' '.join(match
.args()[1:])
114 result
= self
.data
.add(new_chore
)
117 if match
.command('check'):
118 chore_id
= match
.args()[1]
119 result
= self
.data
.check(chore_id
)
122 if match
.command('done'):
123 ids
= match
.args()[1:]
126 result
= self
.data
.done(chore_id
)
127 results
.append(result
)
130 if match
.command('undo'):
131 chore_id
= match
.args()[1]
132 result
= self
.data
.undo(chore_id
)
135 if match
.command('remove'):
136 chore_id
= match
.args()[1]
137 result
= self
.data
.remove(chore_id
)