Scripts for guild notifications using Discord Webhooks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
980 B

#! /usr/bin/python3
"""
WarcrafLogs notifications
"""
import time
import sys
import redis
import requests
import webhook
import conf
now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook_guild)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
r.zremrangebyscore("bot:warcraftlogs", "-inf", now-(60*60*24*30*12)) # 12 meses
wl_api = "https://www.warcraftlogs.com/v1/reports/guild/mirrors/dun-modr/eu?api_key={0}".format(conf.warcraftlogs_token)
wl = requests.get(url=wl_api).json()
if "error" in wl:
print(wl)
sys.exit()
for report in wl:
if report["start"]/1000 < now-(60*60*24*7): # oooold, 7 day only
continue
if not r.zadd("bot:warcraftlogs", now, report["id"]):
continue
url = "https://www.warcraftlogs.com/reports/{0}".format(report["id"])
wh.send("{3} Logs! **[{2}](<{1}>)** por **{0}**".format(report["owner"], url, report["title"], conf.icon_warcraftlogs))
time.sleep(2)