-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
520 lines (412 loc) · 13.9 KB
/
Copy pathmain.py
File metadata and controls
520 lines (412 loc) · 13.9 KB
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
import modules.funcs
import bot_commands
import discord
import discord.app_commands
from discord import Interaction
from discord.ext import commands
import asyncio
import datetime
import openai
import os
import random
import re
##########################################################################
#### !!!Tokens!!!
##########################################################################
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
OPENAI_APIKEY = os.getenv("OPENAI_APIKEY")
COMMAND_PREFIX = "&"
intents = discord.Intents.all()
intents.message_content = True
bot = commands.Bot(command_prefix=COMMAND_PREFIX, intents=intents, case_insensitive=True)
tree = bot.tree
openai.api_key = OPENAI_APIKEY
##########################################################################
#### Bot Event
##########################################################################
async def change_presence():
games = [
"Adobe After Effects 2023",
"Adobe Photoshop 2023",
"Adobe Premire Pro 2023",
"Adobe Illustrator 2023",
"AviUtl",
"Blender",
"CakeWalk",
"CLIP STUDIO PAINT PRO",
"Cookie Clicker",
"Cooking Simulator",
"Crab Game",
"FallGuys",
"LDPlayer",
"Maxon Cinema 4D",
"Minecraft",
"NoxPlayer",
"REAPER",
"Splatoon 3",
"Terraria",
"Unrailed!",
"VocalShifter",
"超将棋"
]
status = [
discord.Status.online,
discord.Status.idle,
discord.Status.dnd
]
await bot.change_presence(
activity=discord.Game(random.choice(games)),
status=random.choice(status)
)
# 20分後に再度ステータス等を変更
await asyncio.sleep(1200)
await change_presence()
#起動時に動作する処理
@bot.event
async def on_ready():
now_string = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print_string = f"< [ {now_string} ] Successfully logged in. >"
print("=" * (60 + len(print_string)))
print("-" * 30 + print_string + "-" * 30)
print("=" * (60 + len(print_string)))
await tree.sync()
await change_presence()
#メッセージ受信時に動作する処理
@bot.event
async def on_message(message):
await bot.process_commands(message)
# 言葉狩り機能
await modules.funcs.kotobagari_proc(message)
# ChatGPT
if bot.user.mentioned_in(message) or message.channel.type == discord.ChannelType.private:
if message.author.bot or message.content[0] == COMMAND_PREFIX:
return
await modules.funcs.process_chat(message)
##########################################################################
#### Tree Command
##########################################################################
# BPM
@tree.command(name="bpm")
async def command_tree_bpm(itrc:Interaction):
"""
音声のBPM値を算出します。
(調べたい音声の近くに)/bpm
"""
await bot_commands.bpm(itrc, None)
# 画像に各種エフェクトをかける
@tree.command(name="effect")
async def command_tree_effect(itrc:Interaction, prompt:str=""):
"""
画像にエフェクトを適用します。
(適用したい画像の近くに)/effect [モード] [モードごとの引数] ...
"""
await bot_commands.effect(itrc, None, prompt=prompt)
# カニ
@tree.command(name="kani")
async def command_tree_kani(itrc:Interaction, kani_text:str="カニ"):
"""
見て見てフラッシュさん カニファル子だよ~
/kani ['カニ'にあたる部分の文字列]
"""
await bot_commands.kani(itrc, None, kani_text=kani_text)
# カニ(画像)
@tree.command(name="kani_img")
async def command_tree_kani_img(itrc, kani_text:str="カニ"):
"""
見て見てフラッシュさん カニファル子だよ~の画像版
/kani_img ['カニ'にあたる部分の文字列]
"""
await bot_commands.kani_img(itrc, None, kani_text=kani_text)
# 言葉狩り機能のオンオフ
@tree.command(name="kotobagari")
async def command_tree_kotobagari(itrc:Interaction, mode:bool):
"""
送信されたチャンネルの言葉狩り機能のオン/オフを変更します。
"""
await bot_commands.kotobagari(itrc, None, mode=mode)
# クワガタ
@tree.command(name="kuwagata")
async def command_tree_kuwagata(itrc:Interaction, kuwagata_text:str="クワガタ"):
"""
フラッシュさん見て見て クワガタ~
/kuwagata ['クワガタ'にあたる部分の文字列]
"""
await bot_commands.kuwagata(itrc, None, kuwagata_text=kuwagata_text)
# クワガタ(画像)
@tree.command(name="kuwagata_img")
async def command_tree_kuwagata_img(itrc, kuwagata_text:str="クワガタ"):
"""
フラッシュさん見て見て クワガタ~の画像版
/kuwagata_img ['クワガタ'にあたる部分の文字列]
"""
await bot_commands.kuwagata_img(itrc, None, kuwagata_text=kuwagata_text)
# おくり
@tree.command(name="okuri")
async def command_tree_okuri(itrc:Interaction, seiyoku:str="性欲", aru:str="ある", no:str="の"):
"""
おくりさんどれだけ性欲あるの
/okuri ['性欲'にあたる部分の文字列] ['ある'にあたる部分の文字列] ['の'にあたる部分の文字列]
"""
await bot_commands.okuri(
itrc,
None,
seiyoku=seiyoku,
aru=aru,
no=no
)
# Ping
@tree.command(name="ping")
async def command_tree_ping(itrc:Interaction):
"""
Ping値を取得します。
"""
await bot_commands.ping(itrc, None, bot)
# raika
@tree.command(name="raika")
async def command_tree_raika(itrc:Interaction, n: int=1):
"""
raikaさんのおもしろツイートガチャ
/raika [実行したい回数]
"""
await bot_commands.raika(itrc, None, n=n)
# 背景を透過
@tree.command(name="removebg")
async def command_tree_removebg(itrc:Interaction, use_removebgapi:bool=False):
"""
画像の背景を透過します。
(透過したい画像の近くに)/removebg [透過方法(オプション)]
・透過方法:use_removebgapiをTrueにするとremovebg APIを使って透過します。
removebg APIの使用制限に達した場合はrembgが使用されます。
"""
await bot_commands.removebg(itrc, None, use_removebgapi=use_removebgapi)
# 任意のメッセージを送信
@tree.command(name="send")
async def command_tree_send(itrc:Interaction, content:str, channel_id:str=None):
"""
任意のメッセージを送信します。
&send [メッセージ] [チャンネルID]
"""
await bot_commands.send(itrc, None, bot, content, channel_id)
# 墓
@tree.command(name="tomb")
async def command_tree_tomb(itrc:Interaction, content:str=""):
"""
墓を作ります。
/tomb [文字列]
"""
await bot_commands.tomb(itrc, None, content=content)
#Text to image(Stable Diffusion)
# @tree.command(name="txt2img")
# async def command_tree_txt2img(itrc:Interaction):
# """
# Stable Diffusionを用いてテキストから画像を生成します。
# """
# await bot_commands.txt2img(itrc, None)
# ウマ娘ガチャシミュレーター
@tree.command(name="uma")
async def command_tree_uma(itrc: Interaction, weights_1: int=79, weights_2: int=18, weights_3: int=3):
"""
ウマ娘のガチャ(10連)をシミュレートします。
/uma [☆1の確率の重み(オプション)] [☆2の確率の重み(オプション)] [☆3の確率の重み(オプション)]
"""
await bot_commands.uma(
itrc,
None,
weights_1=weights_1,
weights_2=weights_2,
weights_3=weights_3
)
##########################################################################
#### Bot Command
##########################################################################
# BPM
@bot.command(name="bpm")
async def command_bot_bpm(ctx):
"""
音声のBPM値を算出します。
(調べたい音声の近くに)&bpm
"""
await bot_commands.bpm(None, ctx)
# 画像に各種エフェクトをかける
@bot.command(name="effect")
async def command_bot_effect(ctx, *args):
"""
画像にエフェクトを適用します。
(適用したい画像の近くに)&effect [モード] [モードごとの引数] ...
"""
try:
await bot_commands.effect(None, ctx, prompt=args[0])
except:
await bot_commands.effect(None, ctx)
# カニ
@bot.command(name="kani")
async def command_bot_kani(ctx, *args):
"""
見て見てフラッシュさん カニファル子だよ~
&kani ['カニ'にあたる部分の文字列]
"""
if args:
await bot_commands.kani(None, ctx, kani_text=args[0])
else:
await bot_commands.kani(None, ctx)
# カニ(画像)
@bot.command(name="kani_img")
async def command_bot_kani_img(ctx, *args):
"""
見て見てフラッシュさん カニファル子だよ~の画像版
&kani_img ['カニ'にあたる部分の文字列]
"""
if args:
await bot_commands.kani_img(None, ctx, kani_text=args[0])
else:
await bot_commands.kani_img(None, ctx)
# 言葉狩り機能のオンオフ
@bot.command(name="kotobagari")
async def command_bot_kotobagari(ctx, *args):
"""
送信されたチャンネルの言葉狩り機能のオン/オフを変更します。
"""
try:
if args[0].lower() == "true":
mode = True
else:
mode = False
await bot_commands.kotobagari(None, ctx, mode=mode)
except:
await bot_commands.kotobagari(None, ctx, mode=False)
# クワガタ
@bot.command(name="kuwagata")
async def command_bot_kuwagata(ctx, *args):
"""
フラッシュさん見て見て クワガタ~
&kuwagata ['クワガタ'にあたる部分の文字列]
"""
if args:
await bot_commands.kuwagata(None, ctx, kuwagata_text=args[0])
else:
await bot_commands.kuwagata(None, ctx)
# クワガタ(画像)
@bot.command(name="kuwagata_img")
async def command_bot_kuwagata_img(ctx, *args):
"""
フラッシュさん見て見て クワガタ~の画像版
&kuwagata_img ['クワガタ'にあたる部分の文字列]
"""
if args:
await bot_commands.kuwagata_img(None, ctx, kuwagata_text=args[0])
else:
await bot_commands.kuwagata_img(None, ctx)
# おくり
@bot.command(name="okuri")
async def command_bot_okuri(ctx, *args):
"""
おくりさんどれだけ性欲あるの
&okuri ['性欲'にあたる部分の文字列] ['ある'にあたる部分の文字列] ['の'にあたる部分の文字列]
"""
if args:
if len(args) > 2:
text = args
elif len(args) == 2:
text = [args[0], args[1], "の"]
else:
text = [args[0], "ある", "の"]
else:
text = ["性欲", "ある", "の"]
await bot_commands.okuri(
None,
ctx,
seiyoku=text[0],
aru=text[1],
no=text[2]
)
# Ping
@bot.command(name="ping")
async def command_bot_ping(ctx):
"""
Ping値を取得します。
"""
await bot_commands.ping(None, ctx, bot)
# raika
@bot.command(name="raika")
async def command_bot_raika(ctx, *args):
"""
raikaさんのおもしろツイートガチャ
&raika [実行したい回数]
"""
try:
n = int(args[0])
await bot_commands.raika(None, ctx, n=n)
except:
await bot_commands.raika(None, ctx)
# 背景を透過
@bot.command(name="removebg")
async def command_bot_removebg(ctx, *args):
"""
画像の背景を透過します。
(透過したい画像の近くに)&removebg [透過方法(オプション)]
・透過方法:use_removebgapiをTrueにするとremovebg APIを使って透過します。
removebg APIの使用制限に達した場合はrembgが使用されます。
"""
try:
use_removebgapi = False
if args[0].lower() == "true":
await bot_commands.removebg(None, ctx, True)
except:
await bot_commands.removebg(None, ctx)
# 任意のメッセージを送信
@bot.command(name="send")
async def command_bot_send(ctx, *args):
"""
任意のメッセージを送信します。
&send [メッセージ] [チャンネルID]
"""
if len(args) > 1:
await bot_commands.send(None, ctx, bot, args[0], args[1])
elif args:
await bot_commands.send(None, ctx, bot, args[0])
# 墓
@bot.command(name="tomb")
async def command_bot_tomb(ctx, *args):
"""
墓を作ります。
&tomb [文字列]
"""
if args:
await bot_commands.tomb(None, ctx, content=args[0])
else:
await bot_commands.tomb(None, ctx)
#Text to image(Stable Diffusion)
# @bot.command(name="txt2img")
# async def command_bot_txt2img(ctx):
# """
# Stable Diffusionを用いてテキストから画像を生成します。
# """
# await bot_commands.txt2img(None, ctx)
# ウマ娘ガチャシミュレーター
@bot.command(name="uma")
async def command_bot_uma(ctx, *args):
"""
ウマ娘のガチャ(10連)をシミュレートします。
&uma [☆1の確率の重み(オプション)] [☆2の確率の重み(オプション)] [☆3の確率の重み(オプション)]
"""
try:
if len(args) > 2:
custom_weights = [int(i) for i in args[:3]]
weights_sum = sum(custom_weights)
custom_weights = [i / weights_sum * 100 for i in custom_weights]
else:
custom_weights = [None, None, None]
except:
custom_weights = [None, None, None]
await bot_commands.uma(
None,
ctx,
weights_1=custom_weights[0],
weights_2=custom_weights[1],
weights_3=custom_weights[2]
)
##########################################################################
#### Run
##########################################################################
# Botの起動とDiscordサーバーへの接続
bot.run(DISCORD_BOT_TOKEN)