Skip to content

Commit

Permalink
Merge pull request #124 from mii-10/master
Browse files Browse the repository at this point in the history
  • Loading branch information
takumi0213 committed Dec 28, 2023
2 parents 3b1f134 + c324a1b commit 32904a2
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions cogs/hybrid/m10s_re_gchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async def connect(self, ctx: commands.Context, *, name:str="main"):
""")
await check_msg.add_reaction("✅")
try:
await self.bot.wait_for("reaction_add", check = lambda r,u: ctx.author.id == u.id and r.message.id == check_msg.id and str(r.emoji) == "✅")
await self.bot.wait_for("reaction_add", check = lambda r,u: ctx.author.id == u.id and r.message.id == check_msg.id and str(r.emoji) == "✅", timeout=30)
except asyncio.TimeoutError:
return await ctx.send("> グローバルチャットへの接続をキャンセルしました。")
if gch:
Expand All @@ -128,22 +128,22 @@ async def connect(self, ctx: commands.Context, *, name:str="main"):
await ctx.author.send("> 接続エラー\n パスワードが違います。もう一度最初からやり直してください。")
sendto = await self.bot.cursor.fetchall("select * from gchat_cinfo where connected_to = %s",(name,))
#sendto = await self.bot.cursor.fetchall()
await self.gchat_send(sendto, ctx.channel, f"> {ctx.author}({ctx.author.id})が{ctx.channel.name}({ctx.channel.id})をこのチャンネルに接続しようとしました。(パスワードが違うことにより失敗)",
"[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
# await self.gchat_send(sendto, ctx.channel, f"> {ctx.author}({ctx.author.id})が{ctx.channel.name}({ctx.channel.id})をこのチャンネルに接続しようとしました。(パスワードが違うことにより失敗)",
# "[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
return
except:
await ctx.author.send("> 接続エラー\n パスワードが入力されませんでした。")
sendto = await self.bot.cursor.fetchall("select * from gchat_cinfo where connected_to = %s",(name,))
#sendto = await self.bot.cursor.fetchall()
await self.gchat_send(sendto, ctx.channel, f"> {ctx.author}({ctx.author.id})が{ctx.channel.name}({ctx.channel.id})をこのチャンネルに接続しようとしました。(パスワード未入力により失敗)",
"[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
# await self.gchat_send(sendto, ctx.channel, f"> {ctx.author}({ctx.author.id})が{ctx.channel.name}({ctx.channel.id})をこのチャンネルに接続しようとしました。(パスワード未入力により失敗)",
# "[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
return
wh = await ctx.channel.create_webhook(name="sina_gchat_webhook",reason=f"思惟奈ちゃんグローバルチャット:{name}への接続が行われたため")
await self.bot.cursor.execute("insert into gchat_cinfo(id,connected_to,wh_id) values(%s,%s,%s)", (ctx.channel.id,name,wh.id))
sendto = await self.bot.cursor.fetchall("select * from gchat_cinfo where connected_to = %s", (name,))
#sendto = await self.bot.cursor.fetchall()
await self.gchat_send(sendto, ctx.channel, f"> グローバルチャットに{ctx.channel.name}({ctx.channel.id})が接続しました!ようこそ!",
"[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
# await self.gchat_send(sendto, ctx.channel, f"> グローバルチャットに{ctx.channel.name}({ctx.channel.id})が接続しました!ようこそ!",
# "[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)

await ctx.send("> 接続が完了しました。")
else:
Expand All @@ -164,8 +164,8 @@ async def connect(self, ctx: commands.Context, *, name:str="main"):

sendto = await self.bot.cursor.fetchall("select * from gchat_cinfo where connected_to = %s", (name,))
#sendto = await self.bot.cursor.fetchall()
await self.gchat_send(sendto, ctx.channel, f"> グローバルチャットに{ctx.channel.name}({ctx.channel.id})が接続しました!",
"[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
# await self.gchat_send(sendto, ctx.channel, f"> グローバルチャットに{ctx.channel.name}({ctx.channel.id})が接続しました!",
# "[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)

await ctx.send("> 接続が完了しました。")

Expand All @@ -187,8 +187,8 @@ async def dconnect(self, ctx:commands.Context):

sendto = await self.bot.cursor.fetchall("select * from gchat_cinfo where connected_to = %s",(cgch["connected_to"],))
#sendto = await self.bot.cursor.fetchall()
await self.gchat_send(sendto, ctx.channel, f"> グローバルチャットから{ctx.channel.name}({ctx.channel.id})が切断しました。さようなら。",
"[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)
# await self.gchat_send(sendto, ctx.channel, f"> グローバルチャットから{ctx.channel.name}({ctx.channel.id})が切断しました。さようなら。",
# "[🛠💠]思惟奈ちゃんグローバルチャット接続案内", ctx.guild.me.display_avatar.replace(static_format="png").url)

await ctx.reply("> 切断が完了しました。\n このチャンネルでの思惟奈ちゃんグローバルチャットのご利用ありがとうございました。")
else:
Expand All @@ -198,8 +198,8 @@ async def dconnect(self, ctx:commands.Context):
@gchat.command(description="グローバルチャットに投稿されたメッセージについて確認します。")
@app_commands.describe(globalchat_message_id="グローバルチャットに投稿されたメッセージのid")
@ut.runnable_check()
async def check_post(self, ctx, globalchat_message_id: int):
gmid = globalchat_message_id
async def check_post(self, ctx, globalchat_message_id: str):
gmid = int(globalchat_message_id)
post = None
dats = await self.bot.cursor.fetchall("select * from gchat_pinfo")
#dats = await self.bot.cursor.fetchall()
Expand Down Expand Up @@ -493,7 +493,8 @@ async def on_message(self, m):
#gpf = await self.bot.cursor.fetchone()

status_embed = discord.Embed(title="", description="", color=upf["gcolor"])
status_embed.set_author(
status_embed_has_content = False
"""status_embed.set_author(
name=f"{ut.ondevicon(m.author)},({str(m.author.id)})")
if gpf["verified"]:
if m.guild.icon:
Expand All @@ -506,9 +507,10 @@ async def on_message(self, m):
status_embed.set_footer(text=f"{m.guild.name}(id:{m.guild.id})",
icon_url=m.guild.icon.replace(static_format="png").url)
else:
status_embed.set_footer(text=f"{m.guild.name}(id:{m.guild.id})")
status_embed.set_footer(text=f"{m.guild.name}(id:{m.guild.id})")"""

if m.type == discord.MessageType.reply:
status_embed_has_content = True
ref = m.reference
if ref.cached_message:
msg = ref.cached_message
Expand All @@ -522,15 +524,15 @@ async def on_message(self, m):
else:
status_embed.add_field(name="メッセージへの返信",value="(このメッセージは削除されている等で取得できません。)")

if gchat_info["connected_to"] in self.without_react:
if status_embed_has_content == False or gchat_info["connected_to"] in self.without_react:
embeds = []
else:
embeds = [status_embed]

if m.stickers:
sticker = m.stickers[0]
sembed = discord.Embed(title=f"スタンプ:{sticker.name}",)
if sticker.format == discord.StickerFormatType.png or sticker.format == discord.StickerFormatType.apng:
if sticker.format == discord.StickerFormatType.png or sticker.format == discord.StickerFormatType.apng or discord.StickerFormatType.gif:
sembed.set_image(url=sticker.url)
elif sticker.format == discord.StickerFormatType.lottie:
# メモ: https://cdn.discordapp.com/stickers/{id}/{hash}.json?size=1024
Expand Down

0 comments on commit 32904a2

Please sign in to comment.