]>
apps.delaporte.us Git - matrix-goal-bot.git/blob - bot.py
2 from datetime
import datetime
as dt
4 import simplematrixbotlib
as botlib
6 from school
import (get_assignments
, STUDENTS
)
8 from chore
.db
import Data
as ChoreData
12 SERVER
= os
.environ
.get('MATRIX_SERVER')
13 BOT_NAME
= os
.environ
.get('GOAL_BOT')
14 BOT_PWD
= os
.environ
.get('GOAL_BOT_PWD')
16 DATE_FORMAT
= '%Y-%m-%d'
19 return dt
.now().strftime(DATE_FORMAT
)
21 creds
= botlib
.Creds(SERVER
, BOT_NAME
, BOT_PWD
)
22 bot
= botlib
.Bot(creds
)
25 @bot.listener.on_message_event
26 async def goals(room
, message
):
27 match
= botlib
.MessageMatch(room
, message
, bot
, PREFIX
)
29 if not match
.is_not_from_this_bot() and match
.prefix():
32 if match
.command("echo"):
33 await bot
.api
.send_text_message(
34 room
.room_id
, " ".join(arg
for arg
in match
.args())
38 # Print this help text
40 # List available students
42 # Get today's assignments
44 # Get an assignment for a date
45 !school get [Name] 2026-03-09
47 if match
.command("help"):
48 await bot
.api
.send_text_message(
49 room
.room_id
, help_text
)
51 if match
.command("list"):
52 student_list
= f
"Known students are {STUDENTS}."
53 await bot
.api
.send_text_message(
54 room
.room_id
, student_list
)
57 if match
.command("get"):
59 if(len(match
.args()) < 2):
60 result
= ['Please specify person to get assignments for.']
62 person
= match
.args()[1]
64 if(len(match
.args()) > 2):
70 await bot
.api
.send_text_message(room
.room_id
, f
'Fetching assignments for {person} on {day}')
71 results
= get_assignments(person
, day
)
76 results
= [f
'No assignments found for {person} on {day}.']
80 await bot
.api
.send_text_message(
84 @bot.listener.on_message_event
85 async def chores(room
, message
):
86 match
= botlib
.MessageMatch(room
, message
, bot
, '!chore')
88 if not match
.is_not_from_this_bot() and match
.prefix():
91 if match
.command('list'):
93 await bot
.api
.send_text_message(
94 room
.room_id
, 'Listing chores...')
96 result
= CHORES
.list()
98 await bot
.api
.send_text_message(
101 await bot
.api
.send_text_message(
102 room
.room_id
, '-- End of List --')
104 if match
.command('setup'):
105 await bot
.api
.send_text_message(
106 room
.room_id
, f
'Doing chore setup...')
107 result
= CHORES
.setup()
108 result
= await bot
.api
.send_text_message(
109 room
.room_id
, f
'Result: {result}')
112 if match
.command('add'):
113 new_chore
= ' '.join(match
.args()[1:])
115 await bot
.api
.send_text_message(
116 room
.room_id
, f
'Adding chore...{new_chore}...')
118 result
= CHORES
.add(new_chore
)
119 await bot
.api
.send_text_message(
120 room
.room_id
, result
)
124 if match
.command('check'):
125 chore_id
= match
.args()[1]
127 result
= CHORES
.check(chore_id
)
128 await bot
.api
.send_text_message(
129 room
.room_id
, result
)
131 if match
.command('done'):
132 chore_id
= match
.args()[1]
133 result
= CHORES
.done(chore_id
)
134 await bot
.api
.send_text_message(
135 room
.room_id
, result
)
137 if match
.command('undo'):
138 chore_id
= match
.args()[1]
139 result
= CHORES
.undo(chore_id
)
140 await bot
.api
.send_text_message(
141 room
.room_id
, result
)
144 if match
.command('remove'):
145 chore_id
= match
.args()[1]
146 result
= CHORES
.remove(chore_id
)
147 await bot
.api
.send_text_message(
148 room
.room_id
, result
)