new guild, new fixes. Now is more generic.

This commit is contained in:
Sergio Álvarez 2017-08-31 17:21:23 +02:00
parent 0822fe28d9
commit f3f31ed8ca
12 changed files with 94 additions and 78 deletions

View File

@ -1,10 +1,11 @@
#! /usr/bin/python3 #! /usr/bin/python3
import datetime import datetime
import time
import webhook import webhook
import conf import conf
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_news)
week = (int(datetime.datetime.now().strftime("%V")) % len(conf.affix_rotation)) - 1 week = (int(datetime.datetime.now().strftime("%V")) % len(conf.affix_rotation)) - 1
@ -14,3 +15,4 @@ for s in conf.affix_rotation[week]:
wh.add_embed(webhook.embed(color=0x3f89ff, fields=f)) wh.add_embed(webhook.embed(color=0x3f89ff, fields=f))
wh.send("**[Affixes de esta semana](<https://mythicpl.us/>)**") wh.send("**[Affixes de esta semana](<https://mythicpl.us/>)**")
time.sleep(2)

62
conf.py
View File

@ -1,26 +1,28 @@
from tokens import * from tokens import *
icon_wowhead = "<:wowhead:283900950379233280>" icon_wowhead = "<:wowhead:352756406925000704>"
icon_mmoc = "<:MMOChampion:283900921694650368>" icon_mmoc = "<:MMOChampion:352756407109681153>"
icon_twitch = "<:twitch:332609778285019137>" icon_twitch = "<:twitch:352756406904160257>"
icon_warcraftlogs = "<:Warcraftlogs:283906655484379138>" icon_warcraftlogs = "<:Warcraftlogs:352756407164076034>"
min_mythic = 10
affixes = { affixes = {
"Bullente": "<:m_teeming:278565188410802176>", "Bullente": "<:m_teeming:352756406514089994>",
"Detonante": "<:m_bursting:327109581048250369>", "Detonante": "<:m_bursting:352760092397010944>",
"Dolorosa": "<:m_grievous:327109581132136449>", "Dolorosa": "<:m_grievous:352760092472377344>",
"Explosiva": "<:m_explosive:327109581249576960>", "Explosiva": "<:m_explosive:352760091981905932>",
"Furibunda": "<:m_raging:278565187986915328>", "Furibunda": "<:m_raging:352756406492987394>",
"Inquieta": "<:m_skittish:278565188087840768>", "Inquieta": "<:m_skittish:352756406497181698>",
"Necrótica": "<:m_necro:278565187634593795>", "Necrótica": "<:m_necro:352756406333472769>",
"Potenciante": "<:m_bolstering:278565187987046400>", "Potenciante": "<:m_bolstering:352756406509633536>",
"Rebosante": "<:m_over:278565188033314816>", "Rebosante": "<:m_over:352756406463758337>",
"Reforzada": "<:m_forti:278565187588456450>", "Reforzada": "<:m_forti:352756406497050624>",
"Sanguina": "<:m_sanguine:278565188020469760>", "Sanguina": "<:m_sanguine:352756406153379844>",
"Sísmica": "<:m_quaking:327109581236862976>", "Sísmica": "<:m_quaking:352760093118300160>",
"Tiránica": "<:m_tyra:278565187852828674>", "Tiránica": "<:m_tyra:352756406279208964>",
"Volcánica": "<:m_volcanic:278565188125458432>" "Volcánica": "<:m_volcanic:352756406341992449>"
} }
affix_human = { affix_human = {
@ -86,18 +88,18 @@ timers = {
} }
class_icons = { class_icons = {
"Character--WARRIOR": "<:class_warrior:278565187257237505>", "Character--WARRIOR": "<:class_warrior:352756406232809483>",
"Character--DRUID": "<:class_druid:278565188381442048>", "Character--DRUID": "<:class_druid:352756406421815296>",
"Character--HUNTER": "<:class_hunter:278565187605364737>", "Character--HUNTER": "<:class_hunter:352756406278946827>",
"Character--DEATHKNIGHT": "<:class_deathknight:278565187903029248>", "Character--DEATHKNIGHT": "<:class_deathknight:352756406408970240>",
"Character--MAGE": "<:class_mage:278565187919937537>", "Character--MAGE": "<:class_mage:352756406035808258>",
"Character--DEMONHUNTER": "<:class_demonhunter:278565187500376065>", "Character--DEMONHUNTER": "<:class_demonhunter:352756406425878528>",
"Character--PRIEST": "<:class_priest:278565187970269184>", "Character--PRIEST": "<:class_priest:352756406299918337>",
"Character--PALADIN": "<:class_paladin:278565187588587521>", "Character--PALADIN": "<:class_paladin:352756406446981130>",
"Character--SHAMAN": "<:class_shaman:278565187831726081>", "Character--SHAMAN": "<:class_shaman:352756406459432960>",
"Character--ROGUE": "<:class_rogue:278565187940909056>", "Character--ROGUE": "<:class_rogue:352756406455107584>",
"Character--WARLOCK": "<:class_warlock:278565187596976130>", "Character--WARLOCK": "<:class_warlock:352756406476341248>",
"Character--MONK": "<:class_monk:278565187618078722>" "Character--MONK": "<:class_monk:352756406337798145>"
} }
#stop here! #stop here!

View File

@ -9,13 +9,13 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_guild)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
bnet_achs = conf.battle_net_url("https://{0}.api.battle.net/wow/data/guild/achievements?locale=es_ES&apikey={1}") bnet_achs = conf.battle_net_url("https://{0}.api.battle.net/wow/data/guild/achievements?locale=es_ES&apikey={1}")
bnet_guild = conf.battle_net_url("https://{0}.api.battle.net/wow/guild/dun%20modr/vagrant%20story?fields=news,members,achievements&locale=es_ES&apikey={1}") bnet_guild = conf.battle_net_url("https://{0}.api.battle.net/wow/guild/dun%20modr/farm%20and%20furious?fields=news,members,achievements&locale=es_ES&apikey={1}")
a = requests.get(url=bnet_achs).json() a = requests.get(url=bnet_achs).json()
g = requests.get(url=bnet_guild).json() g = requests.get(url=bnet_guild).json()
@ -38,10 +38,12 @@ for new in chars.difference(members):
r.sadd("bot:members", new) r.sadd("bot:members", new)
members.add(new) members.add(new)
wh.send(":inbox_tray: **{0}** ha entrado a la guild! 🎉".format(new)) wh.send(":inbox_tray: **{0}** ha entrado a la guild! 🎉".format(new))
time.sleep(2)
for kick in members.difference(chars): for kick in members.difference(chars):
r.srem("bot:members", kick) r.srem("bot:members", kick)
wh.send(":outbox_tray: **{0}** ha salido a la guild :confused:".format(kick)) wh.send(":outbox_tray: **{0}** ha salido a la guild :confused:".format(kick))
time.sleep(2)
@ -67,7 +69,6 @@ for news in g["news"]:
continue continue
wh.send(push) wh.send(push)
time.sleep(2) # prevent rate limit, for example with boss FK time.sleep(2) # prevent rate limit, for example with boss FK
@ -107,7 +108,8 @@ for new in set(g["achievements"]["achievementsCompleted"]).difference(achievemen
url = "http://es.wowhead.com/achievement={0}".format(new) url = "http://es.wowhead.com/achievement={0}".format(new)
icon = "https://wow.zamimg.com/images/wow/icons/large/{0}.jpg".format(ach["icon"]) icon = "https://wow.zamimg.com/images/wow/icons/large/{0}.jpg".format(ach["icon"])
wh.clear_embeds()
wh.add_embed(webhook.embed(title=ach["title"], url="http://es.wowhead.com/achievement={0}".format(new), description=ach["description"], thumbnail=webhook.image(icon))) wh.add_embed(webhook.embed(title=ach["title"], url="http://es.wowhead.com/achievement={0}".format(new), description=ach["description"], thumbnail=webhook.image(icon)))
wh.send(":clap: Vagrant Story ha ganado un logro!") wh.send(":clap: La guild ha ganado un logro!")
time.sleep(2) time.sleep(2)

10
loot.py
View File

@ -11,9 +11,9 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_guild)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
bnet_member = "https://{1}.api.battle.net/wow/character/dun%20modr/{0}?fields=feed,items&locale=es_ES&apikey={2}" bnet_member = "https://{1}.api.battle.net/wow/character/dun%20modr/{0}?fields=feed,items&locale=es_ES&apikey={2}"
@ -35,16 +35,16 @@ for m in members:
if "feed" not in member: if "feed" not in member:
continue continue
for feed in member["feed"]: for feed in member["feed"]:
if feed["type"] != "LOOT": if feed["type"] != "LOOT":
continue continue
fid = "{}-{}".format(m, feed["itemId"]) fid = "{}-{}".format(m, feed["itemId"])
if feed["itemId"] in items and r.sadd("bot:legends", fid): if feed["itemId"] in items and r.sadd("bot:legends", fid):
#r.rpush("bot:rss:new", ":unicorn: **{0}** pilla legendario! **{1}**! <http://es.wowhead.com/item={2}>".format(member["name"], items[feed["itemId"]]["name_eses"], feed["itemId"]) )
wh.send(":tangerine: **{0}** pilla legendario! **[{1}](<http://es.wowhead.com/item={2}>)**".format(member["name"], items[feed["itemId"]]["name_eses"], feed["itemId"])) wh.send(":tangerine: **{0}** pilla legendario! **[{1}](<http://es.wowhead.com/item={2}>)**".format(member["name"], items[feed["itemId"]]["name_eses"], feed["itemId"]))
time.sleep(2)
except: except:
traceback.print_exc() traceback.print_exc()

