From 22bc5fe2404da4c721d7d48739fe5e2887ad70fd Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Wed, 5 Jun 2024 11:22:35 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AF=E3=83=B3=E3=82=BF=E3=82=A4=E3=83=A0?= =?UTF-8?q?=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89=E7=94=A8=E3=81=AB?= =?UTF-8?q?=E3=83=9E=E3=83=BC=E3=82=B8=E4=BA=88=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- temp/password.py | 16 ++++++++++++++++ temp/password.txt | 0 temp/powershell.py | 9 +++++++++ test.py => temp/test.py | 27 +++++++++++++++++---------- 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 temp/password.py create mode 100644 temp/password.txt create mode 100644 temp/powershell.py rename test.py => temp/test.py (61%) diff --git a/temp/password.py b/temp/password.py new file mode 100644 index 0000000..6d1c9d7 --- /dev/null +++ b/temp/password.py @@ -0,0 +1,16 @@ +import random +import string +# パスワードをファイルから読み込む + +with open('password.txt', 'r') as f: + secret = f.read() + +check=int(input("password :")) + +if check==int(secret): + print("ok") + secret=0 + with open('password.txt', 'w') as file: + file.write('') +else: + print("out") \ No newline at end of file diff --git a/temp/password.txt b/temp/password.txt new file mode 100644 index 0000000..e69de29 diff --git a/temp/powershell.py b/temp/powershell.py new file mode 100644 index 0000000..97f65f6 --- /dev/null +++ b/temp/powershell.py @@ -0,0 +1,9 @@ +import os + +# PowerShellコマンドを実行する関数 +def run_powershell_command(command): + # PowerShellコマンドを実行 + os.system(f"powershell -Command {command}") + +# 例としてGet-Dateコマンドを実行して現在の日時を取得 +run_powershell_command("Get-Date") diff --git a/test.py b/temp/test.py similarity index 61% rename from test.py rename to temp/test.py index 594a38d..03e0e7b 100644 --- a/test.py +++ b/temp/test.py @@ -1,11 +1,14 @@ -# インストールした discord.py を読み込む -import discord -import secrets -import string +import discord +import string +import random + +# Intentsの設定 +intents = discord.Intents.default() +intents.message_content = True # 接続に必要なオブジェクトを生成 -client = discord.Client() +client = discord.Client(intents=intents) # 起動時に動作する処理 @client.event @@ -20,14 +23,18 @@ async def on_message(message): if message.author.bot: return # 「/neko」と発言したら「にゃーん」が返る処理 - if message.content == '/neko': + if message.content == "/neko": await message.channel.send('にゃーん') if message.content == '/password': - await message.channel.send(get_random_password_string(4)) -def get_random_password_string(length): - pass_chars = string.ascii_letters + string.digits - password = ''.join(secrets.choice(pass_chars) for x in range(length)) + secret=password_generator_n(4) + await message.channel.send(str(secret)) + with open('password.txt', 'a') as file: + file.write(secret) + +def password_generator_n(length): + numbers = string.digits # (1) + password = ''.join(random.choice(numbers) for _ in range(length)) # (2) return password # Botの起動とDiscordサーバーへの接続