From 42b1c62387a77a5e5dda2902c2394f7ef5be1564 Mon Sep 17 00:00:00 2001 From: gx1285 <78240988+gx1285@users.noreply.github.com> Date: Sat, 10 Dec 2022 13:55:37 +0900 Subject: [PATCH 01/18] 2.1.0 beta1 --- cogs/5000.py | 2 +- cogs/afk.py | 9 ++++----- cogs/ban_member.py | 5 ++++- cogs/bot_info.py | 2 +- cogs/bot_invite.py | 39 +++++++++++++++++++++++---------------- cogs/bot_process.py | 18 ++++++++++++------ 6 files changed, 45 insertions(+), 30 deletions(-) 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..0fe987f 100644 --- a/cogs/afk.py +++ b/cogs/afk.py @@ -2,7 +2,6 @@ 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 +24,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 +33,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 +46,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 +55,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/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 From bf16d7affb93862e5037571cfb71638b1e4159db Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 13:29:38 +0900 Subject: [PATCH 02/18] delete: color.py --- color.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 color.py 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 From 8c04cfe1e5494906883b4eb8443f56f555dc1c7f Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 13:56:04 +0900 Subject: [PATCH 03/18] test --- cogs/embed.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cogs/embed.py b/cogs/embed.py index 8b13789..e69de29 100644 --- a/cogs/embed.py +++ b/cogs/embed.py @@ -1 +0,0 @@ - From 458fd51a16d4d1c5807db0cb83aac45362b40e4b Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 16:03:06 +0900 Subject: [PATCH 04/18] new: embed --- cogs/embed.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/cogs/embed.py b/cogs/embed.py index e69de29..47e6ee3 100644 --- a/cogs/embed.py +++ b/cogs/embed.py @@ -0,0 +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)) From a5a2ba0681b21fe0f1430a1b5835e3600274aec9 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 16:43:50 +0900 Subject: [PATCH 05/18] new: eight-auto-news --- cogs/auto-news.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cogs/auto-news.py 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)) From f7341161f1dc269b89a7b23e379a559fc07e69d9 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 16:50:38 +0900 Subject: [PATCH 06/18] flask8 lint --- cogs/afk.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogs/afk.py b/cogs/afk.py index 0fe987f..c00a18f 100644 --- a/cogs/afk.py +++ b/cogs/afk.py @@ -3,6 +3,7 @@ from replit import db import discord + def afk_set_db(key, data): db[f"afk_{key}"] = data From 518423a9398743b29ae157a461d6f6d834a1c51b Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 18:08:35 +0900 Subject: [PATCH 07/18] =?UTF-8?q?=E2=9C=A8new:=20global=20chat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- cogs/global-chat.py | 98 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 cogs/global-chat.py 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/cogs/global-chat.py b/cogs/global-chat.py new file mode 100644 index 0000000..255db60 --- /dev/null +++ b/cogs/global-chat.py @@ -0,0 +1,98 @@ +import discord +from discord.ext import commands +from discord import app_commands +from replit import db + + +def global_chat_set(key: int, data: str): + if data == "True": + db[f"global_chat_{key}"] = "True" + else: + db[f"global_chat_{key}"] = "False" + + +def global_chat(key: int): + try: + return db[f"global_chat_{key}"] + except KeyError: + return "False" + + +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 global_chat(self, message: discord.Message): + if message.author.bot: + return + if message.channel.type == discord.ChannelType.text: + for channel in self.bot.get_all_channels(): + if global_chat(channel.id) == "True": + if channel.id == message.channel.id: + 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 message.send(embed=embed) + await message.add_reaction('✅') + + @app_commands.guild_only() + @app_commands.command(name="global_chat_join", description="グローバルチャットを有効にします。") + async def global_set(self, i: discord.Interaction): + try: + if i.channel.channel.type == discord.ChannelType.text: + global_chat_set(i.channel_id, "True") + await i.response.send_message("グローバルチャットを有効にしました。", ephemeral=True) + else: + await i.response.send_message("グローバルチャットを有効にできませんでした。", ephemeral=True) + except: + await i.response.send_message("グローバルチャットを有効にできませんでした。", ephemeral=True) + + @app_commands.guild_only() + @app_commands.command(name="global_chat_leave", description="グローバルチャットを無効にします。") + async def global_set(self, i: discord.Interaction): + try: + if i.channel.channel.type == discord.ChannelType.text: + global_chat_set(i.channel_id, "False") + await i.response.send_message("グローバルチャットを無効にしました。", ephemeral=True) + else: + await i.response.send_message("グローバルチャットを無効にできませんでした。", ephemeral=True) + except: + await i.response.send_message("グローバルチャットを無効にできませんでした。", ephemeral=True) + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(auto_news(bot)) From 60b0c3b50e7bb7b6f25c799961dabacb5e54e72c Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 18:11:16 +0900 Subject: [PATCH 08/18] =?UTF-8?q?=F0=9F=90=9Bfix:=20class=E3=81=AE?= =?UTF-8?q?=E5=90=8D=E5=89=8D=E3=82=92=E5=A4=89=E3=81=88=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index 255db60..76e36b7 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -18,7 +18,7 @@ def global_chat(key: int): return "False" -class auto_news(commands.Cog): +class global_chat(commands.Cog): def __init__(self, bot: commands.Bot) -> None: self.bot: commands.Bot = bot @@ -95,4 +95,4 @@ async def global_set(self, i: discord.Interaction): async def setup(bot: commands.Bot) -> None: - await bot.add_cog(auto_news(bot)) + await bot.add_cog(global_chat(bot)) From aaf12f20dca622d28fd726eb834d2d4bd2aa4105 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 18:34:27 +0900 Subject: [PATCH 09/18] =?UTF-8?q?=F0=9F=94=84change:=20CONTRIBUTING.md?= =?UTF-8?q?=E3=81=AE=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88=E3=83=A1=E3=83=83?= =?UTF-8?q?=E3=82=BB=E3=83=BC=E3=82=B8=E3=81=AA=E3=81=A9=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) 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`
From fe8c6b75d5962ad3f0c6c10d4b902992a4ba4890 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 18:45:32 +0900 Subject: [PATCH 10/18] =?UTF-8?q?=F0=9F=90=9Bfix:=20AttributeError?= =?UTF-8?q?=E3=81=A8=E5=90=8D=E5=89=8D=E8=A2=AB=E3=82=8A=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index 76e36b7..927e344 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -18,12 +18,12 @@ def global_chat(key: int): return "False" -class global_chat(commands.Cog): +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(self, message: discord.Message): + async def global_chat_msg_sys(self, message: discord.Message): if message.author.bot: return if message.channel.type == discord.ChannelType.text: @@ -73,7 +73,7 @@ async def global_chat(self, message: discord.Message): @app_commands.command(name="global_chat_join", description="グローバルチャットを有効にします。") async def global_set(self, i: discord.Interaction): try: - if i.channel.channel.type == discord.ChannelType.text: + if i.channel.type == discord.ChannelType.text: global_chat_set(i.channel_id, "True") await i.response.send_message("グローバルチャットを有効にしました。", ephemeral=True) else: @@ -83,9 +83,9 @@ async def global_set(self, i: discord.Interaction): @app_commands.guild_only() @app_commands.command(name="global_chat_leave", description="グローバルチャットを無効にします。") - async def global_set(self, i: discord.Interaction): + async def global_not_set(self, i: discord.Interaction): try: - if i.channel.channel.type == discord.ChannelType.text: + if i.channel.type == discord.ChannelType.text: global_chat_set(i.channel_id, "False") await i.response.send_message("グローバルチャットを無効にしました。", ephemeral=True) else: @@ -95,4 +95,4 @@ async def global_set(self, i: discord.Interaction): async def setup(bot: commands.Bot) -> None: - await bot.add_cog(global_chat(bot)) + await bot.add_cog(global_chat_cog(bot)) From 6bc74eafd1cefe3d5fe1a753c19fab19dc600bbb Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 18:49:58 +0900 Subject: [PATCH 11/18] =?UTF-8?q?=F0=9F=90=9Bfix:=20=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=8C=E3=81=AA=E3=81=84=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index 927e344..cad0358 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -66,7 +66,7 @@ async def global_chat_msg_sys(self, message: discord.Message): embed.add_field( name='返信', value=reference_value, inline=True) - await message.send(embed=embed) + await message.channel.send(embed=embed) await message.add_reaction('✅') @app_commands.guild_only() From af70bf5076d248f0e7f754280facd40423dd6f6b Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 19:04:58 +0900 Subject: [PATCH 12/18] =?UTF-8?q?=F0=9F=90=9Bfix:=20=E3=81=84=E3=82=8D?= =?UTF-8?q?=E3=81=84=E3=82=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 72 ++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index cad0358..0d8b509 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -28,45 +28,45 @@ async def global_chat_msg_sys(self, message: discord.Message): return if message.channel.type == discord.ChannelType.text: for channel in self.bot.get_all_channels(): - if global_chat(channel.id) == "True": - if channel.id == message.channel.id: - 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), + if global_chat(channel.id) == "True": + if channel.id == message.channel.id: + return + else: + 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 + \ + 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) + 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 message.channel.send(embed=embed) + await channel.send(embed=embed) await message.add_reaction('✅') @app_commands.guild_only() From 35a6dc81106f6ccb20c414d5ca1a32cb9e9b3140 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 19:17:53 +0900 Subject: [PATCH 13/18] =?UTF-8?q?=F0=9F=94=84change:=20=E3=83=88=E3=83=94?= =?UTF-8?q?=E3=83=83=E3=82=AF=E5=BC=8F=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 127 +++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 83 deletions(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index 0d8b509..4dd9352 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -1,21 +1,6 @@ import discord from discord.ext import commands from discord import app_commands -from replit import db - - -def global_chat_set(key: int, data: str): - if data == "True": - db[f"global_chat_{key}"] = "True" - else: - db[f"global_chat_{key}"] = "False" - - -def global_chat(key: int): - try: - return db[f"global_chat_{key}"] - except KeyError: - return "False" class global_chat_cog(commands.Cog): @@ -24,75 +9,51 @@ def __init__(self, bot: commands.Bot) -> None: @commands.Cog.listener(name="on_message") async def global_chat_msg_sys(self, message: discord.Message): - if message.author.bot: - return - if message.channel.type == discord.ChannelType.text: - for channel in self.bot.get_all_channels(): - if global_chat(channel.id) == "True": - if channel.id == message.channel.id: - return - else: - 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) + 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.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('✅') - @app_commands.guild_only() - @app_commands.command(name="global_chat_join", description="グローバルチャットを有効にします。") - async def global_set(self, i: discord.Interaction): - try: - if i.channel.type == discord.ChannelType.text: - global_chat_set(i.channel_id, "True") - await i.response.send_message("グローバルチャットを有効にしました。", ephemeral=True) - else: - await i.response.send_message("グローバルチャットを有効にできませんでした。", ephemeral=True) - except: - await i.response.send_message("グローバルチャットを有効にできませんでした。", ephemeral=True) - - @app_commands.guild_only() - @app_commands.command(name="global_chat_leave", description="グローバルチャットを無効にします。") - async def global_not_set(self, i: discord.Interaction): - try: - if i.channel.type == discord.ChannelType.text: - global_chat_set(i.channel_id, "False") - await i.response.send_message("グローバルチャットを無効にしました。", ephemeral=True) - else: - await i.response.send_message("グローバルチャットを無効にできませんでした。", ephemeral=True) - except: - await i.response.send_message("グローバルチャットを無効にできませんでした。", ephemeral=True) - - async def setup(bot: commands.Bot) -> None: await bot.add_cog(global_chat_cog(bot)) From 973d1ab2c57308a9e42b96709ba6285320220706 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 19:18:47 +0900 Subject: [PATCH 14/18] =?UTF-8?q?=F0=9F=97=91=EF=B8=8Fdelete:=20=E4=B8=8D?= =?UTF-8?q?=E8=A6=81=E3=81=AAimport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index 4dd9352..95aa4b6 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -1,6 +1,5 @@ import discord from discord.ext import commands -from discord import app_commands class global_chat_cog(commands.Cog): From 7f93239902822394263772cb6c75533257afb3ca Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 19:29:33 +0900 Subject: [PATCH 15/18] =?UTF-8?q?=F0=9F=90=9Bfix:=20=E3=83=88=E3=83=94?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=8C=E3=81=AA=E3=81=84=E6=99=82=E3=80=81?= =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index 95aa4b6..e911792 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -14,6 +14,10 @@ async def global_chat_msg_sys(self, message: discord.Message): 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 @@ -51,7 +55,7 @@ async def global_chat_msg_sys(self, message: discord.Message): embed.add_field( name='返信', value=reference_value, inline=True) - await channel.send(embed=embed) + await channel.send(embed=embed) await message.add_reaction('✅') async def setup(bot: commands.Bot) -> None: From 12bec77ebdd7a7db85833a5a77710b0a791dcf69 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 20:17:02 +0900 Subject: [PATCH 16/18] =?UTF-8?q?=F0=9F=94=84change:=20help=E3=82=92?= =?UTF-8?q?=E8=87=AA=E5=8B=95=E3=81=A7=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F&=F0=9F=90=9Bfix:?= =?UTF-8?q?=20DM=E3=81=AEgchat=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/global-chat.py | 6 ++++-- cogs/help.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cogs/global-chat.py b/cogs/global-chat.py index e911792..99c913b 100644 --- a/cogs/global-chat.py +++ b/cogs/global-chat.py @@ -8,10 +8,12 @@ def __init__(self, bot: commands.Bot) -> None: @commands.Cog.listener(name="on_message") async def global_chat_msg_sys(self, message: discord.Message): - if message.channel.topic: + 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: + if message.author.bot: return for channel in self.bot.get_all_channels(): if channel.type != discord.ChannelType.text: diff --git a/cogs/help.py b/cogs/help.py index ca7f4f1..8a04b3a 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -3,7 +3,7 @@ import Paginator from discord import app_commands -a = "Tips: `/help コマンド名`でコマンドを検索できます。" +a = "Tips: /help コマンド名でコマンドを検索できます。" class Help(commands.Cog): @@ -21,11 +21,19 @@ async def help(self, i: discord.Interaction, cmd: str = None) -> None: he = discord.Embed(title="ページ2", color=discord.Colour.blurple()) he.add_field(name="help", value="helpを表示します。") he.set_footer(text=a) - embeds = [ - discord.Embed( + ee = discord.Embed( title="ページ1", color=discord.Colour.blurple(), - ).set_footer(text=a), + ).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) From 2677e266e6305208e1024d3ff1502b72a34c16a7 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 20:24:52 +0900 Subject: [PATCH 17/18] =?UTF-8?q?=E2=9C=A8new:=20help=E3=82=92=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E3=81=A7=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/help.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cogs/help.py b/cogs/help.py index 8a04b3a..8cda50e 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -18,12 +18,11 @@ def __init__(self, bot: commands.Bot) -> None: @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) ee = discord.Embed( title="ページ1", - color=discord.Colour.blurple(), + color=0x3498DB, ).set_footer(text=a) num = 0 for command in self.bot.tree.walk_commands(): @@ -37,20 +36,21 @@ async def help(self, i: discord.Interaction, cmd: str = None) -> None: 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, ) ) From 24262673d24c0d6361e8744f054a428e8e2694c2 Mon Sep 17 00:00:00 2001 From: Dec-dog Date: Mon, 12 Dec 2022 20:32:15 +0900 Subject: [PATCH 18/18] =?UTF-8?q?=E2=9C=A8new:=20help=E3=81=AEchoice?= =?UTF-8?q?=E3=82=92=E8=87=AA=E5=8B=95=E3=81=A7=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/help.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cogs/help.py b/cogs/help.py index 8cda50e..b308abf 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -4,16 +4,16 @@ from discord import app_commands 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: