Added Restart/Shutdown Commands

Added the restart and shutdown command to the bot's discord module.
This commit is contained in:
Alex Orid 2020-12-08 06:06:58 -05:00
parent 9cbd57b4b2
commit 32b9a54a27
6 changed files with 88 additions and 5 deletions

View 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()

View 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()

View File

@ -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")

View File

@ -7,3 +7,4 @@ numpy
gTTS gTTS
playsound playsound
discord.py discord.py
psutil

View File

@ -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

View File

@ -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()