ワンタイムパスワード用にマージ予定

This commit is contained in:
suti7yk5032 2024-06-05 11:22:35 +09:00
parent ace0af03d6
commit 22bc5fe240
4 changed files with 42 additions and 10 deletions

16
temp/password.py Normal file
View file

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

0
temp/password.txt Normal file
View file

9
temp/powershell.py Normal file
View file

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

View file

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