Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy on docker (Sourcery refactored) #2

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .github/workflows/status_updater.yml

This file was deleted.

10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.10-slim

WORKDIR /app

COPY . /app

RUN pip install --upgrade pip && \
pip install python-decouple pytz telethon cryptg

CMD ["python3", "main.py"]
49 changes: 34 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MESSAGE_ID = config("MESSAGE_ID", cast=int)
CHANNEL_NAME = config("CHANNEL_NAME", default="FZX Paradox")
TIME_ZONE = config("TIME_ZONE", default="Asia/Kolkata")
INTERVAL = config("INTERVAL", 300) # Time interval in seconds between checks
except BaseException as ex:
log.info(ex)
exit(1)
Expand Down Expand Up @@ -57,10 +58,14 @@ async def check_bots():

"""
try:
await client.edit_message(CHANNEL_ID, MESSAGE_ID, status_message + f"""**Status Update Stats:**
await client.edit_message(
CHANNEL_ID,
MESSAGE_ID,
f"""{status_message}**Status Update Stats:**
┌ **Bots Verified :** 0 out of {len(BOTS)}
├ **Progress :** [○○○○○○○○○○] 0%
└ **Time Elasped :** 0s""")
└ **Time Elasped :** 0s""",
)
Comment on lines 65 to +68
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_bots refactored with the following changes:

except BaseException as e:
log.warning("[EDIT] Unable to edit message in the channel!")
log.error(e)
Expand All @@ -87,38 +92,44 @@ async def check_bots():
bot_stats[bot] = {"response_time": f"`{round(resp_time * 1000, 2)}ms`", "status": "✅", "host": host or "Unknown"}
except BaseException:
bot_stats[bot] = {"response_time": None, "status": "❌", "host": host or "Unknown"}

await client.send_read_acknowledge(bot)
log.info(f"[CHECK] Checked @{bot} - {bot_stats[bot]['status']}.")
bot_no += 1

await client.edit_message(CHANNEL_ID, MESSAGE_ID, status_message + f"""**Status Update Stats:**

await client.edit_message(
CHANNEL_ID,
MESSAGE_ID,
f"""{status_message}**Status Update Stats:**
┌ **Bots Verified :** {bot_no} out of {len(BOTS)}
├ **Progress :** {progress_bar(bot_no, len(BOTS))}
└ **Time Elasped :** {round(time() - start_time, 2)}s""")
└ **Time Elasped :** {round(time() - start_time, 2)}s""",
)

end_time = time()
log.info("[CHECK] Completed periodic checks.")

status_message = header_msg + f"• **Avaliable Bots :** {avl_bots} out of {len(BOTS)}\n\n"
for bot, value in bot_stats.items():
if bot_stats[bot]["response_time"] is None:
status_message += f"""┌ **Bot :** @{bot}
status_message = (
f"{header_msg}• **Avaliable Bots :** {avl_bots} out of {len(BOTS)}\n\n"
)
for bot in bot_stats:
status_message += (
f"""┌ **Bot :** @{bot}
├ **Status :** {bot_stats[bot]['status']}
└ **Host :** {bot_stats[bot]['host']}

"""
else:
status_message += f"""┌ **Bot :** @{bot}
if bot_stats[bot]["response_time"] is None
else f"""┌ **Bot :** @{bot}
├ **Ping :** {bot_stats[bot]['response_time']}
├ **Status :** {bot_stats[bot]['status']}
└ **Host :** {bot_stats[bot]['host']}

"""

)
total_time = end_time - start_time
status_message += f"• **Last Periodic Checked in {round(total_time, 2)}s**\n\n"

current_time = datetime.now(utc).astimezone(timezone(TIME_ZONE))
status_message += f"""• **Last Check Details :**
┌ **Time :** `{current_time.strftime('%H:%M:%S')} hrs`
Expand All @@ -135,4 +146,12 @@ async def check_bots():
return


client.loop.run_until_complete(check_bots())
async def main():
while True:
log.info("Running periodic check...")
await check_bots()
log.info(f"Sleeping for {INTERVAL} seconds...")
await sleep(INTERVAL)

if __name__ == "__main__":
client.loop.run_until_complete(main())