-
Notifications
You must be signed in to change notification settings - Fork 1
/
register_edit.py
138 lines (115 loc) · 4.02 KB
/
register_edit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import os
import json
import firebase_admin
from slack_bolt import App, Ack, Say, BoltContext, Respond
from slack_bolt.adapter.socket_mode import SocketModeHandler
from firebase_admin import firestore, credentials
from slack_sdk import WebClient
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
client = WebClient(token="YOUR_SLACK_API_TOKEN")
# 秘密鍵
cred = credentials.Certificate("JSON/serviceAccountKey.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
# グローバル変数の初期化
GLOBAL_DATE=0
GLOBAL_YEAR=0
GLOBAL_MONTH=0
GLOBAL_DAY=0
GLOBAL_HOUR=0
GLOBAL_MINUTE=0
USER_ID = 0
SECRET = 0
# jsonの読み込み
def send_message_from_json(json_file_path, channel_id):
with open(json_file_path, "r", encoding="UTF-8") as file:
json_data = json.load(file)
app.client.chat_postMessage(channel=channel_id, **json_data)
# ユーザーのヒミツをdatabaseに送信
def save_to_firestore(secret):
global USER_ID
doc_ref = db.collection('user').document(USER_ID)
doc_ref.set({
'private': secret
})
USER_ID=0
@app.message("登録")
def select_date(message):
global USER_ID
USER_ID = message['user']
send_message_from_json("JSON/check_register.json", USER_ID)
@app.action("yes_register")
def start_register(ack: Ack, body: dict, client: WebClient):
ack()
with open("JSON/register_date.json", "r", encoding="UTF-8") as file:
view= json.load(file)
client.views_open(trigger_id=body["trigger_id"], view=view)
@app.action("no_register")
def not_register(ack, say):
ack()
say("登録したいときは,もう一度「登録」と送ってください")
"""
@app.message("登録")
def abc(ack, body, say, client):
modal = "JSON/a.json"
response = client.views_open(
trigger_id=body["trigger_id"],
view=modal
)
# APIリクエストの結果を確認
if response["ok"]:
ack()
else:
say(f"モーダルの表示に失敗しました: {response['error']}")
"""
# 選択した日付の抽出
@app.action("select_date")
def handle_register_hour(ack, body, say):
global GLOBAL_DATE
GLOBAL_DATE = body["actions"][0]["selected_date"]
ack()
global GLOBAL_YEAR, GLOBAL_MONTH, GLOBAL_DAY
GLOBAL_YEAR, GLOBAL_MONTH, GLOBAL_DAY = GLOBAL_DATE.split("-")
# 選択した時間の抽出
@app.action("select_hour")
def handle_register_hour(ack, body, say):
global GLOBAL_HOUR
GLOBAL_HOUR = body["actions"][0]["selected_option"]["value"]
ack()
# 選択した分の抽出
@app.action("select_minute")
def handle_register_minute(ack, body):
global GLOBAL_MINUTE
GLOBAL_MINUTE = body["actions"][0]["selected_option"]["value"]
ack()
# 送信ボタンを押したときの処理
@app.view("register_date")
def handle_message_events(ack, say):
global USER_ID
ack()
message = f"あなたが登録したのは、{GLOBAL_YEAR}年{GLOBAL_MONTH}月{GLOBAL_DAY}日{GLOBAL_HOUR}時{GLOBAL_MINUTE}分です"
say(channel = USER_ID, text=message)
send_message_from_json("JSON/check_secret.json", USER_ID)
@app.action("yes_secret")
def start_secret(ack: Ack, body: dict, client: WebClient, say):
ack()
with open("JSON/register_secret.json", "r", encoding="UTF-8") as file:
view= json.load(file)
client.views_open(trigger_id=body["trigger_id"], view=view)
@app.action("input_secret")
def update(body):
global SECRET
#SECRET = body["view"]["state"]["values"]["OMd"]["input-action"]["value"]
# 秘密の保存(firebase)
@app.view("register_secret")
def save_secret(say, body, ack):
global SECRET
SECRET = body["view"]["state"]["values"][body["view"]["blocks"][0]["block_id"]]["input_secret"]["value"]
ack()
message = f"登録が完了しました!それでは、期日にお会いしましょう😎"
say(channel = USER_ID, text = message)
save_to_firestore(SECRET)
# ここからschedued/pyの内容
# アプリ起動
if __name__ == "__main__":
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()