|
14 | 14 | from typing import Union |
15 | 15 |
|
16 | 16 | import discord |
| 17 | +from aiohttp import ClientResponseError |
17 | 18 | from discord.enums import ActivityType, Status |
18 | 19 | from discord.ext import commands, tasks |
19 | 20 | from discord.ext.commands.view import StringView |
20 | | - |
21 | | -from aiohttp import ClientResponseError |
22 | 21 | from packaging.version import Version |
23 | 22 |
|
24 | 23 | from core import checks, migrations, utils |
25 | 24 | from core.changelog import Changelog |
26 | 25 | from core.models import HostingMethod, InvalidConfigError, PermissionLevel, UnseenFormatter, getLogger |
27 | 26 | from core.paginator import EmbedPaginatorSession, MessagePaginatorSession |
28 | | -from core.utils import trigger_typing, truncate, DummyParam |
| 27 | +from core.utils import DummyParam, trigger_typing, truncate |
29 | 28 |
|
30 | 29 | logger = getLogger(__name__) |
31 | 30 |
|
@@ -872,7 +871,7 @@ async def config_get(self, ctx, *, key: str.lower = None): |
872 | 871 | embed.set_author(name="Current config(s):", icon_url=self.bot.user.display_avatar.url) |
873 | 872 | config = self.bot.config.filter_default(self.bot.config) |
874 | 873 |
|
875 | | - field_count = 0; |
| 874 | + field_count = 0 |
876 | 875 | for name, value in config.items(): |
877 | 876 | if field_count >= 25: |
878 | 877 | break |
@@ -1939,141 +1938,24 @@ async def github(self, ctx): |
1939 | 1938 |
|
1940 | 1939 | @commands.command() |
1941 | 1940 | @checks.has_permissions(PermissionLevel.OWNER) |
1942 | | - @checks.github_token_required(ignore_if_not_heroku=True) |
1943 | 1941 | @checks.updates_enabled() |
1944 | 1942 | @trigger_typing |
| 1943 | + @DeprecationWarning |
1945 | 1944 | async def update(self, ctx, *, flag: str = ""): |
1946 | 1945 | """ |
| 1946 | + REMOVED |
1947 | 1947 | Update Modmail. |
1948 | 1948 | To stay up-to-date with the latest commit from GitHub, specify "force" as the flag. |
1949 | 1949 | """ |
1950 | 1950 |
|
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, |
1958 | 1956 | ) |
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)" |
1967 | 1957 | ) |
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 |
2077 | 1959 |
|
2078 | 1960 | @commands.command(hidden=True, name="eval") |
2079 | 1961 | @checks.has_permissions(PermissionLevel.OWNER) |
|
0 commit comments