@@ -49,6 +49,8 @@ async def on_ready():
49
49
print (f"{ bot .user } has connected to Discord!" )
50
50
logging .info ("Bot is ready and connected." )
51
51
await setup_bot ()
52
+ asyncio .create_task (wipe_logs_periodically ())
53
+ asyncio .create_task (check_for_updates_periodically ())
52
54
53
55
@bot .event
54
56
async def on_message (message ):
@@ -114,6 +116,35 @@ async def wipe_logs_periodically():
114
116
except Exception as e :
115
117
logging .error (f"Error wiping logs: { e } " )
116
118
119
+ async def check_for_updates_periodically ():
120
+ while True :
121
+ try :
122
+ await asyncio .sleep (900 )
123
+ update_proc = await asyncio .create_subprocess_exec (
124
+ "git" , "remote" , "update" ,
125
+ stdout = asyncio .subprocess .PIPE ,
126
+ stderr = asyncio .subprocess .PIPE ,
127
+ )
128
+ await update_proc .communicate ()
129
+ status_proc = await asyncio .create_subprocess_exec (
130
+ "git" , "status" , "-uno" ,
131
+ stdout = asyncio .subprocess .PIPE ,
132
+ stderr = asyncio .subprocess .PIPE ,
133
+ )
134
+ status_stdout , _ = await status_proc .communicate ()
135
+ if b"behind" in status_stdout :
136
+ logging .info ("Repository update detected; running update script." )
137
+ if os .name == "nt" :
138
+ result = os .system ("update.bat" )
139
+ else :
140
+ result = os .system ("bash update.sh" )
141
+ if result != 0 :
142
+ logging .error (f"Update script exited with code { result } " )
143
+ except asyncio .CancelledError :
144
+ break
145
+ except Exception as e :
146
+ logging .error (f"Error checking for updates: { e } " )
147
+
117
148
@bot .event
118
149
async def on_connect ():
119
150
await api_client .initialize ()
0 commit comments