41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import discord
|
|
from discord.ext import commands
|
|
from discord.ext.commands import has_permissions, Context
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
class Update(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
self.last_member = None
|
|
|
|
@commands.command()
|
|
@commands.is_owner()
|
|
async def update(self, context: Context, *args):
|
|
"""
|
|
Make pull from git repository and restart
|
|
|
|
"""
|
|
res = await self.bot.ch(server_id=context.guild.id)
|
|
channel = self.bot.get_channel(int(res))
|
|
await channel.send('restarting...')
|
|
try:
|
|
subprocess.run([],capture_output=True)
|
|
subprocess.run(["git", "pull", "origin", "main"],capture_output=True)
|
|
except:
|
|
await channel.send('restart fail')
|
|
return
|
|
|
|
python = sys.executable
|
|
os.execv(python, [python] + sys.argv)
|
|
await channel.send('restart successful')
|
|
|
|
@commands.Cog.listener()
|
|
async def on_ready(self):
|
|
print('Update cog has been loaded')
|
|
|
|
|
|
async def setup(bot):
|
|
await bot.add_cog(Update(bot))
|