Created
January 17, 2021 11:39
-
-
Save yude/b3a9f2ba554ead6f0a20c694722c3201 to your computer and use it in GitHub Desktop.
Discord のテキストチャンネルから systemd をこねくり回す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.utils import get | |
import subprocess | |
import getpass | |
import tempfile | |
import os | |
client = discord.Client() | |
passwd = (getpass.getpass() + '\n').encode() | |
token = os.environ.get('DISCORD_TOKEN') | |
@client.event | |
async def on_ready(): | |
print("Discord へ接続しました。") | |
@client.event | |
async def on_message(message): | |
if message.author.bot: | |
return | |
if message.content == 'hcu start': | |
await message.channel.send('Minecraft サーバーを起動します...') | |
res = subprocess.run(['sudo', '-S', 'systemctl', 'start', 'minecraft_hcu'], input=passwd, check=True) | |
print(res) | |
if message.content == 'hcu stop': | |
await message.channel.send('Minecraft サーバーを停止します...') | |
res = subprocess.run(['sudo', '-S', 'systemctl', 'stop', 'minecraft_hcu'], input=passwd, check=True) | |
print(res) | |
client.run(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment