Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] LainanAPIからKanaAPIへ変更 #32

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cogs/autoreply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
24 changes: 12 additions & 12 deletions cogs/channel_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion cogs/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"tic_tac_toe",
"parse",
"image",
"lainan_talk",
"kana_talk",
"sudden_death",
"loop_trans",
"reencode",
Expand Down
59 changes: 32 additions & 27 deletions cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)}
Expand All @@ -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):
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
(
Expand Down Expand Up @@ -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(
(
(
Expand Down Expand Up @@ -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://kana.renorari.net/api/?msg=" + urllib.parse.quote(text)) as r:
if r.status != 200:
return
data = await r.json()
Expand Down
2 changes: 1 addition & 1 deletion cogs/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion common_resources/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions common_resources/tokens.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-ロール)",
Expand Down
8 changes: 4 additions & 4 deletions translations/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-ロール)",
Expand Down