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サーバーへの接続