Skip to content
Closed
33 changes: 33 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,33 @@ def check_manual_blocked(self, author: discord.Member) -> bool:
logger.debug("User blocked, user %s.", author.name)
return False

def check_local_git(self) -> bool:
"""
Checks if the bot is installed via git.
"""
valid_local_git = False
git_folder_path = os.path.join(".git")

# Check if the .git folder exists and is a directory
if os.path.exists(git_folder_path) and os.path.isdir(git_folder_path):
required_files = ["config", "HEAD"]
required_dirs = ["refs", "objects"]

# Verify required files exist
for file in required_files:
if not os.path.isfile(os.path.join(git_folder_path, file)):
return valid_local_git

# Verify required directories exist
for directory in required_dirs:
if not os.path.isdir(os.path.join(git_folder_path, directory)):
return valid_local_git

# If all checks pass, set valid_local_git to True
valid_local_git = True

return valid_local_git

async def _process_blocked(self, message):
_, blocked_emoji = await self.retrieve_emoji()
if await self.is_blocked(message.author, channel=message.channel, send_message=True):
Expand Down Expand Up @@ -2160,6 +2187,12 @@ async def before_autoupdate(self):
self.autoupdate.cancel()
return

if not self.check_local_git():
logger.warning("Bot not installed via git.")
logger.warning("Autoupdates disabled.")
self.autoupdate.cancel()
return

@tasks.loop(hours=1, reconnect=False)
async def log_expiry(self):
log_expire_after = self.config.get("log_expiration")
Expand Down
23 changes: 19 additions & 4 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ async def alias_raw(self, ctx, *, name: str.lower):

return await ctx.send(embed=embed)

async def make_alias(self, name, value, action):
async def make_alias(self, name, value, action, ctx):
values = utils.parse_alias(value)
if not values:
embed = discord.Embed(
Expand Down Expand Up @@ -1176,16 +1176,23 @@ async def make_alias(self, name, value, action):
if multiple_alias:
embed.description = (
"The command you are attempting to point "
f"to does not exist: `{linked_command}`."
f"to on step {i} does not exist: `{linked_command}`."
)
else:
embed.description = (
"The command you are attempting to point "
f"to on step {i} does not exist: `{linked_command}`."
f"to does not exist: `{linked_command}`."
)

return embed
else:
if linked_command == "eval" and not await checks.check_permissions(ctx, "eval"):
embed = discord.Embed(
title="Error",
description="You can only add the `eval` command to an alias if you have permissions for that command.",
color=self.bot.error_color,
)
return embed
save_aliases.append(val)
if multiple_alias:
embed.add_field(name=f"Step {i}:", value=utils.truncate(val, 1024))
Expand Down Expand Up @@ -1240,7 +1247,7 @@ async def alias_add(self, ctx, name: str.lower, *, value):
)

if embed is None:
embed = await self.make_alias(name, value, "Added")
embed = await self.make_alias(name, value, "Added", ctx)
return await ctx.send(embed=embed)

@alias.command(name="remove", aliases=["del", "delete"])
Expand Down Expand Up @@ -2150,6 +2157,14 @@ async def update(self, ctx, *, flag: str = ""):
)
await ctx.send(embed=embed)
else:
if self.bot.check_local_git() is False:
embed = discord.Embed(
title="Update Command Unavailable",
description="The bot cannot be updated due to not being installed via git."
"You need to manually update the bot according to your hosting method.",
color=discord.Color.red(),
)
return await ctx.send(embed=embed)
command = "git pull"
proc = await asyncio.create_subprocess_shell(
command,
Expand Down
9 changes: 9 additions & 0 deletions plugins/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
"icon_url": "https://i.imgur.com/qtE7AH8.png",
"thumbnail_url": "https://i.imgur.com/qtE7AH8.png"
},
"support-times": {
"repository": "martinbndr/kyb3r-modmail-plugins",
"branch": "master",
"description": "With this plugin you can set certain times when modmail should be enabled/disabled.",
"bot_version": "4.0.0",
"title": "Support-Times",
"icon_url": "https://raw.githubusercontent.com/martinbndr/kyb3r-modmail-plugins/master/support-times/logo.png",
"thumbnail_url": "https://raw.githubusercontent.com/martinbndr/kyb3r-modmail-plugins/master/support-times/logo.png"
},
"reminder": {
"repository": "martinbndr/kyb3r-modmail-plugins",
"branch": "master",
Expand Down