View File

@ -12,9 +12,9 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_guild)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
warcraft_api = "https://worldofwarcraft.com/es-es/game/pve/leaderboards/dun-modr/{}" warcraft_api = "https://worldofwarcraft.com/es-es/game/pve/leaderboards/dun-modr/{}"
@ -31,7 +31,7 @@ for zone, instance in conf.zones.items():
if len(top) < 3: if len(top) < 3:
print("no affix?") print("no affix?")
continue continue
affix = "" if top[0] not in conf.affixes else conf.affixes[top[0]] affix = "" if top[0] not in conf.affixes else conf.affixes[top[0]]
affix += "" if top[1] not in conf.affixes else conf.affixes[top[1]] affix += "" if top[1] not in conf.affixes else conf.affixes[top[1]]
affix += "" if top[2] not in conf.affixes else conf.affixes[top[2]] affix += "" if top[2] not in conf.affixes else conf.affixes[top[2]]
@ -53,7 +53,7 @@ for zone, instance in conf.zones.items():
inguild = False inguild = False
party = [] party = []
if lvl < 15 or r.zadd("bot:m+", now, k) == 0: if lvl < conf.min_mythic or r.zadd("bot:m+", now, k) == 0:
continue continue
for player in team: for player in team:
@ -71,7 +71,7 @@ for zone, instance in conf.zones.items():
for member in members: for member in members:
if "/{}".format(member).lower() in url and "dun-modr" in url: if "/{}".format(member).lower() in url and "dun-modr" in url:
inguild = True inguild = True
if inguild: if inguild:
chests = 0 chests = 0
for timer in conf.timers[zone]: for timer in conf.timers[zone]:
@ -85,8 +85,8 @@ for zone, instance in conf.zones.items():
#tip = "(piedra +{0} por {1})".format(chests, delta) #tip = "(piedra +{0} por {1})".format(chests, delta)
tip = "(piedra +{0})".format(chests, delta) tip = "(piedra +{0})".format(chests, delta)
msg = ":mega: **[{0}](<{5}>) +{1}** hecha en **{2}** {3}, **rank {4}** de Dun Modr".format(instance, lvl, record, tip, pos, warcraft_api.format(zone)) msg = ":mega: **[{0}](<{5}>) +{1}** hecha en **{2}** {3}, **rank {4}** de Dun Modr".format(instance, lvl, record, tip, pos, warcraft_api.format(zone))
#r.rpush("bot:rss:new", msg)
#print(msg) #print(msg)
wh.clear_embeds()
wh.add_embed(webhook.embed(title=", ".join(party))) wh.add_embed(webhook.embed(title=", ".join(party)))
wh.send(msg) wh.send(msg)

