diff --git a/.gitignore b/.gitignore index b6e4761..b2ebdde 100644 --- a/.gitignore +++ b/.gitignore @@ -54,7 +54,7 @@ coverage.xml # Translations *.mo *.pot - +.vscode/ # Django stuff: *.log local_settings.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2b3654..08a836d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,15 +1,23 @@ -# このBotへ貢献 -## Issueを作成するとき -1. その内容のIssueが既に存在していないかを確認して下さい。(クローズ済みのものも) +# この Bot へ貢献 + +## Issue を作成するとき + +1. その内容の Issue が既に存在していないかを確認して下さい。(クローズ済みのものも) 2. 内容を書き込みます。(テンプレートの場合は文字などを変更します) -3. Issueを作成します。 -## Pull requestを作成する時 -1. その内容のPull requestが既に存在していないかを確認して下さい。(マージ済み、クローズ済みのものも) +3. Issue を作成します。 + +## Pull request を作成する時 + +1. その内容の Pull request が既に存在していないかを確認して下さい。(マージ済み、クローズ済みのものも) 2. もう実装されていないか確認して下さい。 -3. Forkし、コードを書いて、内容を書き込みます。 -4. Pull requestを作成します。 +3. Fork し、コードを書いて、内容を書き込みます。 +4. Pull request を作成します。
+ WIP の場合は、`🚧WIP: oo`にしてください。 + ## コミットメッセージ -何かを作った: `new: ○○`
-何かを修正した: `fix: ○○`
-何かを変更した: `change: ○○`
-何かを更新した: `update: ○○`
+ +何かを作った: `✨new: ○○`
+何かを修正した: `🐛fix: ○○`
+何かを変更した: `🔄change: ○○`
+何かを更新した: `🆙update: ○○`
+何かを削除した: `🗑️delete: oo`
diff --git a/cogs/5000.py b/cogs/5000.py index 604450b..6e07a2d 100644 --- a/cogs/5000.py +++ b/cogs/5000.py @@ -61,7 +61,7 @@ async def gosen( noalpha: str, rainbow: str, ): - embed = discord.Embed(title="5000兆円ほしい!!").set_image(url=f"https://gsapi.cbrx.io/image?top={urllib.parse.quote(top)}&bottom={urllib.parse.quote(bottom)}&type={urllib.parse.quote(type)}&q={urllib.parse.quote(quality)}&hoshii={urllib.parse.quote(hoshii)}&noalpha={urllib.parse.quote(noalpha)}&rainbow={urllib.parse.quote(rainbow)}") + embed = discord.Embed(title="5000兆円ほしい!!", color=0x3498DB).set_image(url=f"https://gsapi.cbrx.io/image?top={urllib.parse.quote(top)}&bottom={urllib.parse.quote(bottom)}&type={urllib.parse.quote(type)}&q={urllib.parse.quote(quality)}&hoshii={urllib.parse.quote(hoshii)}&noalpha={urllib.parse.quote(noalpha)}&rainbow={urllib.parse.quote(rainbow)}") await i.response.send_message( embed=embed ) diff --git a/cogs/afk.py b/cogs/afk.py index 97cef3c..c00a18f 100644 --- a/cogs/afk.py +++ b/cogs/afk.py @@ -2,7 +2,7 @@ from discord import app_commands from replit import db import discord -from color import color + def afk_set_db(key, data): db[f"afk_{key}"] = data @@ -25,7 +25,7 @@ async def afks(self, i: discord.Interaction, reason: str): embed=discord.Embed( title="<:check_mark:985366958537076766> : 成功", description="afkをセットしました。", - color=color, + color=0x3498DB, ), ephemeral=True, ) @@ -34,7 +34,7 @@ async def afks(self, i: discord.Interaction, reason: str): embed=discord.Embed( title="<:error_mark:985366305156767794> : 失敗", description="何らかのエラーが発生しました。", - color=color, + color=0x3498DB, ), ephemeral=True, ) @@ -47,7 +47,7 @@ async def afkk(self, i: discord.Interaction): embed=discord.Embed( title="<:check_mark:985366958537076766> : 成功", description="afkを解除しました。", - color=color, + color=0x3498DB, ), ephemeral=True, ) @@ -56,7 +56,7 @@ async def afkk(self, i: discord.Interaction): embed=discord.Embed( title="<:error_mark:985366305156767794> : 失敗", description="何らかのエラーが発生しました。", - color=color, + color=0x3498DB, ), ephemeral=True, ) diff --git a/cogs/auto-news.py b/cogs/auto-news.py new file mode 100644 index 0000000..8217d2d --- /dev/null +++ b/cogs/auto-news.py @@ -0,0 +1,26 @@ +import discord +from discord.ext import commands + + +class auto_news(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @commands.Cog.listener(name="on_message") + async def msg_auto_news(self, msg: discord.Message): + if msg.channel.type == discord.ChannelType.news: + if msg.channel.topic: + if msg.channel.topic.startswith("eight-auto-news"): + await msg.publish() + await msg.add_reaction("✅") + return + else: + return + else: + return + else: + return + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(auto_news(bot)) diff --git a/cogs/ban_member.py b/cogs/ban_member.py index 166e49b..db50753 100644 --- a/cogs/ban_member.py +++ b/cogs/ban_member.py @@ -18,7 +18,10 @@ async def ban_members(self, i: discord.Interaction): send_content = "".join(m) elif len(m) == 0: send_content = "Banされたユーザーはいません。" - await i.response.send_message(send_content) + try: + await i.response.send_message(embed=discord.Embed(title="Banされたユーザー", description=send_content, color=0x3498DB), ephemeral=True) + except: + await i.response.send_message(embed=discord.Embed(title="Banされたユーザー", description="取得できませんでした。", color=0x3498DB), ephemeral=True) async def setup(bot: commands.Bot) -> None: diff --git a/cogs/bot_info.py b/cogs/bot_info.py index 7c58322..e2169fa 100644 --- a/cogs/bot_info.py +++ b/cogs/bot_info.py @@ -19,7 +19,7 @@ def __init__(self, bot: commands.Bot) -> None: @app_commands.command(name="bot_info", description="Botの情報を表示します。") async def botinfo(self, i: discord.Interaction): await i.response.send_message( - embed=discord.Embed(title="Botの情報").add_field( + embed=discord.Embed(title="Botの情報", color=0x3498DB).add_field( name="全コマンドの合計実行数", value=str(bot_command_all_count_db_get()) ), ephemeral=True, diff --git a/cogs/bot_invite.py b/cogs/bot_invite.py index 05cba0d..1488800 100644 --- a/cogs/bot_invite.py +++ b/cogs/bot_invite.py @@ -11,11 +11,16 @@ def db_set(key, data): def db_get(key): return db[f"bot_invite_db_id_{key}"] - class MyView(discord.ui.View): - @discord.ui.select( - placeholder="招待するBotの権限を選択して下さい", + def __init__(self): + super().__init__(timeout=None) + self.add_item(MySelect()) + +class MySelect(discord.ui.Select): + def __init__(self): + super().__init__(placeholder="招待するBotの権限を選択して下さい", min_values=1, + custom_id="bot_invite_myview_select_menu", max_values=1, options=[ discord.SelectOption( @@ -29,26 +34,28 @@ class MyView(discord.ui.View): discord.SelectOption( label="権限なし", description="全ての権限をなしにしたURLを生成します。", value="none" ), - ], - ) - async def select_callback(self, select, i): + ]) + + async def callback(self, i: discord.Interaction): bot_id = db_get(i.message.id) - d = select.values[0] + d = self.values[0] if d == "admin": - await i.response.edit_message( - f"セレクトメニューをクリックして選択してください\n[Botを招待]({discord.utils.oauth_url(int(bot_id), permissions=discord.Permissions(permissions=discord.Permissions.administrator.flag))})" + await i.response.send_message( + ephemeral=True, + content=f"[Botを招待]({discord.utils.oauth_url(int(bot_id), permissions=discord.Permissions(permissions=discord.Permissions.administrator.flag))})" ) elif d == "all": - await i.response.edit_message( - f"セレクトメニューをクリックして選択してください\n[Botを招待]({discord.utils.oauth_url(int(bot_id), permissions=discord.Permissions(permissions=discord.Permissions.all()))})" + await i.response.send_message( + ephemeral=True, + content=f"[Botを招待]({discord.utils.oauth_url(int(bot_id), permissions=discord.Permissions(permissions=discord.Permissions.all().value))})" ) elif d == "none": - await i.response.edit_message( - f"セレクトメニューをクリックして選択してください\n[Botを招待]({discord.utils.oauth_url(int(bot_id))})" + await i.response.send_message( + ephemeral=True, + content=f"[Botを招待]({discord.utils.oauth_url(int(bot_id))})" ) else: - await i.response.edit_message("セレクトメニューをクリックして選択してください\n不明なパラメーターが選択されました。") - + await i.response.send_message("不明なパラメーターが選択されました。", ephemeral=True) class bot_invite(commands.Cog): def __init__(self, bot: commands.Bot) -> None: @@ -68,7 +75,7 @@ async def botinvite(self, i: discord.Interaction, bot: discord.User = None): else: await i.response.send_message("セレクトメニューをクリックして選択してください") msg = await self.bot.get_channel(i.channel.id).send(view=MyView()) - db_set(int(msg.id), int(self.bot.id)) + db_set(int(msg.id), int(self.bot.user.id)) self.bot.add_view(MyView(), message_id=msg.id) diff --git a/cogs/bot_process.py b/cogs/bot_process.py index 01e0720..4f3b560 100644 --- a/cogs/bot_process.py +++ b/cogs/bot_process.py @@ -1,6 +1,5 @@ import discord from discord.ext import commands -from discord import app_commands from replit import db @@ -9,15 +8,22 @@ def bot_command_count_get(data): def bot_command_count(data): - db[f"bot_command_{data}_count_db"] = int(bot_command_count_get()) + 1 + try: + db[f"bot_command_{data}_count_db"] = int(bot_command_count_get(data)) + 1 + except KeyError: + db[f"bot_command_{data}_count_db"] = 0 + 1 def bot_command_all_count_db_get(): - return db[f"bot_command_all_count_db"] + return db["bot_command_all_count_db"] def bot_command_count_p1(): - db[f"bot_command_all_count_db"] = int(bot_command_all_count_db_get()) + 1 + try: + db["bot_command_all_count_db"] = int(bot_command_all_count_db_get()) + 1 + return + except KeyError: + db["bot_command_all_count_db"] = 0 + 1 class bot_process(commands.Cog): @@ -28,8 +34,8 @@ def __init__(self, bot: commands.Bot) -> None: async def interaction(self, i: discord.Interaction): if i.type == discord.InteractionType.application_command: bot_command_count_p1() - if self.bot.tree.get_command(i.command.name): - bot_command_count(i.command.name) + if i.command: + bot_command_count(data=i.command.name) else: return diff --git a/cogs/embed.py b/cogs/embed.py index 8b13789..47e6ee3 100644 --- a/cogs/embed.py +++ b/cogs/embed.py @@ -1 +1,81 @@ +from discord.ext import commands +from discord import app_commands +import discord +from discord import ui, TextStyle + +class Modal(ui.Modal, title='Embed作成パネル'): + titles = ui.TextInput(label="タイトル", style=TextStyle.long, + placeholder="埋め込みのタイトル。256文字まで", max_length=256, required=False) + description = ui.TextInput(label="説明", style=TextStyle.long, + placeholder="埋め込みの説明。4000文字まで", max_length=4000, required=True) + set_footer_text = ui.TextInput(label="フッターテキスト", style=TextStyle.long, + placeholder="フッターテキスト。2048文字まで", max_length=2048, required=False) + f_icon_url = ui.TextInput(label="フッターアイコン", style=TextStyle.short, + placeholder="フッターアイコンのURL。Http(s)のみ", required=False) + samuneiru = ui.TextInput(label="サムネイル", style=TextStyle.short, + placeholder="埋め込みコンテンツのサムネイル。Http(s)のみ", required=False) + + async def on_submit(self, interaction: discord.Interaction): + if str(self.f_icon_url).startswith("http://") or str(self.samuneiru).startswith("http://") or str(self.f_icon_url).startswith("https://") or str(self.samuneiru).startswith("https://"): + await interaction.response.send_message("URLはhttp(s)から始まります。", ephemeral=True) + return + embed = discord.Embed(title=self.titles, description=self.description) + embed.set_footer(text=self.set_footer_text, icon_url=self.f_icon_url) + embed.set_thumbnail(url=self.samuneiru) + buttonView = discord.ui.View(timeout=None) + buttonView.add_item(discord.ui.Button( + label="Discord Color", style=discord.ButtonStyle.primary, custom_id="color_01" + )) + buttonView.add_item( + discord.ui.Button( + label="灰色", style=discord.ButtonStyle.secondary, custom_id="color_02" + )) + buttonView.add_item( + discord.ui.Button( + label="緑", style=discord.ButtonStyle.success, custom_id="color_03" + )) + buttonView.add_item( + discord.ui.Button( + label="赤", style=discord.ButtonStyle.danger, custom_id="color_04" + )) + await interaction.response.send_message(embed=embed, view=buttonView) + + +class embed_make(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @commands.Cog.listener(name="on_interaction") + async def color_interaction(self, i: discord.Interaction): + if i.data.get("custom_id") == "color_01": + em = i.message.embeds[0] + em.color = 0x5865F2 + await i.message.edit(embed=em) + return await i.response.send_message("完了!", ephemeral=True) + if i.data.get("custom_id") == "color_02": + em = i.message.embeds[0] + em.color = 0x4F545C + await i.message.edit(embed=em) + return await i.response.send_message("完了!", ephemeral=True) + if i.data.get("custom_id") == "color_03": + em = i.message.embeds[0] + em.color = 0x43B581 + await i.message.edit(embed=em) + return await i.response.send_message("完了!", ephemeral=True) + if i.data.get("custom_id") == "color_04": + em = i.message.embeds[0] + em.color = 0xF04747 + await i.message.edit(embed=em) + return await i.response.send_message("完了!", ephemeral=True) + + else: + return + + @app_commands.command(name="embed_make", description="Embedを作成し、送信します。") + async def embed_make(self, i: discord.Interaction): + await i.response.send_modal(Modal()) + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(embed_make(bot)) diff --git a/cogs/global-chat.py b/cogs/global-chat.py new file mode 100644 index 0000000..99c913b --- /dev/null +++ b/cogs/global-chat.py @@ -0,0 +1,64 @@ +import discord +from discord.ext import commands + + +class global_chat_cog(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @commands.Cog.listener(name="on_message") + async def global_chat_msg_sys(self, message: discord.Message): + if message.channel.type != discord.ChannelType.text: + return + if message.channel.topic: + if not message.channel.topic.startswith("eight-global"): + return + if message.author.bot: + return + for channel in self.bot.get_all_channels(): + if channel.type != discord.ChannelType.text: + continue + if not channel.topic: + continue + if channel.topic.startswith("eight-global"): + if channel == message.channel: + continue + embed = discord.Embed(description=message.content, color=0x3498DB) + if hasattr(message.author.avatar, 'key'): + embed.set_author(name="{}#{}".format(message.author.name, message.author.discriminator), icon_url="https://media.discordapp.net/avatars/{}/{}.png?size=1024".format( + message.author.id, message.author.avatar.key)) + else: + embed.set_author(name="{}#{}".format( + message.author.name, message.author.discriminator), url=f"https://discord.com/users/{message.author.id}") + if hasattr(message.guild.icon, 'key'): + embed.set_footer(text="{} / mID:{}".format(message.guild.name, message.id), + icon_url="https://media.discordapp.net/icons/{}/{}.png?size=1024".format(message.guild.id, message.guild.icon.key)) + else: + embed.set_footer( + text="{} / mID:{}".format(message.guild.name, message.id)) + if message.attachments != []: + embed.set_image(url=message.attachments[0].url) + if message.stickers != []: + embed.set_thumbnail(url=message.stickers[0].url) + if message.reference: + reference_msg = await message.channel.fetch_message(message.reference.message_id) + if reference_msg.embeds and reference_msg.author == self.bot.user: + reference_message_content = reference_msg.embeds[0].description + reference_message_author = reference_msg.embeds[0].author.name + elif reference_msg.author != self.bot.user: + reference_message_content = reference_msg.content + reference_message_author = reference_msg.author.name + \ + '#'+reference_msg.author.discriminator + reference_content = "" + for string in reference_message_content.splitlines(): + reference_content += "> " + string + "\n" + reference_value = "**@{}**\n{}".format( + reference_message_author, reference_content) + embed.add_field( + name='返信', value=reference_value, inline=True) + + await channel.send(embed=embed) + await message.add_reaction('✅') + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(global_chat_cog(bot)) diff --git a/cogs/help.py b/cogs/help.py index ca7f4f1..b308abf 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -3,46 +3,54 @@ import Paginator from discord import app_commands -a = "Tips: `/help コマンド名`でコマンドを検索できます。" - +a = "Tips: /help コマンド名でコマンドを検索できます。" +cmd = [] class Help(commands.Cog): def __init__(self, bot: commands.Bot) -> None: self.bot: commands.Bot = bot + for command in self.bot.tree.walk_commands(): + cmd.append(app_commands.Choice(name=command.name, value=command.name)) @discord.app_commands.choices( - cmd=[ - discord.app_commands.Choice(name="help", value="help"), - ] + cmd=cmd ) @app_commands.command(name="help", description="helpを表示します。") async def help(self, i: discord.Interaction, cmd: str = None) -> None: if not cmd: - he = discord.Embed(title="ページ2", color=discord.Colour.blurple()) - he.add_field(name="help", value="helpを表示します。") + he = discord.Embed(title="ページ2", color=0x3498DB) he.set_footer(text=a) - embeds = [ - discord.Embed( + ee = discord.Embed( title="ページ1", - color=discord.Colour.blurple(), - ).set_footer(text=a), + color=0x3498DB, + ).set_footer(text=a) + num = 0 + for command in self.bot.tree.walk_commands(): + num = num + 1 + if num > 24: + he.add_field(name=command.name, value=command.description) + else: + ee.add_field(name=command.name, value=command.description) + embeds = [ + ee, he, ] return await Paginator.Simple().start(i, pages=embeds) - elif cmd == "help": - return await i.response.send_message( - embed=discord.Embed( - title="help", - description="コマンドのヘルプを表示します。", - color=discord.Colour.blurple(), - ).add_field(name="使い方", value="`/help コマンド名(任意)`") + elif cmd: + if self.bot.tree.get_command(cmd): + return await i.response.send_message( + embed=discord.Embed( + title=self.bot.tree.get_command(cmd).name, + description=self.bot.tree.get_command(cmd).description, + color=0x3498DB, + ) ) else: return await i.response.send_message( embed=discord.Embed( title="エラー", description="検索した名前のコマンドは存在しません。", - color=discord.Colour.blurple(), + color=0x3498DB, ) ) diff --git a/color.py b/color.py deleted file mode 100644 index b83fa77..0000000 --- a/color.py +++ /dev/null @@ -1 +0,0 @@ -color = 0x3498DB \ No newline at end of file