2024-06-04 09:36:29 +09:00
import json
import discord
2024-07-21 16:36:16 +09:00
from discord import Interaction , TextStyle , app_commands
from discord . ui import TextInput , View , Modal
2024-06-04 09:36:29 +09:00
import os
import psycopg2
2024-07-07 18:00:49 +09:00
from psycopg2 import sql
2024-06-05 18:37:50 +09:00
import hashlib
import string
import random
2024-07-21 16:36:16 +09:00
from datetime import datetime , timedelta
2024-07-08 11:23:19 +09:00
from openpyxl import Workbook
2024-07-21 16:36:16 +09:00
import threading
import time
2024-06-04 09:36:29 +09:00
2024-07-07 15:33:30 +09:00
class DL ( ) :
2024-07-07 13:49:53 +09:00
def __init__ ( self ) :
self . config_dir_path = " ./config/ "
2024-07-07 15:02:54 +09:00
self . export_dir_path = " ./export/ "
2024-07-07 13:49:53 +09:00
self . server_config_path = self . config_dir_path + " server.json "
2024-07-07 15:52:46 +09:00
try :
if not os . path . isdir ( self . config_dir_path ) :
print ( " config ディレクトリが見つかりません... 作成します。 " )
2024-07-07 15:24:55 +09:00
os . mkdir ( self . config_dir_path )
2024-07-07 15:02:54 +09:00
2024-07-07 15:52:46 +09:00
if not os . path . isfile ( self . server_config_path ) :
print ( " config ファイルが見つかりません... 作成します。 " )
self . server_config = {
" db " : {
" host " : " localhost " ,
" port " : " 5432 " ,
" db_name " : " dislocker " ,
" username " : " user " ,
" password " : " password "
} ,
" bot " : {
" token " : " TYPE HERE BOTS TOKEN KEY " ,
2024-07-26 13:23:21 +09:00
" activity " : {
" name " : " Dislocker " ,
" details " : " ロック中... " ,
" type " : " playing " ,
" state " : " ロック中... "
} ,
2024-07-07 17:24:33 +09:00
" log_channel_id " : " TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!) " ,
2024-07-20 23:08:27 +09:00
" config_channel_id " : " TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!) " ,
2024-08-15 22:41:38 +09:00
" config_public_channel_id " : " TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!) " ,
" monitor " : {
" search_frequency " : 1 ,
" allowable_time " : 180 ,
" fstop_time " : " 21:00:00 "
}
2024-07-07 15:52:46 +09:00
}
2024-07-07 13:49:53 +09:00
}
2024-08-15 22:46:55 +09:00
with open ( self . server_config_path , " w " , encoding = " utf-8 " ) as w :
json . dump ( self . server_config , w , indent = 4 , ensure_ascii = False )
2024-07-07 13:49:53 +09:00
2024-07-07 15:52:46 +09:00
elif os . path . isfile ( self . server_config_path ) :
2024-08-15 22:46:55 +09:00
with open ( self . server_config_path , " r " , encoding = " utf-8 " ) as r :
2024-07-07 15:52:46 +09:00
self . server_config = json . load ( r )
2024-07-07 16:04:46 +09:00
print ( " config ファイルを読み込みました。 " )
2024-07-07 17:24:33 +09:00
2024-07-07 15:52:46 +09:00
if not os . path . isdir ( self . export_dir_path ) :
print ( " export ディレクトリが見つかりません... 作成します。 " )
2024-07-07 15:24:55 +09:00
os . mkdir ( self . export_dir_path )
2024-07-07 17:34:51 +09:00
if type ( self . server_config [ " bot " ] [ " log_channel_id " ] ) is not int or type ( self . server_config [ " bot " ] [ " config_channel_id " ] ) is not int :
2024-07-07 17:24:33 +09:00
print ( " config ファイル内でチャンネルIDがint型で記述されていません。int型で記述して、起動してください。 " )
self . init_result = " not_int "
else :
self . db = psycopg2 . connect ( f " host= { self . server_config [ ' db ' ] [ ' host ' ] } dbname= { self . server_config [ ' db ' ] [ ' db_name ' ] } port= { self . server_config [ ' db ' ] [ ' port ' ] } user= { self . server_config [ ' db ' ] [ ' username ' ] } password= { self . server_config [ ' db ' ] [ ' password ' ] } " )
2024-07-20 20:11:11 +09:00
cursor = self . db . cursor ( )
2024-08-11 15:25:01 +09:00
self . pc_list = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
2024-08-22 23:58:31 +09:00
self . keyboard_list = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
self . mouse_list = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
2024-08-11 15:25:01 +09:00
2024-08-22 23:58:31 +09:00
cursor . execute ( " SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ' public ' AND table_name = ' club_member ' ) " )
2024-07-20 20:11:11 +09:00
find_club_member_table = cursor . fetchall ( )
print ( find_club_member_table )
if find_club_member_table [ 0 ] [ 0 ] == False :
2024-08-23 00:39:34 +09:00
cursor . execute ( " CREATE TABLE club_member (member_id SERIAL NOT NULL, name TEXT NOT NULL, discord_user_name TEXT NOT NULL, discord_user_id TEXT NOT NULL, PRIMARY KEY (member_id)) " )
2024-07-20 20:11:11 +09:00
self . db . commit ( )
2024-08-22 23:58:31 +09:00
cursor . execute ( " SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ' public ' AND table_name = ' pc_list ' ) " )
2024-07-20 20:11:11 +09:00
find_pc_list_table = cursor . fetchall ( )
print ( find_pc_list_table )
if find_pc_list_table [ 0 ] [ 0 ] == False :
2024-08-23 00:39:34 +09:00
cursor . execute ( " CREATE TABLE pc_list (pc_number INTEGER NOT NULL, using_member_id INTEGER, password_hash VARCHAR(32), PRIMARY KEY (pc_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id)) " )
2024-08-22 23:58:31 +09:00
for i in self . pc_list :
2024-07-21 16:36:16 +09:00
print ( i )
2024-08-22 23:58:31 +09:00
cursor . execute ( " INSERT INTO pc_list (pc_number) VALUES ( %s ) " , ( i , ) )
2024-07-21 16:36:16 +09:00
self . db . commit ( )
2024-07-20 20:11:11 +09:00
2024-08-22 23:58:31 +09:00
cursor . execute ( " SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ' public ' AND table_name = ' keyboard_list ' ) " )
find_keyboard_list_table = cursor . fetchall ( )
print ( find_keyboard_list_table )
if find_keyboard_list_table [ 0 ] [ 0 ] == False :
2024-08-23 00:39:34 +09:00
cursor . execute ( " CREATE TABLE keyboard_list (keyboard_number INTEGER NOT NULL, using_member_id INTEGER, PRIMARY KEY (keyboard_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id)) " )
2024-08-22 23:58:31 +09:00
for i in self . keyboard_list :
print ( i )
cursor . execute ( " INSERT INTO keyboard_list (keyboard_number) VALUES ( %s ) " , ( i , ) )
self . db . commit ( )
cursor . execute ( " SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ' public ' AND table_name = ' mouse_list ' ) " )
find_mouse_list_table = cursor . fetchall ( )
print ( find_mouse_list_table )
if find_mouse_list_table [ 0 ] [ 0 ] == False :
2024-08-23 00:39:34 +09:00
cursor . execute ( " CREATE TABLE mouse_list (mouse_number INTEGER NOT NULL, using_member_id INTEGER, PRIMARY KEY (mouse_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id)) " )
2024-08-22 23:58:31 +09:00
for i in self . mouse_list :
print ( i )
cursor . execute ( " INSERT INTO mouse_list (mouse_number) VALUES ( %s ) " , ( i , ) )
self . db . commit ( )
cursor . execute ( " SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = ' public ' AND table_name = ' pc_usage_history ' ) " )
2024-07-20 20:11:11 +09:00
find_pc_usage_history_table = cursor . fetchall ( )
print ( find_pc_usage_history_table )
if find_pc_usage_history_table [ 0 ] [ 0 ] == False :
2024-08-23 00:39:34 +09:00
cursor . execute ( " CREATE TABLE pc_usage_history (id SERIAL NOT NULL, member_id INTEGER NOT NULL, pc_number INTEGER NOT NULL, keyboard_number INTEGER, mouse_number INTEGER, start_use_time TIMESTAMP NOT NULL, end_use_time TIMESTAMP, use_detail TEXT, bot_about TEXT, PRIMARY KEY (id), FOREIGN KEY (member_id) REFERENCES club_member(member_id), FOREIGN KEY (pc_number) REFERENCES pc_list(pc_number), FOREIGN KEY (keyboard_number) REFERENCES keyboard_list(keyboard_number), FOREIGN KEY (mouse_number) REFERENCES mouse_list(mouse_number)) " )
2024-07-20 20:11:11 +09:00
self . db . commit ( )
cursor . close ( )
2024-07-07 17:24:33 +09:00
self . init_result = " ok "
2024-07-07 15:52:46 +09:00
2024-07-07 15:43:43 +09:00
except ( Exception ) as error :
2024-07-07 16:04:46 +09:00
print ( " 初回処理でエラーが発生しました。 \n エラー内容 \n " + str ( error ) )
self . init_result = " error "
2024-07-07 13:49:53 +09:00
2024-07-07 15:48:43 +09:00
finally :
2024-07-07 15:55:14 +09:00
pass
2024-07-07 15:24:55 +09:00
class Bot ( discord . Client ) :
2024-07-21 16:36:16 +09:00
2024-06-05 18:37:50 +09:00
def password_generate ( self , length ) :
numbers = string . digits # (1)
password = ' ' . join ( random . choice ( numbers ) for _ in range ( length ) ) # (2)
2024-06-09 18:39:42 +09:00
return password
2024-06-05 18:37:50 +09:00
def hash_genarate ( self , source ) :
hashed = hashlib . md5 ( source . encode ( ) )
return hashed . hexdigest ( )
2024-08-22 23:58:31 +09:00
def user_register_check ( self , * * kwargs ) :
try :
discord_user_id = str ( kwargs [ " discord_user_id " ] )
cursor = dislocker . db . cursor ( )
cursor . execute ( " SELECT * FROM club_member WHERE discord_user_id = %s " , ( discord_user_id , ) )
user_record = cursor . fetchall ( )
#ユーザーデータが見つかった場合(登録済みの場合)
if user_record :
member_id = user_record [ 0 ] [ 0 ]
name = user_record [ 0 ] [ 1 ]
discord_user_name = user_record [ 0 ] [ 2 ]
return { " result " : 0 , " about " : " exist " , " user_info " : { " member_id " : member_id , " name " : name , " discord_user_name " : discord_user_name } }
#ユーザーデータがなかったら(未登録の場合)
else :
return { " result " : 1 , " about " : " user_data_not_found " }
except Exception as error :
2024-08-23 00:17:51 +09:00
print ( " ユーザーの登録状態を調査中にエラーが発生しました。 \n エラー内容 " )
2024-08-22 23:58:31 +09:00
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
finally :
cursor . close ( )
def pc_used_check ( self , * * kwargs ) :
try :
if " pc_number " in kwargs :
pc_number = int ( kwargs [ " pc_number " ] )
else :
pc_number = None
if " discord_user_id " in kwargs :
discord_user_id = str ( kwargs [ " discord_user_id " ] )
else :
discord_user_id = None
2024-08-23 01:09:00 +09:00
if " member_id " in kwargs :
member_id = str ( kwargs [ " member_id " ] )
else :
member_id = None
2024-08-22 23:58:31 +09:00
cursor = dislocker . db . cursor ( )
2024-08-23 01:09:00 +09:00
if pc_number != None :
# pc番号を指定してpc_listから探す
2024-08-23 00:22:01 +09:00
cursor . execute ( " SELECT * FROM pc_list WHERE pc_number= %s " , ( pc_number , ) )
2024-08-22 23:58:31 +09:00
pc_list_record = cursor . fetchall ( )
if pc_list_record [ 0 ] [ 1 ] == None :
return { " result " : 0 , " about " : " vacent " }
else :
return { " result " : 1 , " about " : " used_by_other " }
2024-08-23 01:09:00 +09:00
elif discord_user_id != None :
2024-08-22 23:58:31 +09:00
#ユーザーIDを指定してPC使用履歴から探す
2024-08-23 01:09:00 +09:00
cursor . execute ( " SELECT * FROM club_member WHERE discord_user_id = %s " , ( discord_user_id , ) )
user_record = cursor . fetchall ( )
#ユーザーデータが見つかった場合(登録済みの場合)
if user_record :
member_id = user_record [ 0 ] [ 0 ]
cursor . execute ( " SELECT * FROM pc_usage_history WHERE member_id = %s ORDER BY id DESC LIMIT 1 " , ( member_id , ) )
pc_usage_history_record = cursor . fetchall ( )
if pc_usage_history_record :
print ( " used " )
if pc_usage_history_record [ 0 ] [ 5 ] == None :
return { " result " : 1 , " about " : " used_by_you " , " pc_usage_history " : { " pc_number " : str ( pc_usage_history_record [ 0 ] [ 2 ] ) , " keyboard_number " : str ( pc_usage_history_record [ 0 ] [ 3 ] ) , " mouse_number " : str ( pc_usage_history_record [ 0 ] [ 4 ] ) , " start_time " : str ( pc_usage_history_record [ 0 ] [ 5 ] ) , " use_detail " : str ( pc_usage_history_record [ 0 ] [ 7 ] ) } }
else :
return { " result " : 0 , " about " : " vacent " }
else :
return { " result " : 0 , " about " : " vacent " }
else :
return { " result " : 1 , " about " : " user_data_not_found " }
elif member_id != None :
cursor . execute ( " SELECT * FROM pc_usage_history WHERE member_id = %s ORDER BY id DESC LIMIT 1 " , ( member_id , ) )
2024-08-22 23:58:31 +09:00
pc_usage_history_record = cursor . fetchall ( )
if pc_usage_history_record :
print ( " used " )
if pc_usage_history_record [ 0 ] [ 5 ] == None :
return { " result " : 1 , " about " : " used_by_you " , " pc_usage_history " : { " pc_number " : str ( pc_usage_history_record [ 0 ] [ 2 ] ) , " keyboard_number " : str ( pc_usage_history_record [ 0 ] [ 3 ] ) , " mouse_number " : str ( pc_usage_history_record [ 0 ] [ 4 ] ) , " start_time " : str ( pc_usage_history_record [ 0 ] [ 5 ] ) , " use_detail " : str ( pc_usage_history_record [ 0 ] [ 7 ] ) } }
else :
return { " result " : 0 , " about " : " vacent " }
else :
return { " result " : 0 , " about " : " vacent " }
2024-08-23 01:09:00 +09:00
else :
return { " result " : 1 , " about " : " search_options_error " }
2024-08-22 23:58:31 +09:00
except Exception as error :
print ( " PCの使用状況を調査中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-08-22 23:58:31 +09:00
def keyboard_used_check ( self , * * kwargs ) :
try :
2024-08-23 01:15:21 +09:00
if kwargs [ " keyboard_number " ] == None :
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " }
else :
2024-08-23 01:15:21 +09:00
keyboard_number = int ( kwargs [ " keyboard_number " ] )
cursor = dislocker . db . cursor ( )
2024-08-22 23:58:31 +09:00
2024-08-23 01:15:21 +09:00
cursor . execute ( " SELECT * FROM keyboard_list WHERE keyboard_number= %s " , ( keyboard_number , ) )
keyboard_list_record = cursor . fetchall ( )
if keyboard_list_record [ 0 ] [ 1 ] == None :
return { " result " : 0 , " about " : " ok " }
else :
return { " result " : 1 , " about " : " keyboard_already_in_use_by_other " }
2024-08-22 23:58:31 +09:00
except Exception as error :
print ( " キーボードの使用状況を調査中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-08-22 23:58:31 +09:00
def mouse_used_check ( self , * * kwargs ) :
try :
2024-08-23 01:15:21 +09:00
if kwargs [ " mouse_number " ] == None :
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " }
else :
2024-08-23 01:15:21 +09:00
mouse_number = int ( kwargs [ " mouse_number " ] )
cursor = dislocker . db . cursor ( )
2024-08-22 23:58:31 +09:00
2024-08-23 01:15:21 +09:00
cursor . execute ( " SELECT * FROM mouse_list WHERE mouse_number= %s " , ( mouse_number , ) )
mouse_list_record = cursor . fetchall ( )
if mouse_list_record [ 0 ] [ 1 ] == None :
return { " result " : 0 , " about " : " ok " }
else :
return { " result " : 1 , " about " : " mouse_already_in_use_by_other " }
2024-08-22 23:58:31 +09:00
except Exception as error :
print ( " マウスの使用状況を調査中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-08-22 23:58:31 +09:00
2024-07-07 15:02:54 +09:00
def register ( self , * * kwargs ) :
2024-07-07 15:24:55 +09:00
try :
2024-08-23 01:30:58 +09:00
cursor = None
2024-07-20 20:11:11 +09:00
user_info = {
" id " : str ( kwargs [ " user_id " ] ) ,
" name " : str ( kwargs [ " name " ] ) ,
" display_name " : str ( kwargs [ " display_name " ] ) ,
" pc_number " : int ( kwargs [ " pc_number " ] ) ,
2024-08-22 23:58:31 +09:00
" keyboard_number " : None ,
" mouse_number " : None ,
2024-07-20 20:11:11 +09:00
" detail " : None
}
2024-07-07 15:24:55 +09:00
if " detail " in kwargs :
2024-07-20 20:11:11 +09:00
user_info [ " detail " ] = str ( kwargs [ " detail " ] )
2024-07-07 15:24:55 +09:00
else :
2024-07-20 20:11:11 +09:00
pass
2024-08-22 23:58:31 +09:00
if kwargs [ " keyboard_number " ] == " own " :
pass
2024-07-07 15:24:55 +09:00
else :
2024-08-22 23:58:31 +09:00
user_info [ " keyboard_number " ] = int ( kwargs [ " keyboard_number " ] )
if kwargs [ " mouse_number " ] == " own " :
pass
else :
user_info [ " mouse_number " ] = int ( kwargs [ " mouse_number " ] )
# ユーザー登録されているかの確認
user_register = self . user_register_check ( discord_user_id = user_info [ " id " ] )
if user_register [ " result " ] == 0 :
member_id = user_register [ " user_info " ] [ " member_id " ]
discord_user_name = user_register [ " user_info " ] [ " discord_user_name " ]
# ユーザーがPCを使っているか
2024-08-23 01:09:00 +09:00
pc_check_self = self . pc_used_check ( member_id = member_id )
2024-08-22 23:58:31 +09:00
if pc_check_self [ " result " ] == 0 :
# 他の人がそのPCを使っているか
pc_check = self . pc_used_check ( pc_number = user_info [ " pc_number " ] )
if pc_check [ " result " ] == 0 :
# キーボードは使われているか
keyboard_check = self . keyboard_used_check ( keyboard_number = user_info [ " keyboard_number " ] )
if keyboard_check [ " result " ] == 0 :
# マウスは使われているか
mouse_check = self . mouse_used_check ( mouse_number = user_info [ " mouse_number " ] )
if mouse_check [ " result " ] == 0 :
# パスワードとハッシュ作成
password = self . password_generate ( 4 )
password_hash = self . hash_genarate ( password )
# PC使用履歴のテーブルにレコードを挿入
2024-08-23 01:38:54 +09:00
print ( " ここ " )
2024-08-23 01:30:58 +09:00
cursor = dislocker . db . cursor ( )
2024-08-22 23:58:31 +09:00
cursor . execute ( " INSERT INTO pc_usage_history (member_id, pc_number, keyboard_number, mouse_number, start_use_time, use_detail) VALUES ( %s , %s , %s , %s , clock_timestamp(), %s ) " , ( member_id , user_info [ " pc_number " ] , user_info [ " keyboard_number " ] , user_info [ " mouse_number " ] , user_info [ " detail " ] ) )
# PCリストの該当のレコードを更新
cursor . execute ( " UPDATE pc_list SET using_member_id = %s , password_hash = %s WHERE pc_number = %s " , ( member_id , password_hash , user_info [ " pc_number " ] ) )
# キーボードリストの該当のレコードを自前(None)だったらスキップ、借りていたら更新
if user_info [ " keyboard_number " ] == None :
pass
else :
cursor . execute ( " UPDATE keyboard_list SET using_member_id = %s WHERE keyboard_number = %s " , ( member_id , user_info [ " keyboard_number " ] ) )
# マウスも同様に
if user_info [ " mouse_number " ] == None :
pass
else :
cursor . execute ( " UPDATE mouse_list SET using_member_id = %s WHERE mouse_number = %s " , ( member_id , user_info [ " mouse_number " ] ) )
2024-08-23 01:18:02 +09:00
dislocker . db . commit ( )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " , " output " : { " password " : str ( password ) , " name " : str ( discord_user_name ) } }
2024-07-07 15:24:55 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " mouse_already_in_use " }
2024-07-20 20:11:11 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " keyboard_already_in_use " }
2024-06-09 18:39:42 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " pc_already_in_use_by_other " }
else :
return { " result " : 1 , " about " : " pc_already_in_use_by_you " , " pc_usage_history " : { " pc_number " : pc_check_self [ " pc_usage_history " ] [ " pc_number " ] , " keyboard_number " : pc_check_self [ " pc_usage_history " ] [ " keyboard_number " ] , " mouse_number " : pc_check_self [ " pc_usage_history " ] [ " mouse_number " ] , " start_time " : pc_check_self [ " pc_usage_history " ] [ " start_time " ] } , " use_detail " : pc_check_self [ " pc_usage_history " ] [ " use_detail " ] }
else :
2024-08-23 00:58:38 +09:00
return { " result " : 1 , " about " : " user_data_not_found " }
2024-07-20 20:11:11 +09:00
except Exception as error :
print ( " 登録処理中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
2024-08-23 00:55:49 +09:00
return { " result " : 1 , " about " : " error " }
2024-07-07 15:24:55 +09:00
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-08-23 00:55:49 +09:00
2024-06-09 18:39:42 +09:00
2024-07-07 15:02:54 +09:00
def stop ( self , * * kwargs ) :
2024-07-07 15:24:55 +09:00
try :
discord_user_id = str ( kwargs [ " user_id " ] )
2024-08-11 15:25:01 +09:00
if " bot_about " in kwargs :
bot_about = kwargs [ " bot_about " ]
else :
bot_about = None
2024-07-07 15:24:55 +09:00
cursor = dislocker . db . cursor ( )
2024-08-22 23:58:31 +09:00
# ユーザーが登録してるかというよりはデータの取得のため
user_register = self . user_register_check ( discord_user_id = discord_user_id )
member_id = user_register [ " user_info " ] [ " member_id " ]
name = user_register [ " user_info " ] [ " name " ]
if user_register [ " result " ] == 0 :
cursor . execute ( " SELECT * FROM pc_usage_history WHERE member_id= %s ORDER BY id DESC LIMIT 1 " , ( member_id , ) )
2024-08-10 17:32:14 +09:00
pc_usage_history_record = cursor . fetchall ( )
2024-08-22 23:58:31 +09:00
2024-08-10 17:32:14 +09:00
if pc_usage_history_record :
2024-08-22 23:58:31 +09:00
usage_id = pc_usage_history_record [ 0 ] [ 0 ]
pc_number = pc_usage_history_record [ 0 ] [ 2 ]
keyboard_number = pc_usage_history_record [ 0 ] [ 3 ]
mouse_number = pc_usage_history_record [ 0 ] [ 4 ]
end_use_time = pc_usage_history_record [ 0 ] [ 6 ]
# 使用中のとき (使用停止時間がNoneのとき)
if end_use_time == None :
# 利用停止の理由の有無を判断
if bot_about == None :
cursor . execute ( " UPDATE pc_usage_history SET end_use_time = clock_timestamp() WHERE id = %s " , ( usage_id , ) )
2024-08-11 15:25:01 +09:00
else :
2024-08-22 23:58:31 +09:00
cursor . execute ( " UPDATE pc_usage_history SET end_use_time = clock_timestamp(), bot_about = %s WHERE id = %s " , ( bot_about , usage_id ) )
# pc_listの使用中ユーザーを消す
cursor . execute ( " UPDATE pc_list SET using_member_id = NULL, password_hash = NULL WHERE pc_number = %s " , ( pc_number , ) )
if keyboard_number == None :
pass
else :
# keyboard_listの使用中ユーザーを消す
cursor . execute ( " UPDATE keyboard_list SET using_member_id = NULL WHERE keyboard_number = %s " , ( keyboard_number , ) )
if mouse_number == None :
pass
else :
# mouse_listの使用中ユーザーを消す
cursor . execute ( " UPDATE mouse_list SET using_member_id = NULL WHERE keyboard_number = %s " , ( mouse_number , ) )
2024-08-10 17:32:14 +09:00
dislocker . db . commit ( )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " , " output_dict " : { " pc_number " : str ( pc_number ) , " name " : str ( name ) } }
else :
return { " result " : 1 , " about " : " unused " }
2024-07-07 15:24:55 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " unused " }
2024-08-10 17:32:14 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " user_data_not_found " }
except Exception as error :
print ( " 停止処理中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
2024-06-09 19:04:32 +09:00
2024-07-07 15:48:43 +09:00
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-06-09 18:39:42 +09:00
2024-07-07 15:02:54 +09:00
def user_register ( self , * * kwargs ) :
2024-07-07 15:24:55 +09:00
try :
discord_user_id = str ( kwargs [ " discord_user_id " ] )
discord_user_name = str ( kwargs [ " discord_user_name " ] )
name = str ( kwargs [ " name " ] )
cursor = dislocker . db . cursor ( )
2024-08-22 23:58:31 +09:00
cursor . execute ( " SELECT * FROM club_member WHERE discord_user_id = %s " , ( discord_user_id , ) )
2024-07-07 15:24:55 +09:00
user_record = cursor . fetchall ( )
if not user_record :
2024-08-22 23:58:31 +09:00
cursor . execute ( " INSERT INTO club_member (name, discord_user_name, discord_user_id) VALUES ( %s , %s , %s ) " , ( name , discord_user_name , discord_user_id ) )
2024-07-07 15:24:55 +09:00
dislocker . db . commit ( )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " }
2024-07-07 15:24:55 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " already_exists " }
2024-07-07 15:24:55 +09:00
2024-07-20 20:11:11 +09:00
except Exception as error :
print ( " ユーザー登録中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " error " }
2024-07-07 15:24:55 +09:00
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-08-22 23:58:31 +09:00
2024-06-09 19:56:59 +09:00
2024-07-07 17:48:54 +09:00
def format_datetime ( self , value ) :
if isinstance ( value , datetime ) :
return value . strftime ( ' % Y- % m- %d % H: % M: % S ' )
return value
2024-07-20 23:08:27 +09:00
def pc_register ( self , * * kwargs ) :
try :
pc_number = int ( kwargs [ " pc_number " ] )
cursor = dislocker . db . cursor ( )
cursor . execute ( " SELECT * FROM pc_list WHERE pc_number = %s " , ( pc_number , ) )
pc_list = cursor . fetchall ( )
if not pc_list :
cursor . execute ( " INSERT INTO pc_list (pc_number) VALUES ( %s ) " , ( pc_number , ) )
dislocker . db . commit ( )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " }
2024-07-20 23:08:27 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " already_exists " }
2024-07-20 23:08:27 +09:00
except Exception as error :
print ( " PCの登録中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " error " }
2024-07-20 23:08:27 +09:00
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-07-20 23:08:27 +09:00
2024-07-07 15:02:54 +09:00
def report_export ( self , * * kwargs ) :
try :
2024-07-07 18:00:49 +09:00
cursor = dislocker . db . cursor ( )
2024-07-07 18:07:53 +09:00
csv_file_path = dislocker . export_dir_path + " pc_usage_history.csv "
2024-07-07 17:48:54 +09:00
main_table = " pc_usage_history "
related_table = " club_member "
2024-07-08 11:23:19 +09:00
excel_file_path = dislocker . export_dir_path + " pc_usage_history.xlsx "
2024-07-07 18:00:49 +09:00
2024-07-07 15:02:54 +09:00
# メインテーブルの列情報を取得( user_idを除く)
2024-07-07 18:00:49 +09:00
cursor . execute ( sql . SQL ( " SELECT * FROM {} LIMIT 0 " ) . format ( sql . Identifier ( main_table ) ) )
2024-07-07 17:43:36 +09:00
main_columns = [ desc [ 0 ] for desc in cursor . description if desc [ 0 ] != ' member_id ' ]
2024-07-07 15:02:54 +09:00
# クエリを作成(列名を明確に指定)
2024-07-07 18:00:49 +09:00
query = sql . SQL ( """
2024-07-07 15:02:54 +09:00
SELECT { main_columns } , { related_table } . name
2024-07-07 18:15:15 +09:00
FROM { main_table }
LEFT JOIN { related_table } ON { main_table } . member_id = { related_table } . id
ORDER BY id
2024-07-07 15:02:54 +09:00
""" ).format(
2024-07-07 18:00:49 +09:00
main_columns = sql . SQL ( ' , ' ) . join ( [ sql . SQL ( " {} . {} " ) . format ( sql . Identifier ( main_table ) , sql . Identifier ( col ) ) for col in main_columns ] ) ,
main_table = sql . Identifier ( main_table ) ,
related_table = sql . Identifier ( related_table )
2024-07-07 15:02:54 +09:00
)
2024-07-07 16:35:57 +09:00
cursor . execute ( query )
2024-07-07 15:02:54 +09:00
# 列名を再構成( nameを2番目に配置)
column_names = [ main_columns [ 0 ] , ' name ' ] + main_columns [ 1 : ]
2024-07-07 16:35:57 +09:00
rows = cursor . fetchall ( )
2024-07-07 15:02:54 +09:00
2024-07-08 11:23:19 +09:00
# Excelワークブックを作成
wb = Workbook ( )
ws = wb . active
# 列名を書き込み
ws . append ( column_names )
# データを書き込み
for row in rows :
# nameを2番目に移動
formatted_row = [ self . format_datetime ( row [ 0 ] ) ] + [ row [ - 1 ] ] + [ self . format_datetime ( field ) if field is not None else ' ' for field in row [ 1 : - 1 ] ]
ws . append ( formatted_row )
# 列幅を自動調整
for col in ws . columns :
max_length = 0
column = col [ 0 ] . column_letter
for cell in col :
try :
if len ( str ( cell . value ) ) > max_length :
max_length = len ( str ( cell . value ) )
except :
pass
adjusted_width = ( max_length + 2 ) * 1.2
ws . column_dimensions [ column ] . width = adjusted_width
# Excelファイルを保存
wb . save ( excel_file_path )
print ( f " テーブル ' { main_table } ' の内容を ' { excel_file_path } ' に出力しました。 " )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " , " file_path " : excel_file_path }
except Exception as error :
print ( " 使用履歴のエクスポート中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
2024-07-08 11:30:20 +09:00
2024-07-07 15:02:54 +09:00
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-08-22 23:58:31 +09:00
2024-07-07 15:02:54 +09:00
2024-07-07 16:35:57 +09:00
def force_stop ( self , * * kwargs ) :
try :
pc_number = kwargs [ " pc_number " ]
2024-08-22 23:58:31 +09:00
cursor = dislocker . db . cursor ( )
2024-08-11 15:25:01 +09:00
if " bot_about " in kwargs :
bot_about = kwargs [ " bot_about " ]
cursor . execute ( " SELECT * FROM pc_list WHERE pc_number = %s " , ( pc_number , ) )
pc_list_record = cursor . fetchall ( )
2024-08-22 23:58:31 +09:00
pc_using_member_id = pc_list_record [ 0 ] [ 1 ]
pc_password_hash = pc_list_record [ 0 ] [ 2 ]
if pc_using_member_id == None :
return { " result " : 1 , " about " : " not_used " }
else :
cursor . execute ( " UPDATE pc_list SET using_member_id = NULL WHERE pc_number = %s " , ( pc_number , ) )
if pc_password_hash == None :
pass
else :
cursor . execute ( " UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s " , ( pc_number , ) )
cursor . execute ( " SELECT * FROM pc_usage_history WHERE member_id = %s AND pc_number = %s ORDER BY id DESC LIMIT 1 " , ( pc_using_member_id , pc_number ) )
2024-08-11 15:25:01 +09:00
pc_usage_history_record = cursor . fetchall ( )
2024-08-22 23:58:31 +09:00
pc_usage_history_record_id = pc_usage_history_record [ 0 ] [ 0 ]
2024-08-23 00:17:51 +09:00
keyboard_number = pc_usage_history_record [ 0 ] [ 3 ]
mouse_number = pc_usage_history_record [ 0 ] [ 4 ]
if keyboard_number == None :
pass
else :
# keyboard_listの使用中ユーザーを消す
cursor . execute ( " UPDATE keyboard_list SET using_member_id = NULL WHERE keyboard_number = %s " , ( keyboard_number , ) )
if mouse_number == None :
pass
else :
# mouse_listの使用中ユーザーを消す
cursor . execute ( " UPDATE mouse_list SET using_member_id = NULL WHERE keyboard_number = %s " , ( mouse_number , ) )
2024-08-22 23:58:31 +09:00
cursor . execute ( " UPDATE pc_usage_history SET end_use_time = clock_timestamp(), bot_about = %s WHERE id = %s " , ( bot_about , pc_usage_history_record_id ) )
2024-08-11 15:25:01 +09:00
dislocker . db . commit ( )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " about " : " ok " }
2024-07-07 16:35:57 +09:00
else :
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " bot_about_not_found " }
2024-08-11 15:25:01 +09:00
2024-08-22 23:58:31 +09:00
except Exception as error :
print ( " fstop中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
return { " result " : 1 , " about " : " error " }
2024-07-07 16:35:57 +09:00
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-07-21 16:36:16 +09:00
async def timeout_notify ( self , * * kwargs ) :
try :
pc_number = kwargs [ " pc_number " ]
discord_display_name = kwargs [ " discord_display_name " ]
await self . get_channel ( dislocker . server_config [ " bot " ] [ " log_channel_id " ] ) . send ( f ' :negative_squared_cross_mark: { discord_display_name } さんのPC { pc_number } の使用登録はタイムアウトにより解除されました。 ' )
2024-08-22 23:58:31 +09:00
return { " result " : 0 , " result " : " ok " }
2024-07-21 16:36:16 +09:00
except Exception as error :
print ( " 自動停止処理中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
2024-08-22 23:58:31 +09:00
return { " result " : 1 , " about " : " error " }
2024-07-21 16:36:16 +09:00
2024-07-07 16:35:57 +09:00
2024-06-04 22:53:31 +09:00
async def on_ready ( self ) :
2024-07-07 16:08:17 +09:00
print ( " DiscordのBotが起動しました。 " )
2024-07-26 13:29:09 +09:00
dislocker_activity = discord . Activity (
2024-07-26 13:23:21 +09:00
name = dislocker . server_config [ " bot " ] [ " activity " ] [ " name " ] ,
type = discord . ActivityType . competing ,
details = dislocker . server_config [ " bot " ] [ " activity " ] [ " details " ] ,
state = dislocker . server_config [ " bot " ] [ " activity " ] [ " state " ]
)
2024-07-26 13:29:09 +09:00
await bot . change_presence ( activity = dislocker_activity )
2024-06-04 09:36:29 +09:00
2024-07-21 16:36:16 +09:00
async def on_interaction ( self , interaction : discord . Interaction ) :
try :
if interaction . data [ " component_type " ] == 2 :
await self . on_button ( interaction )
except KeyError :
pass
2024-06-04 22:53:31 +09:00
async def on_message ( self , message ) :
if message . author . bot :
2024-06-09 18:49:46 +09:00
pass
2024-06-09 18:39:42 +09:00
2024-06-09 19:56:59 +09:00
elif isinstance ( message . channel , discord . DMChannel ) :
2024-08-22 23:58:31 +09:00
"""
2024-06-04 22:53:31 +09:00
msg_split = message . content . split ( )
2024-06-09 19:56:59 +09:00
if msg_split [ 0 ] == " /password " or msg_split [ 0 ] == " /start " :
2024-06-09 18:39:42 +09:00
#メッセージの要素が2つ以下の場合は拒否
2024-06-04 22:53:31 +09:00
if len ( msg_split ) < = 2 :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :warning: PC番号、もしくはデバイス番号が入力されていません。 " )
2024-06-09 19:04:32 +09:00
#メッセージの要素が3つ以上の場合
elif len ( msg_split ) > = 3 :
2024-06-09 18:39:42 +09:00
#番号が数字であることを確認
2024-06-04 22:53:31 +09:00
if msg_split [ 1 ] . isdigit ( ) and msg_split [ 2 ] . isdigit ( ) :
2024-06-09 18:39:42 +09:00
#PC番号が1以上10以下であることを確認
2024-06-04 22:53:31 +09:00
if int ( msg_split [ 1 ] ) < = 10 and int ( msg_split [ 1 ] ) > = 1 :
2024-06-09 19:04:32 +09:00
if len ( msg_split ) == 3 :
2024-07-20 20:11:11 +09:00
register = self . register ( user_id = message . author . id , name = message . author . name , display_name = message . author . display_name , pc_number = msg_split [ 1 ] , device_number = msg_split [ 2 ] )
2024-06-09 19:04:32 +09:00
elif len ( msg_split ) == 4 :
2024-07-20 20:11:11 +09:00
register = self . register ( user_id = message . author . id , name = message . author . name , display_name = message . author . display_name , pc_number = msg_split [ 1 ] , device_number = msg_split [ 2 ] , detail = msg_split [ 3 ] )
2024-06-09 19:04:32 +09:00
2024-06-09 18:39:42 +09:00
if register [ " result " ] == " ok " :
2024-06-09 19:04:32 +09:00
if len ( msg_split ) == 3 :
2024-07-20 23:18:36 +09:00
await message . channel . send ( f " :white_check_mark: 使用が開始されました。 \n >>> # パスワード | { register [ " password " ] } \n ## PC番号 | { msg_split [ 1 ] } \n ## デバイス番号 | { msg_split [ 2 ] } " )
2024-06-09 19:04:32 +09:00
elif len ( msg_split ) == 4 :
2024-07-20 23:18:36 +09:00
await message . channel . send ( f " :white_check_mark: 使用が開始されました。 \n >>> # パスワード | { register [ " password " ] } \n ## PC番号 | { msg_split [ 1 ] } \n ## デバイス番号 | { msg_split [ 2 ] } \n ## 使用目的 | { msg_split [ 3 ] } " )
2024-07-20 23:08:27 +09:00
await self . get_channel ( dislocker . server_config [ " bot " ] [ " log_channel_id " ] ) . send ( f ' :white_check_mark: { register [ " name " ] } さんがPC { msg_split [ 1 ] } の使用を開始しました。 ' )
2024-06-09 18:39:42 +09:00
elif register [ " result " ] == " user_data_not_found " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :dizzy_face: ユーザーとして登録されていないようです。 \n 最初にサーバーで登録を行ってください。 " )
2024-06-09 18:39:42 +09:00
elif register [ " result " ] == " pc_already_in_use_by_you " :
2024-07-20 23:18:36 +09:00
await message . channel . send ( f " # :exploding_head: あなたはPCをもう使用されているようです。 \n 使用状態を解除するには /stop で使用終了をお知らせください。 \n >>> # PC番号 | { register [ " pc_number " ] } \n # デバイス番号 | { register [ " device_number " ] } \n # 使用開始時刻 | { register [ " start_time " ] } \n # 使用目的 | { register [ " detail " ] } " )
2024-06-09 18:39:42 +09:00
elif register [ " result " ] == " pc_already_in_use_by_other " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( f " # :man_gesturing_no: そのPCは他のメンバーによって使用されています。 \n 別のPC番号を指定して、再度お試しください。 " )
2024-06-04 22:53:31 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :dizzy_face: 番号がおかしいようです。 " )
2024-06-04 22:53:31 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :dizzy_face: 指定された番号は不正です。 " )
2024-06-04 22:53:31 +09:00
elif msg_split [ 0 ] == " /stop " :
2024-06-09 18:39:42 +09:00
stop = self . stop ( user_id = message . author . id )
if stop [ " result " ] == " unused " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :shaking_face: 使用されていないようです... " )
2024-06-09 18:39:42 +09:00
elif stop [ " result " ] == " ok " :
2024-07-20 23:18:36 +09:00
await message . channel . send ( f " :white_check_mark: PC番号 { stop [ " pc_number " ] } の使用が終了されました。 " )
2024-07-20 23:08:27 +09:00
await self . get_channel ( dislocker . server_config [ " bot " ] [ " log_channel_id " ] ) . send ( f ' :negative_squared_cross_mark: { stop [ " name " ] } さんがPC { stop [ " pc_number " ] } の使用を終了しました。 ' )
2024-08-22 23:58:31 +09:00
"""
await message . channel . send ( " # :warning: DMでの応答は、現在無効化されています。 " )
2024-06-09 19:56:59 +09:00
2024-07-07 16:35:57 +09:00
elif message . channel . id == dislocker . server_config [ " bot " ] [ " config_channel_id " ] :
2024-06-09 19:56:59 +09:00
msg_split = message . content . split ( )
if msg_split [ 0 ] == " /register " :
2024-07-20 20:11:11 +09:00
print ( len ( msg_split ) )
if len ( msg_split ) == 1 :
register = self . user_register ( name = message . author . display_name , discord_user_name = message . author . name , discord_user_id = message . author . id )
print ( register )
2024-08-22 23:58:31 +09:00
if register [ " about " ] == " ok " :
2024-07-20 23:18:36 +09:00
await message . channel . send ( f " # :white_check_mark: ユーザー情報が登録されました。 \n >>> ユーザー名: { message . author . display_name } " )
2024-08-22 23:58:31 +09:00
elif register [ " about " ] == " already_exists " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :no_entry: 登録できませんでした。 \n もう登録されている可能性があります。 " )
2024-07-20 20:11:11 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :no_entry: 登録できませんでした。 \n 内部エラーが発生しています。 " )
2024-07-20 20:11:11 +09:00
elif len ( msg_split ) < = 3 :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :japanese_goblin: 入力内容に不備があります。 \n 名前、Discordのユーザー名、DiscordのユーザーIDのいずれかが入力されていません。 " )
2024-06-09 19:56:59 +09:00
elif len ( msg_split ) == 4 :
if msg_split [ 3 ] . isdigit ( ) :
register = self . user_register ( name = msg_split [ 1 ] , discord_user_name = msg_split [ 2 ] , discord_user_id = msg_split [ 3 ] )
2024-08-22 23:58:31 +09:00
if register [ " about " ] == " ok " :
2024-07-20 23:18:36 +09:00
await message . channel . send ( f " # :white_check_mark: 登録が完了しました。 \n >>> # 名前 | { msg_split [ 1 ] } \n # Discordのユーザー名 | { msg_split [ 2 ] } \n # DiscordのユーザーID | { msg_split [ 3 ] } " )
2024-08-22 23:58:31 +09:00
elif register [ " about " ] == " already_exists " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :skull_crossbones: 登録できませんでした。 \n そのDiscordアカウントはすでに登録されています。 " )
2024-06-09 19:56:59 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :skull_crossbones: 登録できませんでした。 \n DiscordのユーザーIDが不正です。 " )
2024-06-09 19:56:59 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :skull_crossbones: 登録できませんでした。 \n 内部エラーが発生しています。 " )
2024-06-09 19:56:59 +09:00
2024-07-07 15:02:54 +09:00
elif msg_split [ 0 ] == " /export " :
export = self . report_export ( )
2024-08-22 23:58:31 +09:00
if export [ " about " ] == " ok " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :page_facing_up: 使用履歴のレポートです。 " , file = discord . File ( export [ " file_path " ] ) )
2024-07-07 15:02:54 +09:00
pass
2024-08-22 23:58:31 +09:00
elif export [ " about " ] == " export_error " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :volcano: エクスポートに失敗しました。 " )
2024-07-07 15:02:54 +09:00
2024-07-07 16:35:57 +09:00
elif msg_split [ 0 ] == " /fstop " :
if len ( msg_split ) == 1 :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :warning: 登録を解除できませんでした。 \n 使用を停止したいPC番号を指定してください。 \n -# /fstop PC番号 " )
2024-07-07 16:35:57 +09:00
elif len ( msg_split ) == 2 :
2024-07-20 23:08:27 +09:00
if msg_split [ 1 ] . isdigit ( ) :
2024-08-11 15:25:01 +09:00
fstop = self . force_stop ( pc_number = msg_split [ 1 ] , bot_about = " 管理者による強制停止。 " )
2024-08-22 23:58:31 +09:00
if fstop [ " about " ] == " ok " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( f " # :white_check_mark: PC番号 { msg_split [ 1 ] } の使用登録を解除しました。 " )
2024-08-22 23:58:31 +09:00
elif fstop [ " about " ] == " not_used " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :exploding_head: 登録を解除できませんでした。 \n PCは使用されていないようです... " )
else :
await message . channel . send ( " # :x: 登録を解除できませんでした。 \n 内部エラーが発生しています。 " )
else :
await message . channel . send ( " # :warning: 登録を解除できませんでした。 \n PC番号を認識できません。 \n -# 半角数字で入力してください。 " )
else :
await message . channel . send ( " # warning: 登録を解除できませんでした。 \ 構文が間違っています。 \n -# /fstop PC番号 " )
elif msg_split [ 0 ] == " /pcregister " :
if len ( msg_split ) == 1 :
await message . channel . send ( " # :warning: PCを登録できませんでした。 \n 登録したいPC番号を指定してください。 \n -# 半角数字で入力してください。 " )
elif len ( msg_split ) == 2 :
if msg_split [ 1 ] . isdigit ( ) :
pc_register = self . pc_register ( pc_number = msg_split [ 1 ] )
2024-08-22 23:58:31 +09:00
if pc_register [ " about " ] == " ok " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( f " # :white_check_mark: PCを登録しました。 \n >>> # PC番号 | { msg_split [ 1 ] } " )
2024-08-22 23:58:31 +09:00
elif pc_register [ " about " ] == " already_exists " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( f " :x: PCを登録できませんでした。 \n その番号のPCは既に存在します。 " )
else :
await message . channel . send ( " # :x: PCを登録できませんでした。 \n 内部エラーが発生しています。 " )
else :
await message . channel . send ( " # :warning: PCを登録できませんでした。 \n PC番号を認識できません。 \n -# 半角数字で入力してください。 " )
else :
await message . channel . send ( " # :warning: PCを登録できませんでした。 \n 構文が間違っています。 \n -# /pcregister PC番号 " )
2024-08-22 23:58:31 +09:00
elif msg_split [ 0 ] == " /init " :
user_register_button_view = View ( timeout = None )
user_register_button = discord . ui . Button ( style = discord . ButtonStyle . green , label = " ユーザー登録 " , custom_id = " user_register " )
user_register_button_view . add_item ( user_register_button )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] ) . send ( f ' # :index_pointing_at_the_viewer: ユーザー登録はお済ですか? ' , view = user_register_button_view )
stop_button_view = View ( timeout = None )
stop_button = discord . ui . Button ( style = discord . ButtonStyle . danger , label = " PCの使用を停止 " , custom_id = " stop " )
stop_button_view . add_item ( stop_button )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] ) . send ( f ' # :index_pointing_at_the_viewer: 使用を停止しますか? ' , view = stop_button_view )
pc_button_view = View ( timeout = None )
for i in dislocker . pc_list :
pc_register_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = f " { str ( i ) } " , custom_id = f " pcregister_ { str ( i ) } " )
pc_button_view . add_item ( pc_register_button )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] ) . send ( f ' # :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください! ' , view = pc_button_view )
2024-07-21 16:36:16 +09:00
elif msg_split [ 0 ] == " /registerbutton " :
pc_button_view = View ( timeout = None )
2024-08-22 23:58:31 +09:00
for i in dislocker . pc_list :
pc_register_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = f " { str ( i ) } " , custom_id = f " pcregister_ { str ( i ) } " )
2024-07-21 16:36:16 +09:00
pc_button_view . add_item ( pc_register_button )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] ) . send ( f ' # :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください! ' , view = pc_button_view )
elif msg_split [ 0 ] == " /stopbutton " :
stop_button_view = View ( timeout = None )
stop_button = discord . ui . Button ( style = discord . ButtonStyle . danger , label = " PCの使用を停止 " , custom_id = " stop " )
stop_button_view . add_item ( stop_button )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] ) . send ( f ' # :index_pointing_at_the_viewer: 使用を停止しますか? ' , view = stop_button_view )
elif msg_split [ 0 ] == " /userbutton " :
user_register_button_view = View ( timeout = None )
user_register_button = discord . ui . Button ( style = discord . ButtonStyle . green , label = " ユーザー登録 " , custom_id = " user_register " )
user_register_button_view . add_item ( user_register_button )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] ) . send ( f ' # :index_pointing_at_the_viewer: ユーザー登録はお済ですか? ' , view = user_register_button_view )
2024-07-20 23:08:27 +09:00
elif message . channel . id == dislocker . server_config [ " bot " ] [ " config_public_channel_id " ] :
msg_split = message . content . split ( )
if msg_split [ 0 ] == " /register " :
print ( len ( msg_split ) )
if len ( msg_split ) == 1 :
register = self . user_register ( name = message . author . display_name , discord_user_name = message . author . name , discord_user_id = message . author . id )
print ( register )
2024-08-22 23:58:31 +09:00
if register [ " about " ] == " ok " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( f " # :white_check_mark: ユーザー情報が登録されました。 \n ユーザー名: { message . author . display_name } " )
2024-08-22 23:58:31 +09:00
elif register [ " about " ] == " already_exists " :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :skull_crossbones: 登録できませんでした。 \n そのDiscordアカウントはすでに登録されています。 " )
2024-07-07 16:35:57 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :skull_crossbones: 登録できませんでした。 \n 内部エラーが発生しています。 " )
2024-07-07 16:35:57 +09:00
else :
2024-07-20 23:08:27 +09:00
await message . channel . send ( " # :skull_crossbones: 登録できませんでした。 \n \n -# もしかして... \n -# 手動でメンバーを登録したいですか? \n -# もしそうなら、このチャンネルにはその権限がありません。 \n -# そのチャンネルに移動してから、もう一度試してみてください! " )
2024-07-07 16:35:57 +09:00
2024-07-21 16:36:16 +09:00
async def on_button ( self , interaction : Interaction ) :
custom_id = interaction . data [ " custom_id " ]
custom_id_split = custom_id . split ( " _ " )
print ( custom_id , custom_id_split [ 0 ] )
if custom_id_split [ 0 ] == " pcregister " :
2024-08-22 23:58:31 +09:00
keyboard_register_view = View ( timeout = 15 )
2024-07-21 16:36:16 +09:00
pc_number = custom_id_split [ 1 ]
print ( custom_id_split )
2024-08-22 23:58:31 +09:00
for i in dislocker . keyboard_list :
keyboard_register_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = f " { str ( i ) } " , custom_id = f " keyboardregister_ { str ( pc_number ) } _ { str ( i ) } " )
keyboard_register_view . add_item ( keyboard_register_button )
keyboard_not_register_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = " キーボードは自前 " , custom_id = f " keyboardregister_ { str ( pc_number ) } _own " )
keyboard_register_view . add_item ( keyboard_not_register_button )
2024-07-21 16:36:16 +09:00
2024-08-22 23:58:31 +09:00
await interaction . response . send_message ( f " # :keyboard: キーボードのデバイス番号を選んでください! \n >>> # PC番号 | { str ( pc_number ) } " , view = keyboard_register_view , ephemeral = True )
2024-07-21 16:36:16 +09:00
2024-08-22 23:58:31 +09:00
elif custom_id_split [ 0 ] == " keyboardregister " :
mouse_register_view = View ( timeout = 15 )
2024-07-21 16:36:16 +09:00
pc_number = custom_id_split [ 1 ]
2024-08-22 23:58:31 +09:00
keyboard_number = custom_id_split [ 2 ]
if keyboard_number == " own " :
keyboard_number_show = " 自前 "
else :
keyboard_number_show = keyboard_number
print ( custom_id_split )
for i in dislocker . mouse_list :
mouse_register_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = f " { str ( i ) } " , custom_id = f " mouseregister_ { str ( pc_number ) } _ { str ( keyboard_number ) } _ { str ( i ) } " )
mouse_register_view . add_item ( mouse_register_button )
mouse_not_register_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = " マウスは自前 " , custom_id = f " mouseregister_ { str ( pc_number ) } _ { str ( keyboard_number ) } _own " )
mouse_register_view . add_item ( mouse_not_register_button )
2024-08-23 00:44:57 +09:00
await interaction . response . send_message ( f " # :mouse_three_button: マウスのデバイス番号を選んでください! \n >>> # PC番号 | { str ( pc_number ) } \n # キーボード番号 | { str ( keyboard_number_show ) } " , view = mouse_register_view , ephemeral = True )
2024-08-22 23:58:31 +09:00
elif custom_id_split [ 0 ] == " mouseregister " :
pc_number = custom_id_split [ 1 ]
keyboard_number = custom_id_split [ 2 ]
if keyboard_number == " own " :
keyboard_number_show = " 自前 "
else :
keyboard_number_show = keyboard_number
mouse_number = custom_id_split [ 3 ]
if mouse_number == " own " :
mouse_number_show = " 自前 "
else :
mouse_number_show = mouse_number
2024-07-21 16:36:16 +09:00
reason_register_view = View ( timeout = 15 )
2024-08-22 23:58:31 +09:00
reason_button = discord . ui . Button ( style = discord . ButtonStyle . primary , label = " 使用目的を入力する " , custom_id = f " reasonregister_ { str ( pc_number ) } _ { str ( keyboard_number ) } _ { str ( mouse_number ) } " )
2024-07-21 16:36:16 +09:00
reason_register_view . add_item ( reason_button )
2024-08-22 23:58:31 +09:00
await interaction . response . send_message ( f " # :regional_indicator_q: 使用目的を書いてください! \n >>> # PC番号 | { str ( pc_number ) } \n # キーボード番号 | { str ( keyboard_number_show ) } \n # マウス番号 | { str ( mouse_number_show ) } " , view = reason_register_view , ephemeral = True )
2024-07-21 16:36:16 +09:00
elif custom_id_split [ 0 ] == " reasonregister " :
pc_number = custom_id_split [ 1 ]
2024-08-23 00:53:03 +09:00
keyboard_number = custom_id_split [ 2 ]
mouse_number = custom_id_split [ 3 ]
reason_input_form = Reason ( title = " Dislocker | 登録 " , pc_number = str ( pc_number ) , keyboard_number = str ( keyboard_number ) , mouse_number = str ( mouse_number ) )
2024-07-21 16:36:16 +09:00
await interaction . response . send_modal ( reason_input_form )
elif custom_id_split [ 0 ] == " stop " :
print ( " STOP running " )
pc_stop = self . stop ( user_id = interaction . user . id )
print ( pc_stop )
stop_view = View ( timeout = 15 )
2024-08-22 23:58:31 +09:00
if pc_stop [ " about " ] == " unused " :
2024-07-21 16:36:16 +09:00
await interaction . response . send_message ( " # :shaking_face: 使用されていないようです... " , ephemeral = True )
2024-08-22 23:58:31 +09:00
elif pc_stop [ " about " ] == " user_data_not_found " :
2024-08-10 17:32:14 +09:00
await interaction . response . send_message ( " # :dizzy_face: ユーザーとして登録されていないようです。 \n 最初にサーバーで登録を行ってください。 " , ephemeral = True )
2024-08-22 23:58:31 +09:00
elif pc_stop [ " about " ] == " ok " :
await interaction . response . send_message ( f " :white_check_mark: PC番号 { pc_stop [ " output_dict " ] [ " pc_number " ] } の使用が終了されました。 " , ephemeral = True )
await self . get_channel ( dislocker . server_config [ " bot " ] [ " log_channel_id " ] ) . send ( f ' :negative_squared_cross_mark: { pc_stop [ " output_dict " ] [ " name " ] } さんがPC { pc_stop [ " output_dict " ] [ " pc_number " ] } の使用を終了しました。 ' )
2024-07-21 16:36:16 +09:00
else :
await interaction . response . send_message ( " # :skull_crossbones: 停止できませんでした。 \n 内部エラーが発生しています。 " , ephemeral = True )
elif custom_id_split [ 0 ] == " user " and custom_id_split [ 1 ] == " register " :
print ( " User Register RUnning " )
user_register = self . user_register ( name = interaction . user . display_name , discord_user_name = interaction . user . name , discord_user_id = interaction . user . id )
2024-08-22 23:58:31 +09:00
if user_register [ " about " ] == " ok " :
2024-07-21 16:36:16 +09:00
await interaction . response . send_message ( f " # :white_check_mark: ユーザー情報が登録されました。 \n >>> ユーザー名: { interaction . user . display_name } " , ephemeral = True )
2024-08-22 23:58:31 +09:00
elif user_register [ " about " ] == " already_exists " :
2024-07-21 16:36:16 +09:00
await interaction . response . send_message ( " # :no_entry: 登録できませんでした。 \n もう登録されている可能性があります。 " , ephemeral = True )
else :
await interaction . response . send_message ( " # :no_entry: 登録できませんでした。 \n 内部エラーが発生しています。 " , ephemeral = True )
class Monitor ( ) :
2024-08-10 17:32:14 +09:00
def __init__ ( self , * * kwargs ) - > None :
2024-08-15 22:41:38 +09:00
self . search_frequency = kwargs [ " search_frequency " ]
2024-07-21 16:36:16 +09:00
self . allowable_time = kwargs [ " allowable_time " ]
2024-08-15 22:41:38 +09:00
self . fstop_time = kwargs [ " fstop_time " ]
2024-08-10 18:10:35 +09:00
self . init_wait_time = 10
2024-08-10 17:32:14 +09:00
def start ( self , * * kwargs ) :
2024-08-15 22:41:38 +09:00
search_thread = threading . Thread ( target = self . search )
search_thread . start ( )
2024-08-10 17:32:14 +09:00
2024-07-21 16:36:16 +09:00
def search ( self ) :
try :
2024-08-10 18:10:35 +09:00
time . sleep ( self . init_wait_time )
2024-07-21 16:36:16 +09:00
while True :
cursor = dislocker . db . cursor ( )
cursor . execute ( " SELECT * FROM pc_list WHERE password_hash IS NOT NULL " )
pc_list = cursor . fetchall ( )
2024-08-11 15:25:01 +09:00
current_datetime = datetime . now ( )
2024-08-15 22:41:38 +09:00
fstop_time = self . fstop_time
2024-08-11 15:25:01 +09:00
if current_datetime . time ( ) . strftime ( " % H: % M: % S " ) == fstop_time :
for i in dislocker . pc_list :
stop = bot . force_stop ( pc_number = i , bot_about = " 使用停止忘れによるBotによる強制停止。 " )
result = { " result " : " FSTOP " }
else :
if pc_list :
if len ( pc_list ) == 1 :
user_id = pc_list [ 0 ] [ 1 ]
2024-07-21 16:36:16 +09:00
cursor . execute ( " SELECT * FROM pc_usage_history WHERE member_id= %s AND end_use_time IS NULL ORDER BY id DESC LIMIT 1 " , ( user_id , ) )
pc_usage = cursor . fetchall ( )
print ( pc_usage )
start_time = pc_usage [ 0 ] [ 4 ]
print ( start_time )
print ( type ( start_time ) )
2024-08-11 15:25:01 +09:00
time_difference = current_datetime - start_time
print ( current_datetime , start_time )
2024-07-25 23:44:47 +09:00
print ( time_difference . seconds , timedelta ( seconds = self . allowable_time ) . seconds )
if time_difference . seconds > = timedelta ( seconds = self . allowable_time ) . seconds :
2024-07-21 16:36:16 +09:00
cursor . execute ( " SELECT * FROM club_member WHERE id = %s " , ( user_id , ) )
user_info = cursor . fetchall ( )
2024-08-11 15:25:01 +09:00
stop = bot . stop ( user_id = user_info [ 0 ] [ 3 ] , bot_about = " パスワードのタイムアウトでBotによる強制停止。 " )
2024-07-21 16:36:16 +09:00
2024-08-11 15:25:01 +09:00
bot . timeout_notify ( pc_number = pc_list [ 0 ] [ 0 ] , discord_display_name = user_info [ 0 ] [ 1 ] )
2024-08-16 13:23:12 +09:00
result = { " result " : " STOP " , " details " : str ( pc_usage ) }
2024-07-25 23:44:47 +09:00
else :
2024-08-16 13:23:12 +09:00
result = { " result " : " BUT SAFE " , " details " : str ( pc_usage ) }
2024-07-21 16:36:16 +09:00
2024-08-11 15:25:01 +09:00
elif len ( pc_list ) > = 2 :
for i in pc_list :
print ( i )
user_id = i [ 1 ]
cursor . execute ( " SELECT * FROM pc_usage_history WHERE member_id= %s AND end_use_time IS NULL ORDER BY id DESC LIMIT 1 " , ( user_id , ) )
pc_usage = cursor . fetchall ( )
print ( pc_usage )
start_time = pc_usage [ 0 ] [ 4 ]
print ( start_time )
print ( type ( start_time ) )
time_difference = current_datetime - start_time
print ( time_difference . seconds , timedelta ( seconds = self . allowable_time ) . seconds )
if time_difference . seconds > = timedelta ( seconds = self . allowable_time ) . seconds :
cursor . execute ( " SELECT * FROM club_member WHERE id = %s " , ( user_id , ) )
user_info = cursor . fetchall ( )
stop = bot . stop ( user_id = user_info [ 0 ] [ 3 ] , bot_about = " タイムアウトでBotによる強制停止。 " )
bot . timeout_notify ( pc_number = i [ 0 ] , discord_display_name = user_info [ 0 ] [ 1 ] )
2024-08-16 13:23:12 +09:00
result = { " result " : " STOP " , " details " : str ( pc_usage ) }
2024-08-11 15:25:01 +09:00
else :
2024-08-16 13:23:12 +09:00
result = { " result " : " BUT SAFE " , " details " : str ( pc_usage ) }
2024-08-11 15:25:01 +09:00
else :
result = { " result " : " NONE " }
2024-07-21 16:36:16 +09:00
else :
result = { " result " : " NONE " }
2024-08-16 13:15:10 +09:00
if result [ " result " ] == " NONE " :
pass
else :
print ( current_datetime )
print ( result [ " result " ] )
2024-08-15 22:41:38 +09:00
time . sleep ( self . search_frequency )
2024-07-21 16:36:16 +09:00
2024-08-10 17:32:14 +09:00
2024-07-21 16:36:16 +09:00
except Exception as error :
print ( " 自動停止処理中にエラーが発生しました。 \n エラー内容 " )
print ( str ( error . __class__ . __name__ ) )
print ( str ( error . args ) )
print ( str ( error ) )
result = { " result " : " error " }
dislocker . db . rollback ( )
finally :
2024-08-23 01:30:58 +09:00
if cursor :
cursor . close ( )
2024-07-21 16:36:16 +09:00
print ( result [ " result " ] )
return result
class Reason ( Modal ) :
2024-08-23 00:53:03 +09:00
def __init__ ( self , title : str , pc_number : str , keyboard_number : str , mouse_number : str , timeout = 15 ) - > None :
2024-07-21 16:36:16 +09:00
super ( ) . __init__ ( title = title , timeout = timeout )
2024-08-23 00:53:03 +09:00
print ( pc_number , keyboard_number , mouse_number )
self . reason_input_form = TextInput ( label = " 使用目的を入力してください " , style = TextStyle . short , custom_id = f " register_ { pc_number } _ { keyboard_number } _ { mouse_number } " )
2024-07-21 16:36:16 +09:00
self . add_item ( self . reason_input_form )
async def on_submit ( self , interaction : Interaction ) - > None :
custom_id = interaction . data [ " components " ] [ 0 ] [ " components " ] [ 0 ] [ " custom_id " ]
print ( custom_id )
custom_id_split = custom_id . split ( " _ " )
pc_number = custom_id_split [ 1 ]
2024-08-22 23:58:31 +09:00
keyboard_number = custom_id_split [ 2 ]
if keyboard_number == " own " :
keyboard_number_show = " 自前 "
else :
keyboard_number_show = keyboard_number
mouse_number = custom_id_split [ 3 ]
if mouse_number == " own " :
mouse_number_show = " 自前 "
else :
mouse_number_show = mouse_number
register = bot . register ( user_id = interaction . user . id , name = interaction . user . name , display_name = interaction . user . display_name , pc_number = pc_number , keyboard_number = keyboard_number , mouse_number = mouse_number , detail = self . reason_input_form . value )
print ( register )
if register [ " about " ] == " ok " :
await interaction . response . send_message ( f " :white_check_mark: 使用が開始されました。 \n >>> # パスワード | { register [ " password " ] } \n ## PC番号 | { pc_number } \n ## キーボード番号 | { keyboard_number_show } \n ## マウス番号 | { mouse_number_show } \n ## 使用目的 | { self . reason_input_form . value } " , ephemeral = True )
await bot . get_channel ( dislocker . server_config [ " bot " ] [ " log_channel_id " ] ) . send ( f ' :white_check_mark: { register [ " name " ] } さんがPC { pc_number } の使用を開始しました。 \n >>> ## キーボード番号 | { keyboard_number_show } \n ## マウス番号 | { mouse_number_show } \n ## 使用目的 | { self . reason_input_form . value } ' )
elif register [ " about " ] == " pc_already_in_use_by_you " :
pc_usage_history = register [ " pc_usage_history " ]
await interaction . response . send_message ( f " # :exploding_head: あなたはPCをもう使用されているようです。 \n 使用状態を解除するには 終了ボタン で使用終了をお知らせください。 \n >>> # PC番号 | { pc_usage_history [ " pc_number " ] } \n # キーボード番号 | { pc_usage_history [ " keyboard_number " ] } \n # マウス番号 | { pc_usage_history [ " mouse_number " ] } \n # 使用開始時刻 | { pc_usage_history [ " start_time " ] } \n # 使用目的 | { pc_usage_history [ " use_detail " ] } " , ephemeral = True )
elif register [ " about " ] == " pc_already_in_use_by_other " :
2024-07-21 16:36:16 +09:00
await interaction . response . send_message ( f " # :man_gesturing_no: そのPCは他のメンバーによって使用されています。 \n 別のPC番号を指定して、再度お試しください。 " , ephemeral = True )
2024-08-22 23:58:31 +09:00
elif register [ " about " ] == " keyboard_already_in_use " :
await interaction . response . send_message ( f " # :man_gesturing_no: そのキーボードは他のメンバーによって使用されています。 \n 別のキーボードのデバイス番号を指定して、再度お試しください。 " , ephemeral = True )
elif register [ " about " ] == " mouse_already_in_use " :
await interaction . response . send_message ( f " # :man_gesturing_no: そのマウスは他のメンバーによって使用されています。 \n 別のマウスのデバイス番号を指定して、再度お試しください。 " , ephemeral = True )
elif register [ " about " ] == " user_data_not_found " :
2024-07-21 16:36:16 +09:00
await interaction . response . send_message ( " # :dizzy_face: ユーザーとして登録されていないようです。 \n 最初にサーバーで登録を行ってください。 " , ephemeral = True )
else :
await interaction . response . send_message ( " # :skull_crossbones: 登録できませんでした。 \n 内部エラーが発生しています。 " , ephemeral = True )
2024-07-07 16:35:57 +09:00
2024-07-07 15:33:30 +09:00
dislocker = DL ( )
2024-07-07 16:04:46 +09:00
if dislocker . init_result == " ok " :
2024-07-20 20:11:11 +09:00
print ( " Botを起動します... " )
2024-07-07 15:43:43 +09:00
intents = discord . Intents . default ( )
intents . message_content = True
bot = Bot ( intents = intents )
2024-08-15 22:41:38 +09:00
monitor = Monitor ( search_frequency = dislocker . server_config [ " bot " ] [ " monitor " ] [ " search_frequency " ] , allowable_time = dislocker . server_config [ " bot " ] [ " monitor " ] [ " allowable_time " ] , fstop_time = dislocker . server_config [ " bot " ] [ " monitor " ] [ " fstop_time " ] )
2024-08-10 17:32:14 +09:00
monitor . start ( )
2024-07-07 15:43:43 +09:00
bot . run ( dislocker . server_config [ ' bot ' ] [ ' token ' ] )
2024-07-07 17:10:05 +09:00
else :
pass