8
rss.py
View File

@ -9,9 +9,9 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_news)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
r.zremrangebyscore("bot:rss", "-inf", now-(60*60*24*30*3)) # 3 meses de caché r.zremrangebyscore("bot:rss", "-inf", now-(60*60*24*30*3)) # 3 meses de caché
url_feeds = [ url_feeds = [
@ -25,7 +25,7 @@ for url in url_feeds:
if "items" not in feed or len(feed["items"]) < 3: if "items" not in feed or len(feed["items"]) < 3:
continue continue
for i in [0, 1, 2]: # 3 últimas noticias for i in [0, 1, 2]: # 3 últimas noticias
entry = feed["items"][i] entry = feed["items"][i]
fid = "{} {}".format(feed["feed"]["title"][0:20], entry["published"]) fid = "{} {}".format(feed["feed"]["title"][0:20], entry["published"])
@ -39,8 +39,8 @@ for url in url_feeds:
else: else:
icon = ":newspaper2:" icon = ":newspaper2:"
#r.rpush("bot:rss:new", "{2} {0}\n<{1}>".format(entry["title"], entry["link"], icon))
wh.send("{2} [{0}](<{1}>)".format(entry["title"], entry["link"], icon)) wh.send("{2} [{0}](<{1}>)".format(entry["title"], entry["link"], icon))
time.sleep(2)
except: except:
print(url) print(url)

View File

@ -9,9 +9,9 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_news)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
twitch_api = "https://api.twitch.tv/kraken/streams/followed?oauth_token={0}".format(conf.twitch_token) twitch_api = "https://api.twitch.tv/kraken/streams/followed?oauth_token={0}".format(conf.twitch_token)
@ -27,5 +27,5 @@ for stream in t["streams"]:
if r.zadd("bot:twitch", now, stream["channel"]["name"]) == 0: if r.zadd("bot:twitch", now, stream["channel"]["name"]) == 0:
continue continue
#r.rpush("bot:rss:new", ":projector: **{0}** está stremeando <{1}>".format(stream["channel"]["name"], stream["channel"]["url"]))
wh.send("{3} **{0}** está stremeando: [{2}](<{1}>)".format(stream["channel"]["name"], stream["channel"]["url"], stream["channel"]["status"], conf.icon_twitch)) wh.send("{3} **{0}** está stremeando: [{2}](<{1}>)".format(stream["channel"]["name"], stream["channel"]["url"], stream["channel"]["status"], conf.icon_twitch))
time.sleep(2)

10
tokens-sample.py Normal file
View File

@ -0,0 +1,10 @@
url_discord_webhook_guild = "https://discordapp.com/api/webhooks/???/???????"
url_discord_webhook_news = "https://discordapp.com/api/webhooks/???/???????"
battle_net_region = "eu"
battle_net_apikey = "????"
twitch_token = "?????"
warcraftlogs_token = "???????"

View File

@ -1,9 +0,0 @@
url_discord_webhook = "https://discordapp.com/api/webhooks/???/???????"
battle_net_region = "eu"
battle_net_apikey = "????"
twitch_token = "?????"
warcraftlogs_token = "???????"

View File

@ -8,12 +8,12 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_guild)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) 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 r.zremrangebyscore("bot:warcraftlogs", "-inf", now-(60*60*24*30*12)) # 12 meses
wl_api = "https://www.warcraftlogs.com/v1/reports/guild/vagrant%20story/dun-modr/eu?api_key={0}".format(conf.warcraftlogs_token) wl_api = "https://www.warcraftlogs.com/v1/reports/guild/farm%20and%20furious/dun-modr/eu?api_key={0}".format(conf.warcraftlogs_token)
wl = requests.get(url=wl_api).json() wl = requests.get(url=wl_api).json()
@ -25,5 +25,5 @@ for report in wl:
continue continue
url = "https://www.warcraftlogs.com/reports/{0}".format(report["id"]) url = "https://www.warcraftlogs.com/reports/{0}".format(report["id"])
#r.rpush("bot:rss:new", "<:Warcraftlogs:283906655484379138> Log en vivo! **{2}** por **{0}** en <{1}>".format(report["owner"], url, report["title"]))
wh.send("{3} Logs! **[{2}](<{1}>)** por **{0}**".format(report["owner"], url, report["title"], conf.icon_warcraftlogs)) wh.send("{3} Logs! **[{2}](<{1}>)** por **{0}**".format(report["owner"], url, report["title"], conf.icon_warcraftlogs))
time.sleep(2)

