]>
Commit | Line | Data |
---|---|---|
d73bba54 MT |
1 | #!/usr/bin/python3 |
2 | ||
9d5172de MT |
3 | import datetime |
4 | ||
d73bba54 MT |
5 | from .misc import Object |
6 | ||
7 | class Campaigns(Object): | |
b9cb2dee MT |
8 | async def send(self, template, promotional=True, **kwargs): |
9 | """ | |
10 | Sends a message to all users that have consented to promotional messages | |
11 | """ | |
12 | for account in self.backend.accounts.subscribed: | |
13 | # Send the message | |
14 | account.send_message(template, **kwargs) | |
15 | ||
16 | # Remember that we sent a promotional message | |
17 | if promotional: | |
18 | account.promotional_message_sent() | |
9d5172de MT |
19 | |
20 | async def donate(self): | |
21 | """ | |
22 | Runs the donation campain, i.e. sends an email once every two months. | |
23 | """ | |
24 | t = datetime.datetime.now() - datetime.timedelta(days=60) | |
25 | ||
26 | for account in self.backend.accounts.subscribed: | |
27 | # Fall through if we have no timestamp | |
28 | if account.last_promotional_message_sent_at is None: | |
29 | pass | |
30 | ||
31 | # Fall through if we have passed the threshold | |
32 | elif account.last_promotional_message_sent_at <= t: | |
33 | pass | |
34 | ||
35 | # If nothing matched, we skip this user | |
36 | else: | |
37 | continue | |
38 | ||
39 | # Send a donation reminder | |
40 | account.send_message("auth/messages/donation-reminder") | |
41 | ||
42 | # Remember that we sent a promotional message | |
43 | account.promotional_message_sent() |