Skip to content

Commit 051ec7b

Browse files
authored
Merge branch 'development' into development
2 parents 4a20960 + 6e75c44 commit 051ec7b

File tree

3 files changed

+48
-18
lines changed

3 files changed

+48
-18
lines changed

bot.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,33 @@ def check_manual_blocked(self, author: discord.Member) -> bool:
794794
logger.debug("User blocked, user %s.", author.name)
795795
return False
796796

797+
def check_local_git(self) -> bool:
798+
"""
799+
Checks if the bot is installed via git.
800+
"""
801+
valid_local_git = False
802+
git_folder_path = os.path.join(".git")
803+
804+
# Check if the .git folder exists and is a directory
805+
if os.path.exists(git_folder_path) and os.path.isdir(git_folder_path):
806+
required_files = ["config", "HEAD"]
807+
required_dirs = ["refs", "objects"]
808+
809+
# Verify required files exist
810+
for file in required_files:
811+
if not os.path.isfile(os.path.join(git_folder_path, file)):
812+
return valid_local_git
813+
814+
# Verify required directories exist
815+
for directory in required_dirs:
816+
if not os.path.isdir(os.path.join(git_folder_path, directory)):
817+
return valid_local_git
818+
819+
# If all checks pass, set valid_local_git to True
820+
valid_local_git = True
821+
822+
return valid_local_git
823+
797824
async def _process_blocked(self, message):
798825
_, blocked_emoji = await self.retrieve_emoji()
799826
if await self.is_blocked(message.author, channel=message.channel, send_message=True):
@@ -2160,6 +2187,12 @@ async def before_autoupdate(self):
21602187
self.autoupdate.cancel()
21612188
return
21622189

2190+
if not self.check_local_git():
2191+
logger.warning("Bot not installed via git.")
2192+
logger.warning("Autoupdates disabled.")
2193+
self.autoupdate.cancel()
2194+
return
2195+
21632196
@tasks.loop(hours=1, reconnect=False)
21642197
async def log_expiry(self):
21652198
log_expire_after = self.config.get("log_expiration")

cogs/utility.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,11 +2134,7 @@ async def update(self, ctx, *, flag: str = ""):
21342134
data = await self.bot.api.get_user_info()
21352135
if data:
21362136
user = data["user"]
2137-
embed.set_author(
2138-
name=user["username"],
2139-
icon_url=user["avatar_url"] if user["avatar_url"] else None,
2140-
url=user["url"],
2141-
)
2137+
embed.set_author(name=user["username"], icon_url=user["avatar_url"], url=user["url"])
21422138
await ctx.send(embed=embed)
21432139
else:
21442140
error = None
@@ -2177,7 +2173,7 @@ async def update(self, ctx, *, flag: str = ""):
21772173

21782174
embed.set_author(
21792175
name=user["username"] + " - Updating bot",
2180-
icon_url=user["avatar_url"] if user["avatar_url"] else None,
2176+
icon_url=user["avatar_url"],
21812177
url=user["url"],
21822178
)
21832179

@@ -2195,13 +2191,18 @@ async def update(self, ctx, *, flag: str = ""):
21952191
color=self.bot.main_color,
21962192
)
21972193
embed.set_footer(text="Force update")
2198-
embed.set_author(
2199-
name=user["username"],
2200-
icon_url=user["avatar_url"] if user["avatar_url"] else None,
2201-
url=user["url"],
2202-
)
2194+
embed.set_author(name=user["username"], icon_url=user["avatar_url"], url=user["url"])
22032195
await ctx.send(embed=embed)
22042196
else:
2197+
if self.bot.check_local_git() is False:
2198+
embed = discord.Embed(
2199+
title="Update Command Unavailable",
2200+
description="The bot cannot be updated due to not being installed via git."
2201+
"You need to manually update the bot according to your hosting method."
2202+
"If you face any issues please don´t hesitate to contact modmail support.",
2203+
color=discord.Color.red(),
2204+
)
2205+
return await ctx.send(embed=embed)
22052206
command = "git pull"
22062207
proc = await asyncio.create_subprocess_shell(
22072208
command,
@@ -2214,11 +2215,7 @@ async def update(self, ctx, *, flag: str = ""):
22142215
res = res.decode("utf-8").rstrip()
22152216

22162217
if err and not res:
2217-
embed = discord.Embed(
2218-
title="Update failed",
2219-
description=err,
2220-
color=self.bot.error_color,
2221-
)
2218+
embed = discord.Embed(title="Update failed", description=err, color=self.bot.error_color)
22222219
await ctx.send(embed=embed)
22232220

22242221
elif res != "Already up to date.":

core/config_help.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@
533533
"notes": [
534534
"When `recipient_thread_close` is enabled and the recipient closed their own thread, `thread_self_close_response` is used instead of this configuration.",
535535
"You may use the `{{closer}}` variable for access to the [Member](https://discordpy.readthedocs.io/en/latest/api.html#discord.Member) that closed the thread.",
536-
"`{{loglink}}` can be used as a placeholder substitute for the full URL linked to the thread in the log viewer and `{{loglink}}` for the unique key (ie. s3kf91a) of the log.",
536+
"`{{loglink}}` can be used as a placeholder substitute for the full URL linked to the thread in the log viewer and `{{logkey}}` for the unique key (ie. s3kf91a) of the log.",
537537
"Discord flavoured markdown is fully supported in `thread_close_response`.",
538538
"See also: `thread_close_title`, `thread_close_footer`, `thread_self_close_response`, `thread_creation_response`."
539539
]
@@ -547,7 +547,7 @@
547547
"notes": [
548548
"When `recipient_thread_close` is disabled or the thread wasn't closed by the recipient, `thread_close_response` is used instead of this configuration.",
549549
"You may use the `{{closer}}` variable for access to the [Member](https://discordpy.readthedocs.io/en/latest/api.html#discord.Member) that closed the thread.",
550-
"`{{loglink}}` can be used as a placeholder substitute for the full URL linked to the thread in the log viewer and `{{loglink}}` for the unique key (ie. s3kf91a) of the log.",
550+
"`{{loglink}}` can be used as a placeholder substitute for the full URL linked to the thread in the log viewer and `{{logkey}}` for the unique key (ie. s3kf91a) of the log.",
551551
"Discord flavoured markdown is fully supported in `thread_self_close_response`.",
552552
"See also: `thread_close_title`, `thread_close_footer`, `thread_close_response`."
553553
]

0 commit comments

Comments
 (0)