Added Restart/Shutdown Commands
Added the restart and shutdown command to the bot's discord module.
This commit is contained in:
parent
9cbd57b4b2
commit
32b9a54a27
23
commands/implemented/command_restartBot_discord.py
Normal file
23
commands/implemented/command_restartBot_discord.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from commands.command_base import AbstractCommand
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import discord.message
|
||||||
|
|
||||||
|
import utilities_script as utilities
|
||||||
|
|
||||||
|
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||||
|
command = "//restart"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD)
|
||||||
|
|
||||||
|
async def do_command(self, bot, discord_message: discord.message):
|
||||||
|
|
||||||
|
if str(discord_message.author.top_role) == "Admin":
|
||||||
|
print("Admin Check")
|
||||||
|
#response = str("Bot restarting... on %s" % discord_message.guild.name)
|
||||||
|
response = str("Bot restarting...")
|
||||||
|
await bot.send_message(discord_message, response)
|
||||||
|
utilities.restart_self()
|
||||||
23
commands/implemented/command_shutdownBot_discord.py
Normal file
23
commands/implemented/command_shutdownBot_discord.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from abc import ABCMeta
|
||||||
|
|
||||||
|
from commands.command_base import AbstractCommand
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import discord.message
|
||||||
|
|
||||||
|
import utilities_script as utilities
|
||||||
|
|
||||||
|
class CommandTTS(AbstractCommand, metaclass=ABCMeta):
|
||||||
|
command = "//shutdown"
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD)
|
||||||
|
|
||||||
|
async def do_command(self, bot, discord_message: discord.message):
|
||||||
|
|
||||||
|
if str(discord_message.author.top_role) == "Admin":
|
||||||
|
print("Admin Check")
|
||||||
|
#response = str("Bot restarting... on %s" % discord_message.guild.name)
|
||||||
|
response = str("Bot shutting down...")
|
||||||
|
await bot.send_message(discord_message, response)
|
||||||
|
utilities.hard_shutdown()
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import utilities_script as utilities
|
||||||
|
|
||||||
from discord import message
|
from discord import message
|
||||||
from discord.client import Client
|
from discord.client import Client
|
||||||
@ -49,13 +50,15 @@ class Discord_Module(discord.Client):
|
|||||||
|
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
print("{" + message.guild.name + "}[ " + str(message.channel) + " ](" + message.author.display_name + ")> ")
|
print("{" + message.guild.name + "}[ " + str(message.channel) + " ](" + message.author.display_name + ")> ")
|
||||||
|
#print(message.author.mention)
|
||||||
print(message.content)
|
print(message.content)
|
||||||
#print(message.channel.id)
|
#print(message.channel.id)
|
||||||
#Message ID
|
#Message ID
|
||||||
#print(str(message.id))
|
#print(str(message.id))
|
||||||
#print(str(message.channel.id))
|
#print(str(message.channel.id))
|
||||||
if message.content == "//testing":
|
if message.content == "//test":
|
||||||
await message.channel.send('test response')
|
pass
|
||||||
|
#await message.channel.send('test response')
|
||||||
#test = self.get_channel(431129571308339210)
|
#test = self.get_channel(431129571308339210)
|
||||||
#await test.send("testerino")
|
#await test.send("testerino")
|
||||||
|
|
||||||
|
|||||||
@ -7,3 +7,4 @@ numpy
|
|||||||
gTTS
|
gTTS
|
||||||
playsound
|
playsound
|
||||||
discord.py
|
discord.py
|
||||||
|
psutil
|
||||||
@ -1,6 +1,7 @@
|
|||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import utilities_script as utilities
|
||||||
|
|
||||||
import twitch
|
import twitch
|
||||||
import twitch.chat
|
import twitch.chat
|
||||||
|
|||||||
@ -1,6 +1,38 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import psutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
clearScreen = lambda: os.system('cls' if os.name == 'nt' else 'clear')
|
clearScreen = lambda: os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
|
||||||
def get_args(text: str) -> list:
|
def get_args(text: str) -> list:
|
||||||
return text.split(" ")
|
return text.split(" ")
|
||||||
|
|
||||||
|
def hard_shutdown():
|
||||||
|
current_system_pid = os.getpid()
|
||||||
|
|
||||||
|
ThisSystem = psutil.Process(current_system_pid)
|
||||||
|
ThisSystem.terminate()
|
||||||
|
|
||||||
|
def restart_self():
|
||||||
|
|
||||||
|
#current_system_pid = os.getpid()
|
||||||
|
#os.startfile("python C:/praxis/main.py")
|
||||||
|
#subprocess.run("python C:/praxis/main.py")
|
||||||
|
#subprocess.call("python main.py", shell=True)
|
||||||
|
os.system('start cmd /k python main.py')
|
||||||
|
hard_shutdown()
|
||||||
|
#os.system('python twitch_script.py')
|
||||||
|
#os.system('python discord_script.py')
|
||||||
|
|
||||||
|
def restart_target():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def launch_target(inputScript: str):
|
||||||
|
cmd = "start cmd /k python " + inputScript
|
||||||
|
os.system(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
#pass
|
||||||
|
restart_self()
|
||||||
Loading…
Reference in New Issue
Block a user