Skip to content

Commit

Permalink
add: key to producer send
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTheDev committed Apr 11, 2024
1 parent 99bbf93 commit 398dde8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions bot/clan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def send_reminder(time: str, war_unique_id: str, clan_tag: str ,producer: KafkaP
"time" : time,
"data" : war._raw_data
}
producer.send("reminder", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("reminder", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))



Expand Down Expand Up @@ -107,7 +107,7 @@ async def schedule_reminders(reminder_times, war_end_time: coc.Timestamp):
for attack in new_attacks:
json_data = {"type": "new_attack", "war": war._raw_data, "league_group": league_group,
"attack": attack._raw_data, "clan_tag": clan_tag}
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))

previous_league_group = None
if previous_war.is_cwl:
Expand All @@ -118,16 +118,16 @@ async def schedule_reminders(reminder_times, war_end_time: coc.Timestamp):
if previous_war.preparation_start_time and war.preparation_start_time and previous_war.preparation_start_time.time != war.preparation_start_time.time:
if previous_war.state != "warEnded":
json_data = {"type": "war_ended", "war": previous_war._raw_data, "league_group": previous_league_group, "clan_tag": clan_tag}
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
json_data = {"type": "new_war", "war": war._raw_data, "league_group": league_group, "clan_tag": clan_tag}
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
elif war.preparation_start_time and not previous_war.preparation_start_time:
json_data = {"type": "new_war", "war": war._raw_data, "league_group": league_group, "clan_tag": clan_tag}
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))

if war.state != previous_war.state and previous_war.state == "warEnded":
json_data = {"type": "war_ended", "war": previous_war._raw_data, "league_group": previous_league_group, "clan_tag": clan_tag}
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("war", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))



Expand Down Expand Up @@ -165,7 +165,7 @@ async def raid_weekend_track(clan_tags: List[str], db_client: MongoDatabase, coc

for clan in new_clans:
json_data = {"type": "new_offensive_opponent", "clan": clan._raw_data, "clan_tag": clan_tag, "raid": current_raid._raw_data}
producer.send("capital", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("capital", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))

attacked = []
for member in current_raid.members:
Expand All @@ -177,11 +177,11 @@ async def raid_weekend_track(clan_tags: List[str], db_client: MongoDatabase, coc
"clan_tag": current_raid.clan_tag,
"attacked" : attacked,
"raid": current_raid._raw_data}
producer.send("capital", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("capital", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))

if current_raid.state != previous_raid.state:
json_data = {"type": "raid_state", "clan_tag": current_raid.clan_tag, "old_raid": previous_raid._raw_data, "raid": current_raid._raw_data}
producer.send("capital", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("capital", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))


await db_client.capital_cache.bulk_write(db_updates, ordered=False)
Expand All @@ -204,29 +204,29 @@ async def clan_track(clan_tag: str, coc_client: coc.Client, producer: KafkaProdu
for attribute in attributes:
if getattr(clan, attribute) != getattr(previous_clan, attribute):
json_data = {"type": attribute, "old_clan": previous_clan._raw_data, "new_clan": clan._raw_data}
producer.send("clan", value=ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("clan", value=ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
current_tags = set(n.tag for n in previous_clan.members)
if current_tags:
# we can't check the member_count first incase 1 person left and joined within the 60sec.
members_joined = (n for n in clan.members if n.tag not in current_tags)
for member in members_joined:
json_data = {"type": "member_join", "clan": clan._raw_data, "member": member._raw_data}
producer.send("clan", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("clan", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))

current_tags = set(n.tag for n in clan.members)
if current_tags:
members_left = (n for n in previous_clan.members if n.tag not in current_tags)
for member in members_left:
json_data = {"type": "member_leave", "clan": clan._raw_data, "member": member._raw_data}
producer.send("clan", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("clan", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))

previous_donations = {n.tag: (n.donations, n.received) for n in previous_clan.members}
for member in clan.members:
if (member_donated := previous_donations.get(member.tag)) is not None:
mem_donos, mem_received = member_donated
if mem_donos < member.donations or mem_received < member.received:
json_data = {"type": "all_member_donations", "old_clan": previous_clan._raw_data, "new_clan": clan._raw_data}
producer.send("clan", ujson.dumps(json_data).encode("utf-8"), key=clan_tag, timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
producer.send("clan", ujson.dumps(json_data).encode("utf-8"), key=clan_tag.encode("utf-8"), timestamp_ms=int(pend.now(tz=pend.UTC).timestamp() * 1000))
break


0 comments on commit 398dde8

Please sign in to comment.