-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
279 lines (213 loc) · 8.88 KB
/
main.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
"""
Author: PenutChen
"""
import asyncio
import datetime as dt
import hashlib
import random
import discord
from discord import Interaction, InteractionMessage
from discord.commands import Option
from discord.commands.context import ApplicationContext
from loguru import logger
from fries import FriesBot, exchange_name, get_token, set_logger
bot = FriesBot()
# Commands
@bot.slash_command(name="薯條喵喵喵", description="喵喵喵!")
async def help(ctx: ApplicationContext):
await ctx.respond(bot.resp("help"))
@bot.slash_command(name="薯條哈囉", description="跟本喵打招呼")
async def hello(ctx: ApplicationContext):
await ctx.respond(bot.resp("hello", ctx.author.mention))
@bot.slash_command(name="薯條灑花", description="灑花!")
async def sprinkle(
ctx: ApplicationContext,
n: Option(int, "想灑花的次數", name="次數", required=False, default=1),
):
n = 1 if n < 1 else n
n = 5 if n > 5 else n
msg = ["灑花 (\\* ̄▽ ̄)/‧☆\\*\"\\`'\\*-.,_,.-\\*'\\`\"\\*-.,_☆"] * n
msg = "\n".join(msg)
await ctx.respond(msg)
@bot.slash_command(name="薯條斗內", description="來個贊助本喵罐罐的連結")
async def donate(ctx: ApplicationContext):
msgs = ["贊助我的奴僕一杯咖啡吧 ヽ(=^・ω・^=)丿", "贊助我一個貓罐頭吧 ฅ(≚ᄌ≚)"]
url = "https://p.ecpay.com.tw/DEA19"
await ctx.respond(f"{random.choice(msgs)}\n{url}")
@bot.slash_command(name="薯條粉絲", description="秀出本喵的粉絲團")
async def fanpage(ctx: ApplicationContext):
await ctx.respond(
"薯條的臉書粉絲團\n"
"<https://www.facebook.com/FattyCatFries/>\n\n"
"薯條的 Instagram\n"
"<https://www.instagram.com/fatty_fries_cat/>"
)
# Fries Commands
@bot.slash_command(name="薯條時間", description="顯示 GMT+8 時間")
async def time(ctx: ApplicationContext):
ts = dt.datetime.utcnow() + dt.timedelta(hours=8)
ts = ts.strftime("%H:%M:%S")
await ctx.respond(f"喵喵喵,現在時間 {ts} (GMT+8)")
@bot.slash_command(name="召喚薯條", description="獲得本喵的美照一張")
async def summon(
ctx: ApplicationContext,
n: Option(int, "美照的數量", name="數量", required=False, default=1),
):
n = int(n)
n = 1 if n < 1 else n
send = ctx.respond
mention = ctx.author.mention
if n > 1:
if ctx.guild is not None:
await ctx.respond(f"{mention} 召喚超過一張會改成私訊給你喔!")
send = ctx.author.send
async def _send():
for pic in bot.get_pictures(n):
await send(pic)
if n > 10:
n = 10
await send(f"{mention} 不可以一次召喚太多啊啊啊會壞掉啊啊啊啊啊")
else:
await send(f"{mention} 熱騰騰的薯條來囉~")
await _send()
@bot.slash_command(name="薯條維基", description="搜尋中文維基頁面")
async def wiki(
ctx: ApplicationContext,
query: Option(str, "想要搜尋的頁面名稱", name="搜尋目標", required=True),
):
msgs = bot.get_wiki(query)
for msg in msgs:
await ctx.respond(msg)
# TRPG Commands
@bot.slash_command(name="薯條擲骰子", description="讓本喵來幫你擲個骰子")
async def dice(
ctx: ApplicationContext,
dice: Option(str, "骰子的格式,決定骰子的面數與個數", name="格式", required=True),
name: Option(str, "任務名稱", name="任務", required=False),
):
msg = f"{ctx.author.mention} {bot.roll_dice(dice, name)}"
await ctx.respond(msg)
@bot.slash_command(name="薯條算術", description="讓本喵來幫你做個簡單運算")
async def calc(
ctx: ApplicationContext,
pattern: Option(str, "想要讓本喵幫你計算的數學式", name="算式", required=True),
):
msg = bot.do_calc(pattern)
await ctx.respond(msg)
# Fortune Commands
@bot.slash_command(name="薯條水晶球", description="讓本喵幫你看看薯條水晶球")
async def crystal_ball(
ctx: ApplicationContext,
wish: Option(str, "你的願望是什麼?讓本喵幫你看看吧!", name="願望", required=False, default=""),
):
wish = exchange_name(wish)
sent = f"{ctx.author.mention} 讓本喵來幫你看看{wish}"
msg = await ctx.respond(sent)
await asyncio.sleep(1)
sent = f"{sent}\n喵喵喵,召喚水晶球 :crystal_ball:!"
await msg.edit_original_response(content=sent)
await asyncio.sleep(1)
sent = f"{sent}\n本喵從水晶球裡看到了,"
await msg.edit_original_response(content=sent)
await asyncio.sleep(1)
sent = f"{sent}是「:{bot.get_crystal()}:」!"
await msg.edit_original_response(content=sent)
@bot.slash_command(name="薯條抽籤", description="讓本喵來幫你抽根簡單的籤")
async def draw(
ctx: ApplicationContext,
wish: Option(str, "你想要占卜的目標是什麼?", name="目標", required=False),
):
draw_name = ["大吉", "吉", "小吉", "小兇", "兇", "大凶"]
if not wish:
r = random.choice(draw_name)
await ctx.respond(f"{ctx.author.mention} 抽到了「{r}」!")
else:
ts = dt.datetime.now().strftime("%Y%m%d")
ss = f"{wish}{ctx.author.id}{ts}"
m = hashlib.sha384(ss.encode()).hexdigest()
r = sum([ord(ch) for ch in m]) % len(draw_name)
r = draw_name[r]
await ctx.respond(f"{ctx.author.mention} 的「{wish}」抽到了「{r}」!")
@bot.slash_command(name="薯條籤筒", description="讓本喵來幫你抽根淺草籤")
async def fortune(
ctx: ApplicationContext,
_: Option(str, "來個淺草籤幫你的未來祈願吧~", name="祈願", required=False),
):
msg = bot.resp("fortune", ctx.author.mention, bot.get_fortune())
await ctx.respond(msg)
@bot.slash_command(name="薯條甲子籤", description="讓本喵幫你抽一張六十甲子籤")
async def sixty_jiazi(
ctx: ApplicationContext,
_: Option(str, "人定勝天,路是自己走出來的", name="命運", required=False),
):
await ctx.respond(bot.get_sixty_jiazi())
@bot.slash_command(name="薯條塔羅", description="讓本喵來幫你抽張塔羅牌")
async def tarot(
ctx: ApplicationContext,
n: Option(int, "想要抽的塔羅牌數量", name="牌數", required=False, default=1),
wish: Option(str, "讓本喵為你的夢想抽張塔羅牌吧!", name="夢想", required=False),
):
send = ctx.respond
mention = ctx.author.mention
if n > 1:
if ctx.guild is not None:
await ctx.respond(f"{mention} 抽超過一張塔羅牌會改成私訊給你喔!")
send = ctx.author.send
if wish is not None:
wish = exchange_name(wish)
msg = f"{mention} 讓本喵來占卜看看 {wish} (≧◡≦)"
else:
msg = f"{mention} 讓本喵來幫你抽個 (≧◡≦)"
await send(msg)
for msg, path in bot.get_tarots(n):
await send(msg, file=discord.File(path))
if random.randint(0, 10) == 1:
await send("喜歡薯條塔羅嗎?歡迎體驗新的指令「`/超級薯條塔羅`」! ")
@bot.slash_command(name="薯條解牌", description="查詢特定塔羅牌")
async def tarot_query(
ctx: ApplicationContext,
query: Option(str, "想要解牌的塔羅牌名稱", name="牌名", required=True),
):
msg, path = bot.query_card(query)
if path:
await ctx.respond(msg, file=discord.File(path))
else:
await ctx.respond(msg)
@bot.slash_command(name="超級薯條塔羅", description="讓本喵來幫你抽張塔羅牌並附上貓能智慧的解牌釋疑")
async def super_tarot(
ctx: ApplicationContext,
problem: Option(str, "不管有任何疑惑都讓本喵來為你釋疑吧!", name="疑惑", required=True),
):
wish = exchange_name(problem)
mention = ctx.author.mention
wish_msg = f"{mention} 讓本喵來占卜看看「{wish}」 (≧◡≦)"
prompt, card_name, img_path = bot.get_gpt_tarots(problem)
resp_msg = ""
head_msg = f"{wish_msg}\n本喵幫你抽到的塔羅牌為:{card_name}\n\n"
wait_msg = "(等待薯條貓神解牌中 ...)"
msg: Interaction = await ctx.respond(
head_msg + wait_msg,
file=discord.File(img_path),
)
final_msg = None
with ctx.typing():
try:
# Iteration of Each Response
for resp_msg in bot.get_gpt_response(prompt):
resp_msg = head_msg + resp_msg
await msg.edit_original_response(content=resp_msg)
final_msg = resp_msg
except Exception as e:
print(f"Error: {e}")
final_msg = f"{head_msg}{resp_msg} ... 發生錯誤,請稍後嘗試"
await msg.edit_original_response(content=final_msg)
logger.info(f"Problem: {problem}")
logger.info(f"Response: {final_msg}")
msg: InteractionMessage = await msg.original_response()
try:
await msg.add_reaction("😘")
except:
pass
if __name__ == "__main__":
set_logger()
bot.run(get_token())