Skip to content

Commit 9bfdfa4

Browse files
committed
Updated coffee example
1 parent 9546bcd commit 9bfdfa4

File tree

10 files changed

+14
-34
lines changed

10 files changed

+14
-34
lines changed

Examples/Additional Application Layer Example/Coffee/app/app.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

Examples/Additional Application Layer Example/Coffee/main_coffee.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@
33
This is an example of an additional application layer you can build with this framework.
44
The application sends a message saying 'Good morning' every day at 10 AM and then sends a picture of a coffe cup from a randomized list.
55
"""
6-
from datetime import timedelta
6+
import os
77
import daf
8-
import app.app
9-
from daf import discord
10-
8+
import random
9+
from datetime import datetime, timedelta
1110

11+
@daf.data_function
12+
def get_data(storage: list):
13+
now = datetime.now()
14+
if not len(storage):
15+
storage += [os.path.join("./images", x) for x in os.listdir("./images")]
16+
random.shuffle(storage)
1217

18+
image = storage.pop()
19+
text = "Good morning ({:02d}.{:02d}.{:02d} - {:02d}:{:02d}:{:02d})".format(now.day, now.month,now.year,now.hour,now.minute, now.second)
20+
return text, daf.FILE(image) # Return message to be sent
1321

22+
now = datetime.now()
1423
servers = [
1524
daf.GUILD(
1625
snowflake=123456789,
1726
messages=[
1827

19-
daf.TextMESSAGE(start_period=None, end_period=timedelta(seconds=10), data=app.app.get_data(), channels=[123456789], mode="send", start_in=timedelta(seconds=0))
28+
daf.TextMESSAGE(start_period=None, end_period=timedelta(days=1), data=get_data([]), channels=[123456789], mode="send", start_in=now.replace(second=0, microsecond=0, minute=0, hour=10) + timedelta(days=1) - now)
2029
],
2130
logging=True
2231
)

0 commit comments

Comments
 (0)