Added discord webhook for now
This commit is contained in:
parent
0086bb57d8
commit
ca4675c62f
|
|
@ -1,2 +1,3 @@
|
|||
ACCOUNT_EMAIL=email@domain.fr
|
||||
ACCOUNT_PASSWORD=your_password
|
||||
ACCOUNT_PASSWORD=your_password
|
||||
DISCORD_WEBHOOK=https://discord.com/api/webhooks/...
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ TODO:
|
|||
- [ ] Complete API (for selling)
|
||||
- [ ] Add a scoring for cards pulled
|
||||
- [ ] Multiusers
|
||||
²
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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}],
|
||||
},
|
||||
)
|
||||
Loading…
Reference in New Issue