View File

@ -13,8 +13,8 @@ class Webhook():
def __init__(self, url, **kwargs): def __init__(self, url, **kwargs):
self.url = url self.url = url
self.wh = { self.wh = {
"username": kwargs.get("username", None), #"username": kwargs.get("username", None),
"avatar_url": kwargs.get("avatar_url", None), #"avatar_url": kwargs.get("avatar_url", None),
"content": None, "content": None,
"embeds": [] "embeds": []
} }
@ -34,8 +34,16 @@ class Webhook():
r = self.requests.post(self.url, json=self.wh) r = self.requests.post(self.url, json=self.wh)
if "X-RateLimit-Remaining" in r.headers and int(r.headers["X-RateLimit-Remaining"]) <= 5: if "X-RateLimit-Remaining" in r.headers and int(r.headers["X-RateLimit-Remaining"]) <= 1:
raise Exception("RateLimit {0}/{1}, reset in ~{2}s".format(r.headers["X-RateLimit-Remaining"], r.headers["X-RateLimit-Limit"], int(r.headers["X-RateLimit-Reset"])-int(now))) wait = int(r.headers["X-RateLimit-Reset"])-int(now)
raise Exception("RateLimit {0}/{1}, reset in ~{2}s".format(r.headers["X-RateLimit-Remaining"], r.headers["X-RateLimit-Limit"], wait))
"""rl = "RateLimit {0}/{1}, reset in ~{2}s".format(r.headers["X-RateLimit-Remaining"], r.headers["X-RateLimit-Limit"], wait)
if wait < 600:
print(rl)
time.sleep(wait+1)
else:
raise Exception(rl)"""
if r.text != "": if r.text != "":
raise Exception("Webhook error: {0}".format(r.text)) raise Exception("Webhook error: {0}".format(r.text))

