From a08e5a99362407409ee74b407ba3fb3c04ac2b0d Mon Sep 17 00:00:00 2001 From: renorari Date: Thu, 28 Sep 2023 08:23:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Change:=20LainanAPI=E3=81=8B=E3=82=89KanaAP?= =?UTF-8?q?I=E3=81=B8=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/autoreply.py | 2 +- cogs/channel_settings.py | 24 ++++++------- cogs/cog.py | 2 +- cogs/fun.py | 59 +++++++++++++++++-------------- cogs/level.py | 2 +- common_resources/settings.py | 2 +- common_resources/tokens.py.sample | 2 ++ translations/en/main.json | 8 ++--- translations/ja/main.json | 8 ++--- 9 files changed, 58 insertions(+), 51 deletions(-) diff --git a/cogs/autoreply.py b/cogs/autoreply.py index 00d3abb..dca834d 100644 --- a/cogs/autoreply.py +++ b/cogs/autoreply.py @@ -70,7 +70,7 @@ async def on_message_ar(self, message): return if not self.bot.is_ready(): return - if message.author.bot or message.channel.id in self.bot.guild_settings[message.guild.id]["lainan_talk"]: + if message.author.bot or message.channel.id in self.bot.guild_settings[message.guild.id]["kana_talk"]: return if message.author.id in SB_Bans.keys() and is_command(message): if SB_Bans[message.author.id] > time.time(): diff --git a/cogs/channel_settings.py b/cogs/channel_settings.py index 7ff8555..175e163 100644 --- a/cogs/channel_settings.py +++ b/cogs/channel_settings.py @@ -114,33 +114,33 @@ async def activate_2ch_link(self, ctx): e = discord.Embed(title="既に有効です。", description="", color=Error) return await ctx.reply(embed=e) - @channel_setting.group(name="lainan_talk", invoke_without_command=True) + @channel_setting.group(name="kana_talk", invoke_without_command=True) @commands.has_permissions(manage_channels=True) - async def ch_lainan_talk(self, ctx): + async def ch_kana_talk(self, ctx): await self.bot.send_subcommands(ctx) - @ch_lainan_talk.command(name="deactivate", aliases=Deactivate_aliases) + @ch_kana_talk.command(name="deactivate", aliases=Deactivate_aliases) @commands.has_permissions(manage_channels=True) - async def deactivate_lainan_talk(self, ctx): - if ctx.channel.id not in self.bot.guild_settings[ctx.guild.id]["lainan_talk"]: + async def deactivate_kana_talk(self, ctx): + if ctx.channel.id not in self.bot.guild_settings[ctx.guild.id]["kana_talk"]: e = discord.Embed(title="既に無効化されています。", description="", color=Error) return await ctx.reply(embed=e) else: - self.bot.guild_settings[ctx.guild.id]["lainan_talk"].remove(ctx.channel.id) + self.bot.guild_settings[ctx.guild.id]["kana_talk"].remove(ctx.channel.id) e = discord.Embed( - title=f"`#{ctx.channel.name}`でのLainan APIの返信を無効にしました。", + title=f"`#{ctx.channel.name}`でのKanaAPIの返信を無効にしました。", description="", color=Success, ) return await ctx.reply(embed=e) - @ch_lainan_talk.command(name="activate", aliases=Activate_aliases) + @ch_kana_talk.command(name="activate", aliases=Activate_aliases) @commands.has_permissions(manage_channels=True) - async def activate_lainan_talk(self, ctx): - if ctx.channel.id not in self.bot.guild_settings[ctx.guild.id]["lainan_talk"]: - self.bot.guild_settings[ctx.guild.id]["lainan_talk"].append(ctx.channel.id) + async def activate_kana_talk(self, ctx): + if ctx.channel.id not in self.bot.guild_settings[ctx.guild.id]["kana_talk"]: + self.bot.guild_settings[ctx.guild.id]["kana_talk"].append(ctx.channel.id) e = discord.Embed( - title=f"`#{ctx.channel.name}`でのLainan APIの返信を有効にしました。", + title=f"`#{ctx.channel.name}`でのKanaAPIの返信を有効にしました。", description="", color=Success, ) diff --git a/cogs/cog.py b/cogs/cog.py index 5401fd9..6921b85 100644 --- a/cogs/cog.py +++ b/cogs/cog.py @@ -76,7 +76,7 @@ "tic_tac_toe", "parse", "image", - "lainan_talk", + "kana_talk", "sudden_death", "loop_trans", "reencode", diff --git a/cogs/fun.py b/cogs/fun.py index 4df22e9..5789afb 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -20,6 +20,7 @@ import _pathmagic # type: ignore # noqa: F401 from common_resources.consts import Error, Gaming, Info, Official_discord_id, Success +from common_resources.tokens import kana_user_id, kana_user_password from common_resources.tools import chrsize_len, flatten Bignum_join = {} @@ -124,8 +125,8 @@ def rgb_tuple(i): Mention_re = re.compile(r"<@\!?(\d+?)>") -LAINAN_QUEUE = [] -lainan_doing = False +KANA_QUEUE = [] +kana_doing = False BRACKET_BASE = "()[]{}()「」[]【】《》「」『』〈〉{}〔〕〘〙〚〛" BRACKET_DICT = {BRACKET_BASE[i * 2]: BRACKET_BASE[i * 2 + 1] for i in range(len(BRACKET_BASE) // 2)} @@ -142,45 +143,53 @@ def __init__(self, _bot): Number_emojis = _bot.consts["ne"] @commands.Cog.listener("on_message") - async def on_message_lainan(self, message): - global lainan_doing + async def on_message_kana(self, message): + global kana_doing if message.author.bot: return - elif message.channel.id not in self.bot.guild_settings[message.guild.id]["lainan_talk"]: + elif message.channel.id not in self.bot.guild_settings[message.guild.id]["kana_talk"]: return elif is_command(message): return - elif "lainan" not in message.content.lower(): + elif "kana" not in message.content.lower(): return - wh = discord.utils.get((await message.channel.webhooks()), name="sevenbot-lainan") + wh = discord.utils.get((await message.channel.webhooks()), name="sevenbot-kana") if wh is None: wh = await message.channel.create_webhook( - name="sevenbot-lainan", - avatar=(await self.bot.oemojis["lainan"].url_as().read()), + name="sevenbot-kana", + avatar=(await self.bot.oemojis["kana"].url_as().read()), ) - LAINAN_QUEUE.append([wh, message.content]) - if not lainan_doing: - lainan_doing = True + KANA_QUEUE.append([wh, message.content]) + if not kana_doing: + kana_doing = True try: async with aiohttp.ClientSession() as s: - while LAINAN_QUEUE: - cr = LAINAN_QUEUE[0] - async with s.get("https://api.lainan.one/?msg=" + urllib.parse.quote(cr[1])) as r: + while KANA_QUEUE: + cr = KANA_QUEUE[0] + async with s.post("https://kana.renorari.net/api/v2chat", data={ + "message": cr[1], + "user": { + "id": kana_user_id, + "password": kana_user_password + }, + "character_name": "discord", + "custom_character": "" + }) as r: if r.status != 200: return data = await r.json() await cr[0].send( - data["reaction"], - username="Lainan", + data["message"], + username="Kana", allowed_mentions=discord.AllowedMentions.none(), ) - LAINAN_QUEUE.pop(0) + KANA_QUEUE.pop(0) await asyncio.sleep(1) except Exception as e: - lainan_doing = False + kana_doing = False raise e - lainan_doing = False + kana_doing = False @commands.Cog.listener() async def on_raw_reaction_add(self, pl): @@ -412,7 +421,6 @@ async def single_wait(e, user): if pl.emoji.name == "check5": if user.mention == Wolf_join[message.id][0]: if len(Wolf_join[message.id]) >= 6: - e = discord.Embed( title=get_txt(guild.id, "ww")["title"] + " - " + get_txt(guild.id, "ww")["ready"], description=get_txt(guild.id, "ww")["ready_desc"].format(len(Wolf_join[message.id])) @@ -530,7 +538,6 @@ def check(reaction, user): elif reaction.emoji != self.bot.oemojis["skip"]: loop.create_task(reaction.message.remove_reaction(reaction.emoji, user)) if reaction.emoji.name == "info": - loop.create_task(user.send(embed=rce)) return False return reaction.count == len(wolf_members) + 1 @@ -1125,7 +1132,6 @@ async def tic_tac_toe(self, ctx, target: discord.Member): Circle_width = 16 for i, f in enumerate(fields): if fields[i] == 0: - w, h = text_draw.textsize(str(i + 1), fnt) text_draw.text( ( @@ -1418,7 +1424,6 @@ async def _image_github(self, ctx, *, base=None): Color = tuple(map(lambda x: math.floor(x * 256), list(Color))) for i in range(15): if int(Base_hashed[i], 16) % 2 == 0: - draw.rectangle( ( ( @@ -1591,10 +1596,10 @@ async def _image_switch(self, ctx): await ctx.reply(embed=e) await ctx.message.delete() - @commands.command(aliases=["lainan", "ltalk"]) - async def lainan_talk(self, ctx, *, text): + @commands.command(aliases=["kana", "ltalk"]) + async def kana_talk(self, ctx, *, text): async with aiohttp.ClientSession() as s: - async with s.get("https://api.lainan.one/?msg=" + urllib.parse.quote(text)) as r: + async with s.get("https://api.kana.renorari.net/api/?msg=" + urllib.parse.quote(text)) as r: if r.status != 200: return data = await r.json() diff --git a/cogs/level.py b/cogs/level.py index 0978a84..e4bdf16 100644 --- a/cogs/level.py +++ b/cogs/level.py @@ -40,7 +40,7 @@ async def on_message_level(self, message): return if ( message.author.bot - # or message.channel.id in self.bot.guild_settings[message.guild.id]["lainan_talk"] + # or message.channel.id in self.bot.guild_settings[message.guild.id]["kana_talk"] ): return if message.guild is None: diff --git a/common_resources/settings.py b/common_resources/settings.py index a6e0c1e..6fba58e 100644 --- a/common_resources/settings.py +++ b/common_resources/settings.py @@ -121,7 +121,7 @@ def get_key_type(k, v): "timezone": 0, "archive_category": 0, "ww_role": {"alive": None, "dead": None}, - "lainan_talk": [], + "kana_talk": [], "auth_channel": { "type": None, "channel": 0, diff --git a/common_resources/tokens.py.sample b/common_resources/tokens.py.sample index cd944a1..04f9c3c 100644 --- a/common_resources/tokens.py.sample +++ b/common_resources/tokens.py.sample @@ -12,3 +12,5 @@ botdd_token = "botdd token here" web_pass = "web password here" sentry_url = "sentry url here" emergency = False +kana_user_id = "kana user id here" +kana_user_password = "kana user password here" \ No newline at end of file diff --git a/translations/en/main.json b/translations/en/main.json index 0924c5b..f07334e 100644 --- a/translations/en/main.json +++ b/translations/en/main.json @@ -728,10 +728,10 @@ "channel_settings auto_parse": "自動パースについての設定です。", "channel_settings auto_parse activate": "自動パースを有効にします。", "channel_settings auto_parse deactivate": "自動パースを無効にします。", - "channel_settings lainan_talk": "[Lainan API](https://lainan.one/)の返信についての設定です。", - "channel_settings lainan_talk activate": "[Lainan API](https://lainan.one/)の返信を有効にします。", - "channel_settings lainan_talk deactivate": "[Lainan API](https://lainan.one/)の返信を無効にします。", - "lainan_talk": "[Lainan API](https://lainan.one/) を使って会話します\n文章: 会話する文章(文字列)", + "channel_settings kana_talk": "[KanaAPI](https://kana.renorari.net/api/)の返信についての設定です。", + "channel_settings kana_talk activate": "[KanaAPI](https://kana.renorari.net/api/)の返信を有効にします。", + "channel_settings kana_talk deactivate": "[KanaAPI](https://kana.renorari.net/api/)の返信を無効にします。", + "kana_talk": "[KanaAPI](https://kana.renorari.net/api/) を使って会話します\n文章: 会話する文章(文字列)", "level_settings": "レベルシステムの設定コマンドです。", "role_link": "ロールリンク関連のコマンドです。", "role_link add": "ロールリンクを追加します。\nロール: このサーバーのリンクしたいロール(ロール)\nサーバー: リンクしたいサーバー(ID-サーバー)\nロール2: 他サーバーのリンクしたいロール(ID-ロール)", diff --git a/translations/ja/main.json b/translations/ja/main.json index 700109b..5658f9d 100644 --- a/translations/ja/main.json +++ b/translations/ja/main.json @@ -680,10 +680,10 @@ "channel_settings auto_parse": "自動パースについての設定です。", "channel_settings auto_parse activate": "自動パースを有効にします。", "channel_settings auto_parse deactivate": "自動パースを無効にします。", - "channel_settings lainan_talk": "[Lainan API](https://lainan.one/)の返信についての設定です。", - "channel_settings lainan_talk activate": "[Lainan API](https://lainan.one/)の返信を有効にします。", - "channel_settings lainan_talk deactivate": "[Lainan API](https://lainan.one/)の返信を無効にします。", - "lainan_talk": "[Lainan API](https://lainan.one/) を使って会話します\n文章: 会話する文章(文字列)", + "channel_settings kana_talk": "[KanaAPI](https://kana.renorari.net/api/)の返信についての設定です。", + "channel_settings kana_talk activate": "[KanaAPI](https://kana.renorari.net/api/)の返信を有効にします。", + "channel_settings kana_talk deactivate": "[KanaAPI](https://kana.renorari.net/api/)の返信を無効にします。", + "kana_talk": "[KanaAPI](https://kana.renorari.net/api/) を使って会話します\n文章: 会話する文章(文字列)", "level_settings": "レベルシステムの設定コマンドです。", "role_link": "ロールリンク関連のコマンドです。", "role_link add": "ロールリンクを追加します。\nロール: このサーバーのリンクしたいロール(ロール)\nサーバー: リンクしたいサーバー(ID-サーバー)\nロール2: 他サーバーのリンクしたいロール(ID-ロール)", From fc4de3b454a5f91d178b1e1d85b9f171c41bdaea Mon Sep 17 00:00:00 2001 From: renorari Date: Thu, 28 Sep 2023 08:29:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20KanaAPI=E3=81=AEURL=E3=81=AE?= =?UTF-8?q?=E9=96=93=E9=81=95=E3=81=84=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/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/fun.py b/cogs/fun.py index 5789afb..e580d75 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -1599,7 +1599,7 @@ async def _image_switch(self, ctx): @commands.command(aliases=["kana", "ltalk"]) async def kana_talk(self, ctx, *, text): async with aiohttp.ClientSession() as s: - async with s.get("https://api.kana.renorari.net/api/?msg=" + urllib.parse.quote(text)) as r: + async with s.get("https://kana.renorari.net/api/?msg=" + urllib.parse.quote(text)) as r: if r.status != 200: return data = await r.json()