17
17
18
18
import discord
19
19
import isodate
20
- from aiohttp import ClientSession
20
+ from aiohttp import ClientSession , ClientResponseError
21
21
from discord .ext import commands , tasks
22
22
from discord .ext .commands .view import StringView
23
23
from emoji import UNICODE_EMOJI
@@ -630,6 +630,8 @@ async def on_ready(self):
630
630
)
631
631
logger .warning ("If the external servers are valid, you may ignore this message." )
632
632
633
+ self .post_metadata .start ()
634
+ self .autoupdate .start ()
633
635
self ._started = True
634
636
635
637
async def convert_emoji (self , name : str ) -> str :
@@ -1581,6 +1583,7 @@ async def before_post_metadata(self):
1581
1583
await self .wait_for_connected ()
1582
1584
if not self .config .get ("data_collection" ) or not self .guild :
1583
1585
self .post_metadata .cancel ()
1586
+ return
1584
1587
1585
1588
logger .debug ("Starting metadata loop." )
1586
1589
logger .line ("debug" )
@@ -1591,44 +1594,50 @@ async def autoupdate(self):
1591
1594
latest = changelog .latest_version
1592
1595
1593
1596
if self .version < parse_version (latest .version ):
1594
- if self .hosting_method == HostingMethod .HEROKU :
1597
+ try :
1598
+ # update fork if gh_token exists
1595
1599
data = await self .api .update_repository ()
1600
+ except InvalidConfigError :
1601
+ data = {}
1602
+ except ClientResponseError as exc :
1603
+ logger .error (f"Autoupdate failed! Status { exc .status } ." )
1604
+ logger .error (f"Message: { exc .message } " )
1605
+ self .autoupdate .cancel ()
1606
+ return
1607
+ if self .hosting_method == HostingMethod .HEROKU :
1608
+ commit_data = data .get ("data" )
1609
+ if not commit_data :
1610
+ return
1596
1611
1597
- embed = discord .Embed (color = self .main_color )
1612
+ logger .info ("Bot has been updated." )
1613
+
1614
+ if not self .config ["update_notifications" ]:
1615
+ return
1598
1616
1599
- commit_data = data ["data" ]
1617
+ embed = discord .Embed (color = self .main_color )
1618
+ message = commit_data ["commit" ]["message" ]
1619
+ html_url = commit_data ["html_url" ]
1620
+ short_sha = commit_data ["sha" ][:6 ]
1600
1621
user = data ["user" ]
1622
+ embed .add_field (
1623
+ name = "Merge Commit" ,
1624
+ value = f"[`{ short_sha } `]({ html_url } ) " f"{ message } - { user ['username' ]} " ,
1625
+ )
1601
1626
embed .set_author (
1602
1627
name = user ["username" ] + " - Updating Bot" ,
1603
1628
icon_url = user ["avatar_url" ],
1604
1629
url = user ["url" ],
1605
1630
)
1606
1631
1607
- embed .set_footer (text = f"Updating Modmail v{ self .version } " f" -> v{ latest .version } " )
1632
+ embed .set_footer (text = f"Updating Modmail v{ self .version } -> v{ latest .version } " )
1608
1633
1609
1634
embed .description = latest .description
1610
1635
for name , value in latest .fields .items ():
1611
1636
embed .add_field (name = name , value = value )
1612
1637
1613
- if commit_data :
1614
- message = commit_data ["commit" ]["message" ]
1615
- html_url = commit_data ["html_url" ]
1616
- short_sha = commit_data ["sha" ][:6 ]
1617
- embed .add_field (
1618
- name = "Merge Commit" ,
1619
- value = f"[`{ short_sha } `]({ html_url } ) " f"{ message } - { user ['username' ]} " ,
1620
- )
1621
- logger .info ("Bot has been updated." )
1622
- channel = self .log_channel
1623
- if self .config ["update_notifications" ]:
1624
- await channel .send (embed = embed )
1638
+ channel = self .update_channel
1639
+ await channel .send (embed = embed )
1625
1640
else :
1626
- try :
1627
- # update fork if gh_token exists
1628
- await self .api .update_repository ()
1629
- except InvalidConfigError :
1630
- pass
1631
-
1632
1641
command = "git pull"
1633
1642
proc = await asyncio .create_subprocess_shell (
1634
1643
command ,
@@ -1642,7 +1651,7 @@ async def autoupdate(self):
1642
1651
1643
1652
if err and not res :
1644
1653
logger .warning (f"Autoupdate failed: { err } " )
1645
- self .autoupdate_loop .cancel ()
1654
+ self .autoupdate .cancel ()
1646
1655
return
1647
1656
1648
1657
elif res != "Already up to date." :
@@ -1659,7 +1668,7 @@ async def autoupdate(self):
1659
1668
description = "If you do not have an auto-restart setup, please manually start the bot." ,
1660
1669
color = self .main_color ,
1661
1670
)
1662
- embed .set_footer (text = f"Updating Modmail v{ self .version } " f" -> v{ latest .version } " )
1671
+ embed .set_footer (text = f"Updating Modmail v{ self .version } -> v{ latest .version } " )
1663
1672
if self .config ["update_notifications" ]:
1664
1673
await channel .send (embed = embed )
1665
1674
return await self .close ()
@@ -1671,16 +1680,16 @@ async def before_autoupdate(self):
1671
1680
1672
1681
if self .config .get ("disable_autoupdates" ):
1673
1682
logger .warning ("Autoupdates disabled." )
1674
- self .autoupdate_loop .cancel ()
1683
+ self .autoupdate .cancel ()
1675
1684
1676
1685
if self .hosting_method == HostingMethod .DOCKER :
1677
1686
logger .warning ("Autoupdates disabled as using Docker." )
1678
- self .autoupdate_loop .cancel ()
1687
+ self .autoupdate .cancel ()
1679
1688
1680
1689
if not self .config .get ("github_token" ) and self .hosting_method == HostingMethod .HEROKU :
1681
1690
logger .warning ("GitHub access token not found." )
1682
1691
logger .warning ("Autoupdates disabled." )
1683
- self .autoupdate_loop .cancel ()
1692
+ self .autoupdate .cancel ()
1684
1693
1685
1694
def format_channel_name (self , author , exclude_channel = None , force_null = False ):
1686
1695
"""Sanitises a username for use with text channel names
0 commit comments