View File

@ -8,11 +8,11 @@ import conf
now = time.time() now = time.time()
wh = webhook.Webhook(conf.url_discord_webhook) wh = webhook.Webhook(conf.url_discord_webhook_guild)
r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True) r = redis.StrictRedis(host='localhost', charset="utf-8", decode_responses=True, db=1)
wp_api = "http://www.wowprogress.com/guild/eu/dun-modr/VaGRaNT+SToRY/json_rank" wp_api = "http://www.wowprogress.com/guild/eu/dun-modr/Farm+and+Furious/json_rank"
rank = requests.get(url=wp_api).json() rank = requests.get(url=wp_api).json()
@ -22,18 +22,19 @@ if rank is not None and "realm_rank" in rank:
msg = None msg = None
if last is None: if last is None:
msg = ":arrow_right: Vagrant entra en el ranking de Dun Modr: **{0}**".format(realm) msg = ":arrow_right: La guild entra en el ranking de Dun Modr: **{0}**".format(realm)
elif int(last) > int(rank["realm_rank"]): elif int(last) > int(rank["realm_rank"]):
msg = ":arrow_up: Vagrant sube en el ranking de Dun Modr: **{0}** (+{1})".format(realm, int(last)-int(realm)) msg = ":arrow_up: La guild sube en el ranking de Dun Modr: **{0}** (+{1})".format(realm, int(last)-int(realm))
elif int(last) < int(realm): elif int(last) < int(realm):
msg = ":arrow_down: Vagrant baja en el ranking de Dun Modr: **{0}** (-{1})".format(realm, int(realm)-int(last)) msg = ":arrow_down: La guild baja en el ranking de Dun Modr: **{0}** (-{1})".format(realm, int(realm)-int(last))
elif int(last) == int(realm): elif int(last) == int(realm):
msg = ":ok_hand: Vagrant se mantiene en el ranking de Dun Modr: **{0}**".format(realm) msg = ":ok_hand: La guild se mantiene en el ranking de Dun Modr: **{0}**".format(realm)
r.set("bot:wowprogress", realm) r.set("bot:wowprogress", realm)
if msg: if msg:
wh.send(msg) wh.send(msg)
time.sleep(2)