Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Dec 26, 2023
1 parent 22487bb commit d8d290d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
6 changes: 1 addition & 5 deletions ProjectMan/modules/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ async def module_help(client: Client, message: Message):


def add_command_help(module_name, commands):
if module_name in CMD_HELP.keys():
command_dict = CMD_HELP[module_name]
else:
command_dict = {}

command_dict = CMD_HELP[module_name] if module_name in CMD_HELP.keys() else {}
for x in commands:
for y in x:
if y is not x:
Expand Down
58 changes: 28 additions & 30 deletions ProjectMan/modules/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ async def is_heroku():


async def gen_chlog(repo, diff):
ch_log = ""
d_form = "%d/%m/%y"
for c in repo.iter_commits(diff):
ch_log += (
f"• [{c.committed_datetime.strftime(d_form)}]: {c.summary} <{c.author}>\n"
)
return ch_log
return "".join(
f"• [{c.committed_datetime.strftime(d_form)}]: {c.summary} <{c.author}>\n"
for c in repo.iter_commits(diff)
)


async def updateme_requirements():
Expand Down Expand Up @@ -100,8 +98,6 @@ async def upstream(client: Client, message: Message):
repo.__del__()
return
except InvalidGitRepositoryError:
if conf != "deploy":
pass
repo = Repo.init()
origin = repo.create_remote("upstream", off_repo)
origin.fetch()
Expand All @@ -128,23 +124,21 @@ async def upstream(client: Client, message: Message):
if "deploy" not in conf:
if changelog:
changelog_str = f"**Tersedia Pembaruan Untuk Branch [{ac_br}]:\n\nCHANGELOG:**\n\n`{changelog}`"
if len(changelog_str) > 4096:
await status.edit("**Changelog terlalu besar, dikirim sebagai file.**")
file = open("output.txt", "w+")
file.write(changelog_str)
file.close()
await client.send_document(
message.chat.id,
"output.txt",
caption=f"**Ketik** `{cmd}update deploy` **Untuk Mengupdate Userbot.**",
reply_to_message_id=status.id,
)
remove("output.txt")
else:
if len(changelog_str) <= 4096:
return await status.edit(
f"{changelog_str}\n**Ketik** `{cmd}update deploy` **Untuk Mengupdate Userbot.**",
disable_web_page_preview=True,
)
await status.edit("**Changelog terlalu besar, dikirim sebagai file.**")
with open("output.txt", "w+") as file:
file.write(changelog_str)
await client.send_document(
message.chat.id,
"output.txt",
caption=f"**Ketik** `{cmd}update deploy` **Untuk Mengupdate Userbot.**",
reply_to_message_id=status.id,
)
remove("output.txt")
else:
await status.edit(
f"\n`Your BOT is` **up-to-date** `with branch` **[{ac_br}]**\n",
Expand All @@ -156,18 +150,21 @@ async def upstream(client: Client, message: Message):
import heroku3

heroku = heroku3.from_key(HEROKU_API_KEY)
heroku_app = None
heroku_applications = heroku.apps()
if not HEROKU_APP_NAME:
await status.edit(
"`Please set up the HEROKU_APP_NAME variable to be able to update userbot.`"
)
repo.__del__()
return
for app in heroku_applications:
if app.name == HEROKU_APP_NAME:
heroku_app = app
break
heroku_app = next(
(
app
for app in heroku_applications
if app.name == HEROKU_APP_NAME
),
None,
)
if heroku_app is None:
await status.edit(
f"{txt}\n`Invalid Heroku credentials for updating userbot dyno.`"
Expand All @@ -180,7 +177,7 @@ async def upstream(client: Client, message: Message):
ups_rem.fetch(ac_br)
repo.git.reset("--hard", "FETCH_HEAD")
heroku_git_url = heroku_app.git_url.replace(
"https://", "https://api:" + HEROKU_API_KEY + "@"
"https://", f"https://api:{HEROKU_API_KEY}@"
)
if "heroku" in repo.remotes:
remote = repo.remote("heroku")
Expand Down Expand Up @@ -233,13 +230,14 @@ async def updaterman(client: Client, message: Message):
verification = str(checks.count())
if verification == "":
return await response.edit("Bot is up-to-date!")
updates = ""
ordinal = lambda format: "%d%s" % (
format,
"tsnrhtdd"[(format // 10 % 10 != 1) * (format % 10 < 4) * format % 10 :: 4],
)
for info in repo.iter_commits(f"HEAD..origin/{BRANCH}"):
updates += f"<b>➣ #{info.count()}: [{info.summary}]({REPO_}/commit/{info}) by -> {info.author}</b>\n\t\t\t\t<b>➥ Commited on:</b> {ordinal(int(datetime.fromtimestamp(info.committed_date).strftime('%d')))} {datetime.fromtimestamp(info.committed_date).strftime('%b')}, {datetime.fromtimestamp(info.committed_date).strftime('%Y')}\n\n"
updates = "".join(
f"<b>➣ #{info.count()}: [{info.summary}]({REPO_}/commit/{info}) by -> {info.author}</b>\n\t\t\t\t<b>➥ Commited on:</b> {ordinal(int(datetime.fromtimestamp(info.committed_date).strftime('%d')))} {datetime.fromtimestamp(info.committed_date).strftime('%b')}, {datetime.fromtimestamp(info.committed_date).strftime('%Y')}\n\n"
for info in repo.iter_commits(f"HEAD..origin/{BRANCH}")
)
_update_response_ = "<b>A new update is available for the Bot!</b>\n\n➣ Pushing Updates Now</code>\n\n**<u>Updates:</u>**\n\n"
_final_updates_ = _update_response_ + updates
if len(_final_updates_) > 4096:
Expand Down

0 comments on commit d8d290d

Please sign in to comment.