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.

62 lines
1.7 KiB

#! /usr/bin/python3
Loot notifications
import time
import json
import traceback
import os
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)
bnet_member = "https://{1}{0}?fields=feed,items&locale=es_ES&apikey={2}"
# legends database
items = {}
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "items_legend.json"), 'r') as f:
js = json.load(f)
for item in js:
items[item["item_id"]] = item
members = r.smembers("bot:members") # i need all guild members
request = requests.Session()
for m in members:
member = request.get(url=bnet_member.format(m, conf.battle_net_region, conf.battle_net_apikey)).json()
if "feed" not in member:
for feed in member["feed"]:
if feed["type"] != "LOOT":
fid = "{}-{}".format(m, feed["itemId"])
if feed["itemId"] in items and r.sadd("bot:legends", fid):
wh.send(":tangerine: **{0}** pilla legendario! **[{1}](<{2}>)**".format(member["name"], items[feed["itemId"]]["name_eses"], feed["itemId"]))
Vamos a generar el archivo items_legend.json
Sacar la lista de legends de aquí: view-source:;7;0
Buscar: 'var _ = {};' y copiar toda la línea siguiente
Reemplazar: '_\[(\d+)\]=\{' por '\n{"item_id": \1, '
Reemplazar: ';$' por ','
Añadir los [ ... ]