-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommandLab.py
More file actions
174 lines (150 loc) · 6.87 KB
/
CommandLab.py
File metadata and controls
174 lines (150 loc) · 6.87 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
import asyncio
import logging
import logging.config
from datetime import datetime
from os import listdir, path
import os
import aiofiles
import discord
import yaml
from discord import app_commands
from discord.abc import User
from discord.ext import commands
from config.config import config
from utils.setup import setup, setup_mcdata
logger = logging.getLogger("root")
# ステータス定義 ({key}を{value}中)
STATUSES = [
("JavaEditionをプレイ中", "playing", 120),
("BedrockEditionをプレイ中", "playing", 120),
("BugEditionをプレイ中(笑)", "playing", 10),
("マイクラのコマンドを勉強中", "playing", 100),
("discord.pyとpythonを勉強中", "playing", 100),
("Javaを勉強中", "playing", 100),
("JavaScriptを勉強中", "playing", 100),
("コマ研Botはいつでもあなたのメッセージを見ている", "watching", 20),
("大体何でもできるのだ♪", "watching", 30),
("私はボットです", "playing", 30),
("Netflixで映画を視聴中", "watching", 30),
("ポテトをツンツン中", "playing", 30),
("YouTubeを視聴中", "watching", 60),
("新規機能随時募集中!", "watching", 60),
("お買い物中", "playing", 40),
("春菊を調理中", "playing", 40),
("すき焼きを食事中", "playing", 40),
("春菊の配信を視聴中", "watching", 10),
("ニコニコ動画を視聴中", "watching", 60),
("Spotifyを再生中", "listening", 60),
("サーバー人数2400人ありがとう!", "watching", 120),
("5周年ありがとう!", "watching", 120),
("MINCERAFT", "playing", 10),
("新規機能随時募集中!", "watching", 60),
]
class CommandLabBot(commands.Bot):
status_index: int
def __init__(self) -> None:
super().__init__(
command_prefix=config.prefix,
intents=discord.Intents.all(),
owner_ids=config.users.owner_ids,
)
self.status_index = 0
async def is_owner(self, user: User) -> bool:
return user.id in config.users.owner_ids
async def change_status(self):
await self.wait_until_ready()
name, activity_type, interval = STATUSES[self.status_index]
if activity_type == "playing": # ~をプレイ中
activity = discord.Activity(type=discord.ActivityType.playing, name=name)
elif activity_type == "streaming": # ~を配信中
activity = discord.Streaming(name=name, url="your_stream_url")
elif activity_type == "listening": # ~を再生中
activity = discord.Activity(type=discord.ActivityType.listening, name=name)
elif activity_type == "watching": # ~を視聴中
activity = discord.Activity(type=discord.ActivityType.watching, name=name)
elif activity_type == "competing": # ~に参戦中
activity = discord.Activity(type=discord.ActivityType.competing, name=name)
else: # その他
activity = discord.Activity(type=discord.ActivityType.custom, name=name)
await self.change_presence(activity=activity)
self.status_index += 1
if self.status_index >= len(STATUSES):
self.status_index = 0
await asyncio.sleep(interval)
asyncio.create_task(self.change_status())
async def setup_hook(self) -> None:
if "*" in config.enabled_features:
for name in listdir("cogs"):
if name != "__pycache__" and not name.startswith("_"):
modname = name.replace(".py", "")
f = f"cogs.{modname}"
await self.load_extension(f)
logger.info(f"機能 [{f}] が正常にロードされました。")
else:
for f in config.enabled_features:
await self.load_extension(f)
logger.info(f"機能 [{f}] が正常にロードされました。")
await self.tree.sync()
self.loop.create_task(self.change_status())
@classmethod
async def start(cls, token: str) -> None:
logging.config.dictConfig(
yaml.load(
await (await aiofiles.open(
path.join(os.getenv("BASE_DIR", "."), "data/logging.yaml")
)).read(),
Loader=yaml.SafeLoader,
)
)
await setup()
await setup_mcdata()
client = cls()
async with client:
@client.event
async def on_ready():
start_embed = discord.Embed(
title="BOTが起動しました!",
description="BOT has been started!",
color=0xFFD700,
timestamp=datetime.now(),
)
logger.info("BOTが起動しました")
if config.channels.komaken_bot_development_room is not None:
start_notice_channel = await client.fetch_channel(
config.channels.komaken_bot_development_room
)
await start_notice_channel.send(embed=start_embed)
@client.event
async def on_message(message: discord.Message):
if not message.author.bot:
if message.author.id in client.owner_ids or []:
await client.process_commands(message)
if client.user in message.mentions and message.reference is None:
if message.author.bot:
return
await message.reply(
f"{message.author.mention}呼んだ?わからないことがあったら以下のコマンドを実行してみてね(^^♪\n> 全コマンド雑説明: </chelp-all:1383117112628871198>\n> コマンド別説明 : </chelp:1218483030247604265>", silent=True
)
@client.tree.error
async def on_error(
ctx: discord.Interaction, error: app_commands.AppCommandError
):
if isinstance(error, app_commands.MissingRole) or isinstance(
error, app_commands.MissingPermissions
):
await ctx.response.send_message("権限あらへんで(関西弁)", ephemeral=True)
else:
logger.error(error)
return await super().start(client, token=token)
async def close(self) -> None:
logger.info("機能のアンロードを行っています...")
for e in list(self.extensions.keys()):
await self.unload_extension(e)
logger.info("機能のアンロードが完了しました。プロセスを終了します")
return await super().close()
if config.token == "FILE":
config.token = open("..\\CMTK.txt", mode="r").read()
if config.token == "ENV":
config.token = os.getenv("TOKEN")
if __name__ == "__main__":
asyncio.run(CommandLabBot.start(token=config.token))