Skip to content

Commit a012278

Browse files
committed
Remove autoupdate system and update command
1 parent 782e620 commit a012278

File tree

5 files changed

+13
-263
lines changed

5 files changed

+13
-263
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ however, insignificant breaking changes do not guarantee a major version bump, s
3333
- Remove Discord.py dependency version check
3434
- Remove modmail telemetry
3535
- Remove lottie sticker support
36+
- Autoupdate system
37+
- Autoupdating was prone to serious issues and cannot be used within container images, the only supported distribution method of OpenModmail.
3638

3739
### Fixed
3840
- Persistent notes have been fixed after the previous discord.py update.

bot.py

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,130 +1592,6 @@ async def on_command_error(
15921592
else:
15931593
logger.error("Unexpected exception:", exc_info=exception)
15941594

1595-
@tasks.loop(hours=1)
1596-
async def autoupdate(self):
1597-
changelog = await Changelog.from_url(self)
1598-
latest = changelog.latest_version
1599-
1600-
if self.version < Version(latest.version):
1601-
error = None
1602-
data = {}
1603-
try:
1604-
# update fork if gh_token exists
1605-
data = await self.api.update_repository()
1606-
except InvalidConfigError:
1607-
pass
1608-
except ClientResponseError as exc:
1609-
error = exc
1610-
if self.hosting_method == HostingMethod.HEROKU:
1611-
if error is not None:
1612-
logger.error(f"Autoupdate failed! Status: {error.status}.")
1613-
logger.error(f"Error message: {error.message}")
1614-
self.autoupdate.cancel()
1615-
return
1616-
1617-
commit_data = data.get("data")
1618-
if not commit_data:
1619-
return
1620-
1621-
logger.info("Bot has been updated.")
1622-
1623-
if not self.config["update_notifications"]:
1624-
return
1625-
1626-
embed = discord.Embed(color=self.main_color)
1627-
message = commit_data["commit"]["message"]
1628-
html_url = commit_data["html_url"]
1629-
short_sha = commit_data["sha"][:6]
1630-
user = data["user"]
1631-
embed.add_field(
1632-
name="Merge Commit",
1633-
value=f"[`{short_sha}`]({html_url}) " f"{message} - {user['username']}",
1634-
)
1635-
embed.set_author(
1636-
name=user["username"] + " - Updating Bot",
1637-
icon_url=user["avatar_url"],
1638-
url=user["url"],
1639-
)
1640-
1641-
embed.set_footer(text=f"Updating Modmail v{self.version} -> v{latest.version}")
1642-
1643-
embed.description = latest.description
1644-
for name, value in latest.fields.items():
1645-
embed.add_field(name=name, value=value)
1646-
1647-
channel = self.update_channel
1648-
await channel.send(embed=embed)
1649-
else:
1650-
command = "git pull"
1651-
proc = await asyncio.create_subprocess_shell(
1652-
command,
1653-
stderr=PIPE,
1654-
stdout=PIPE,
1655-
)
1656-
err = await proc.stderr.read()
1657-
err = err.decode("utf-8").rstrip()
1658-
res = await proc.stdout.read()
1659-
res = res.decode("utf-8").rstrip()
1660-
1661-
if err and not res:
1662-
logger.warning(f"Autoupdate failed: {err}")
1663-
self.autoupdate.cancel()
1664-
return
1665-
1666-
elif res != "Already up to date.":
1667-
if os.getenv("PIPENV_ACTIVE"):
1668-
# Update pipenv if possible
1669-
await asyncio.create_subprocess_shell(
1670-
"pipenv sync",
1671-
stderr=PIPE,
1672-
stdout=PIPE,
1673-
)
1674-
message = ""
1675-
else:
1676-
message = "\n\nDo manually update dependencies if your bot has crashed."
1677-
1678-
logger.info("Bot has been updated.")
1679-
channel = self.update_channel
1680-
if self.hosting_method in (HostingMethod.PM2, HostingMethod.SYSTEMD):
1681-
embed = discord.Embed(title="Bot has been updated", color=self.main_color)
1682-
embed.set_footer(
1683-
text=f"Updating Modmail v{self.version} " f"-> v{latest.version} {message}"
1684-
)
1685-
if self.config["update_notifications"]:
1686-
await channel.send(embed=embed)
1687-
else:
1688-
embed = discord.Embed(
1689-
title="Bot has been updated and is logging out.",
1690-
description=f"If you do not have an auto-restart setup, please manually start the bot. {message}",
1691-
color=self.main_color,
1692-
)
1693-
embed.set_footer(text=f"Updating Modmail v{self.version} -> v{latest.version}")
1694-
if self.config["update_notifications"]:
1695-
await channel.send(embed=embed)
1696-
return await self.close()
1697-
1698-
@autoupdate.before_loop
1699-
async def before_autoupdate(self):
1700-
await self.wait_for_connected()
1701-
logger.debug("Starting autoupdate loop")
1702-
1703-
if self.config.get("disable_autoupdates"):
1704-
logger.warning("Autoupdates disabled.")
1705-
self.autoupdate.cancel()
1706-
return
1707-
1708-
if self.hosting_method == HostingMethod.DOCKER:
1709-
logger.warning("Autoupdates disabled as using Docker.")
1710-
self.autoupdate.cancel()
1711-
return
1712-
1713-
if not self.config.get("github_token") and self.hosting_method == HostingMethod.HEROKU:
1714-
logger.warning("GitHub access token not found.")
1715-
logger.warning("Autoupdates disabled.")
1716-
self.autoupdate.cancel()
1717-
return
1718-
17191595
def format_channel_name(self, author, exclude_channel=None, force_null=False):
17201596
"""Sanitises a username for use with text channel names
17211597

cogs/utility.py

Lines changed: 11 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414
from typing import Union
1515

1616
import discord
17+
from aiohttp import ClientResponseError
1718
from discord.enums import ActivityType, Status
1819
from discord.ext import commands, tasks
1920
from discord.ext.commands.view import StringView
20-
21-
from aiohttp import ClientResponseError
2221
from packaging.version import Version
2322

2423
from core import checks, migrations, utils
2524
from core.changelog import Changelog
2625
from core.models import HostingMethod, InvalidConfigError, PermissionLevel, UnseenFormatter, getLogger
2726
from core.paginator import EmbedPaginatorSession, MessagePaginatorSession
28-
from core.utils import trigger_typing, truncate, DummyParam
27+
from core.utils import DummyParam, trigger_typing, truncate
2928

3029
logger = getLogger(__name__)
3130

@@ -872,7 +871,7 @@ async def config_get(self, ctx, *, key: str.lower = None):
872871
embed.set_author(name="Current config(s):", icon_url=self.bot.user.display_avatar.url)
873872
config = self.bot.config.filter_default(self.bot.config)
874873

875-
field_count = 0;
874+
field_count = 0
876875
for name, value in config.items():
877876
if field_count >= 25:
878877
break
@@ -1939,141 +1938,24 @@ async def github(self, ctx):
19391938

19401939
@commands.command()
19411940
@checks.has_permissions(PermissionLevel.OWNER)
1942-
@checks.github_token_required(ignore_if_not_heroku=True)
19431941
@checks.updates_enabled()
19441942
@trigger_typing
1943+
@DeprecationWarning
19451944
async def update(self, ctx, *, flag: str = ""):
19461945
"""
1946+
REMOVED
19471947
Update Modmail.
19481948
To stay up-to-date with the latest commit from GitHub, specify "force" as the flag.
19491949
"""
19501950

1951-
if self.bot.hosting_method == HostingMethod.DOCKER:
1952-
await ctx.send(
1953-
embed=discord.Embed(
1954-
title="Error",
1955-
description="This command is not supported on Docker.",
1956-
color=self.bot.error_color,
1957-
)
1951+
await ctx.send(
1952+
embed=discord.Embed(
1953+
title="Error",
1954+
description="This command is not supported.",
1955+
color=self.bot.error_color,
19581956
)
1959-
return
1960-
1961-
changelog = await Changelog.from_url(self.bot)
1962-
latest = changelog.latest_version
1963-
1964-
desc = (
1965-
f"The latest version is [`{self.bot.version}`]"
1966-
"(https://github.com/raidensakura/modmail/blob/stable/bot.py#L1)"
19671957
)
1968-
1969-
if self.bot.version >= Version(latest.version) and flag.lower() != "force":
1970-
embed = discord.Embed(title="Already up to date", description=desc, color=self.bot.main_color)
1971-
1972-
data = await self.bot.api.get_user_info()
1973-
if data:
1974-
user = data["user"]
1975-
embed.set_author(name=user["username"], icon_url=user["avatar_url"], url=user["url"])
1976-
await ctx.send(embed=embed)
1977-
else:
1978-
error = None
1979-
data = {}
1980-
try:
1981-
# update fork if gh_token exists
1982-
data = await self.bot.api.update_repository()
1983-
except InvalidConfigError:
1984-
pass
1985-
except ClientResponseError as exc:
1986-
error = exc
1987-
1988-
if self.bot.hosting_method == HostingMethod.HEROKU:
1989-
if error is not None:
1990-
embed = discord.Embed(
1991-
title="Update failed",
1992-
description=f"Error status: {error.status}.\nError message: {error.message}",
1993-
color=self.bot.error_color,
1994-
)
1995-
return await ctx.send(embed=embed)
1996-
if not data:
1997-
# invalid gh_token
1998-
embed = discord.Embed(
1999-
title="Update failed",
2000-
description="Invalid Github token.",
2001-
color=self.bot.error_color,
2002-
)
2003-
return await ctx.send(embed=embed)
2004-
2005-
commit_data = data["data"]
2006-
user = data["user"]
2007-
if commit_data and commit_data.get("html_url"):
2008-
embed = discord.Embed(color=self.bot.main_color)
2009-
2010-
embed.set_footer(text=f"Updating Modmail v{self.bot.version} -> v{latest.version}")
2011-
2012-
embed.set_author(
2013-
name=user["username"] + " - Updating bot",
2014-
icon_url=user["avatar_url"],
2015-
url=user["url"],
2016-
)
2017-
2018-
embed.description = latest.description
2019-
for name, value in latest.fields.items():
2020-
embed.add_field(name=name, value=truncate(value, 200))
2021-
2022-
html_url = commit_data["html_url"]
2023-
short_sha = commit_data["sha"][:6]
2024-
embed.add_field(name="Merge Commit", value=f"[`{short_sha}`]({html_url})")
2025-
else:
2026-
embed = discord.Embed(
2027-
title="Already up to date",
2028-
description="No further updates required.",
2029-
color=self.bot.main_color,
2030-
)
2031-
embed.set_footer(text="Force update")
2032-
embed.set_author(name=user["username"], icon_url=user["avatar_url"], url=user["url"])
2033-
await ctx.send(embed=embed)
2034-
else:
2035-
command = "git pull"
2036-
proc = await asyncio.create_subprocess_shell(
2037-
command,
2038-
stderr=PIPE,
2039-
stdout=PIPE,
2040-
)
2041-
err = await proc.stderr.read()
2042-
err = err.decode("utf-8").rstrip()
2043-
res = await proc.stdout.read()
2044-
res = res.decode("utf-8").rstrip()
2045-
2046-
if err and not res:
2047-
embed = discord.Embed(title="Update failed", description=err, color=self.bot.error_color)
2048-
await ctx.send(embed=embed)
2049-
2050-
elif res != "Already up to date.":
2051-
logger.info("Bot has been updated.")
2052-
2053-
embed = discord.Embed(
2054-
title="Bot has been updated",
2055-
color=self.bot.main_color,
2056-
)
2057-
embed.set_footer(text=f"Updating Modmail v{self.bot.version} " f"-> v{latest.version}")
2058-
embed.description = latest.description
2059-
for name, value in latest.fields.items():
2060-
embed.add_field(name=name, value=truncate(value, 200))
2061-
2062-
if self.bot.hosting_method == HostingMethod.OTHER:
2063-
embed.description = (
2064-
"If you do not have an auto-restart setup, please manually start the bot.",
2065-
)
2066-
2067-
await ctx.send(embed=embed)
2068-
return await self.bot.close()
2069-
else:
2070-
embed = discord.Embed(
2071-
title="Already up to date",
2072-
description=desc,
2073-
color=self.bot.main_color,
2074-
)
2075-
embed.set_footer(text="Force update")
2076-
await ctx.send(embed=embed)
1958+
return
20771959

20781960
@commands.command(hidden=True, name="eval")
20791961
@checks.has_permissions(PermissionLevel.OWNER)

core/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ class ConfigManager:
173173
"enable_eval": True,
174174
# github access token for private repositories
175175
"github_token": None,
176-
"disable_autoupdates": False,
177176
"disable_updates": False,
178177
# Logging
179178
"log_level": "INFO",
@@ -213,7 +212,6 @@ class ConfigManager:
213212
"enable_plugins",
214213
"data_collection",
215214
"enable_eval",
216-
"disable_autoupdates",
217215
"disable_updates",
218216
"update_notifications",
219217
"thread_contact_silently",

core/config_help.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,14 +1169,6 @@
11691169
"This configuration can only be set through `.env` file or environment (config) variables."
11701170
]
11711171
},
1172-
"disable_autoupdates": {
1173-
"default": "No",
1174-
"description": "Controls if autoupdates should be disabled or not.",
1175-
"examples": [],
1176-
"notes": [
1177-
"This configuration can only be set through `.env` file or environment (config) variables."
1178-
]
1179-
},
11801172
"disable_updates": {
11811173
"default": "No",
11821174
"description": "Controls if the update command should be disabled or not.",

0 commit comments

Comments
 (0)