diff --git a/.env.example b/.env.example index ef47b93..8ea1c12 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ ACCOUNT_EMAIL=email@domain.fr -ACCOUNT_PASSWORD=your_password \ No newline at end of file +ACCOUNT_PASSWORD=your_password +DISCORD_WEBHOOK=https://discord.com/api/webhooks/... diff --git a/README.md b/README.md index c58e884..d418cc7 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,4 @@ TODO: - [ ] Complete API (for selling) - [ ] Add a scoring for cards pulled - [ ] Multiusers +² \ No newline at end of file diff --git a/src/app.py b/src/app.py index c3afd34..39662cf 100644 --- a/src/app.py +++ b/src/app.py @@ -6,6 +6,7 @@ from pathlib import Path # from sqlalchemy import create_engine from .lib.utils import EveryRunRotator from .services.wiki_masters import WikiMastersClient, UserSession +from .services.discord import DiscordClient from dotenv import load_dotenv from datetime import datetime, timedelta, timezone @@ -59,8 +60,11 @@ class App: if packs_remaining == 10 or next_pack_in < timedelta(seconds=20): packs_remaining, packs_last_regen_at, cards = user.pull() + content = "" for card in cards: - logger.info("Pulled [{}] {} (uid={})", card.rarity, card.name, card._id) + content += "- [%s] [%s](%s)\n" % (card.rarity, card.name, card.url) + DiscordClient.send_message(content) + next_pack_in = WikiMastersClient.ONE_PACK_TIME - ( datetime.now(tz=timezone.utc) - packs_last_regen_at @@ -86,6 +90,7 @@ class App: def start(self): logger.info("Starting the bot...") + DiscordClient.send_message("### The bot is starting !") wm_client = WikiMastersClient() self.users["pasterp"] = wm_client.login( diff --git a/src/services/discord.py b/src/services/discord.py new file mode 100644 index 0000000..ba0c31c --- /dev/null +++ b/src/services/discord.py @@ -0,0 +1,17 @@ +from os import environ +import httpx + +TYPE_TEXT_DISPLAY = 10 + + +class DiscordClient: + @staticmethod + def send_message(msg: str): + url = environ["DISCORD_WEBHOOK"] + httpx.post( + f"{url}?with_components=true", + json={ + "flags": 1 << 15, + "components": [{"type": TYPE_TEXT_DISPLAY, "content": msg}], + }, + )