From 2dc223451783185285255bcd2d8f587ea7899b66 Mon Sep 17 00:00:00 2001 From: djerfy Date: Sun, 26 May 2024 12:50:42 +0200 Subject: [PATCH 1/2] feat: improve discord absorb hook Signed-off-by: djerfy --- hooks/discord_absorb.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hooks/discord_absorb.py b/hooks/discord_absorb.py index a0dd0a2..7fa08b5 100755 --- a/hooks/discord_absorb.py +++ b/hooks/discord_absorb.py @@ -15,23 +15,31 @@ def load_config(): async def discord_blocks_farmed(absorbeb_coins): config = load_config() absorbeb_coins = json.loads(absorbeb_coins.strip()) - farmed_heights = [] - farmers = set() + farmers = [] + for coin, farmer_record in absorbeb_coins: farmed_heights.append( str(int.from_bytes(bytes.fromhex( coin['coin']['parent_coin_info'][2:])[16:], 'big' )) ) - farmers.add(farmer_record['name'] or farmer_record['launcher_id']) + farmers.append(farmer_record) - coins_blocks = ', '.join([f'#{i}' for i in farmed_heights]) - farmed_by = ', '.join(farmers) + coins_blocks = ", ".join([f"[#{i}](https://www.spacescan.io/block/{i})" for i in farmed_heights]) + farmed_by = ", ".join([f"[{f['name'] or f['launcher_id']}](https://openchia.io/en/explorer/farmer/{f['launcher_id'].split('x')[1]})" for f in farmers]) async with aiohttp.request('POST', config['hook_discord_absorb']['url'], json={ - 'content': f"New block(s) farmed! {coins_blocks}. Farmed by {farmed_by}.", 'username': config['hook_discord_absorb']['username'], + 'embeds': [{ + 'title': '🏆 New block(s) farmed!', + 'description': f'New block(s) farmed! {coins_blocks}. Farmed by {farmed_by}.', + 'color': 1350400, + 'footer': { + 'text': 'Powered by openchia.io' + }, + 'timestamp': str(datetime.datetime.now(datetime.UTC)) + }] }) as r: pass From 1d08d9d5ed1a3971ff27f6cf56ea88e41ac132cd Mon Sep 17 00:00:00 2001 From: djerfy Date: Sun, 26 May 2024 12:52:13 +0200 Subject: [PATCH 2/2] misc: import datetime module Signed-off-by: djerfy --- hooks/discord_absorb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/discord_absorb.py b/hooks/discord_absorb.py index 7fa08b5..d7b4b3e 100755 --- a/hooks/discord_absorb.py +++ b/hooks/discord_absorb.py @@ -5,7 +5,7 @@ import os import sys import yaml - +import datetime def load_config(): with open(os.environ['CONFIG_PATH'], 'r') as f: