diff --git a/cogs/afk.py b/cogs/afk.py new file mode 100644 index 0000000..d5103ff --- /dev/null +++ b/cogs/afk.py @@ -0,0 +1,48 @@ +from discord.ext import commands +from discord import app_commands +from replit import db +import discord + + +def afk_set_db(key, data): + db[f"afk_{key}"] = data + + +def afk_get(key): + return db[f"afk_{key}"] + + +class afk(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.describe(reason="afkになる理由") + @app_commands.command(name="afk_set", description="afkをセット又は解除します。") + async def afks(self, i: discord.Interaction, reason: str): + try: + afk_set_db(int(i.user.id), reason) + await i.response.send_message("afkをセットしました!") + except: + await i.response.send_message("afkをセットできませんでした。", ephemeral=True) + + @app_commands.command(name="afk_kaizyo", description="afkを解除します") + async def afkk(self, i: discord.Interaction): + try: + afk_set_db(int(i.user.id), False) + await i.response.send_message("afkを解除しました!") + except: + await i.response.send_message("afkを解除できませんでした。", ephemeral=True) + + @commands.Cog.listener(name='on_message') + async def afk_msg(self, message: discord.Message): + try: + if message.mentions: + for d in message.mentions: + if afk_get[int(d.id)]: + await message.channel.send("このユーザーはafkです。(こののメッセージは10秒後に削除されます。)", delete_after=10) + except: + pass + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(afk(bot)) diff --git a/cogs/ban_member.py b/cogs/ban_member.py new file mode 100644 index 0000000..9952f20 --- /dev/null +++ b/cogs/ban_member.py @@ -0,0 +1,29 @@ +from discord.ext import commands +from discord import app_commands +import discord + + +class ban_member(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.command(name="ban_member", description="Banされたユーザー一覧を表示します。") + async def ban_members(self, i: discord.Interaction): + m = [] + try: + if i.guild.channels.permissions_for(i.user) == discord.Permissions.ban_members: + if i.guild.channels.permissions_for(i.guild.get_member(self.bot.user.id)) == discord.Permissions.ban_members: + async for entry in i.guild.bans(limit=150): + m.append(f"{entry.user.name}, ") + send_content = "".join(m) + await i.response.send_message(send_content) + else: + await i.response.send_message("データを取得できませんでした(Botの権限がないなどの原因で)", 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(ban_member(bot)) diff --git a/cogs/bot_invite.py b/cogs/bot_invite.py new file mode 100644 index 0000000..a70b5e8 --- /dev/null +++ b/cogs/bot_invite.py @@ -0,0 +1,75 @@ +from discord.ext import commands +from discord import app_commands +import discord +from replit import db + + +def db_set(key, data): + db[f"bot_invite_db_id_{key}"] = data + + +def db_get(key): + return db[f"bot_invite_db_id_{key}"] + + +class MyView(discord.ui.View): + @discord.ui.select( + placeholder="招待するBotの権限を選択して下さい", + min_values=1, + max_values=1, + options=[ + discord.SelectOption( + label="管理者", + description="全ての権限を有効にしたURLを生成します。", + value="admin", + ), + discord.SelectOption( + label="権限選択式", + description="全ての権限を選択式にしたURLを生成します。", + value="all" + ), + discord.SelectOption( + label="権限なし", + description="全ての権限をなしにしたURLを生成します。", + value="none" + ), + + ] + ) + async def select_callback(self, select, i): + bot_id = db_get(i.message.id) + d = select.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))})") + 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()))})") + elif d == "none": + await i.response.edit_message(f"セレクトメニューをクリックして選択してください\n[Botを招待]({discord.utils.oauth_url(int(bot_id))})") + else: + await i.response.edit_message("セレクトメニューをクリックして選択してください\n不明なパラメーターが選択されました。") + + +class bot_invite(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.describe(bot="招待するBot") + @app_commands.command(name="bot_invite", description="Botの招待リンクを生成します。") + async def botinvite(self, i: discord.Interaction, bot: discord.User = None): + if bot: + if bot.bot: + await i.response.send_message("セレクトメニューをクリックして選択してください") + msg = await self.bot.get_channel(i.channel.id).send(view=MyView()) + db_set(int(msg.id), int(bot.id)) + self.bot.add_view(MyView(), message_id=msg.id) + else: + await i.response.send_message("指定したものはBotではありません。") + 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)) + self.bot.add_view(MyView(), message_id=msg.id) + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(bot_invite(bot)) diff --git a/cogs/help.py b/cogs/help.py index 4d82a15..fdb994b 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -2,7 +2,7 @@ from discord.ext import commands import Paginator from discord import app_commands -a = "Tips: `/help コマンド名`か、`eg!help コマンド名`でコマンドを検索できます。" +a = "Tips: `/help コマンド名`でコマンドを検索できます。" class Help(commands.Cog): diff --git a/cogs/ping.py b/cogs/ping.py new file mode 100644 index 0000000..8ff118c --- /dev/null +++ b/cogs/ping.py @@ -0,0 +1,16 @@ +from discord.ext import commands +from discord import app_commands +import discord + + +class ping(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.command(name="ping", description="ping値を測定します。") + async def pingpong(self, i: discord.Interaction): + await i.response.send_message(f'{round(self.bot.latency * 1000)}ms') + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(ping(bot)) diff --git a/cogs/role_all.py b/cogs/role_all.py new file mode 100644 index 0000000..f215fd1 --- /dev/null +++ b/cogs/role_all.py @@ -0,0 +1,48 @@ +from discord.ext import commands +from discord import app_commands +import discord +import enum + + +class bot(enum.Enum): + はい = True + いいえ = False + + +class roleall(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.describe(bot='Botにもロールを付与する?') + @app_commands.choices(bot=[ + app_commands.Choice(name='はい', value=True), + app_commands.Choice(name='いいえ', value=False), + ]) + @app_commands.command(name="role_all_add", description="全メンバーにロールを付与します。") + async def roleall_add(self, i: discord.Interaction, role: discord.Role, bot: bool): + if bot: + for member in i.guild.members: + await member.add_roles(role) + elif not bot: + for member in i.guild.members: + if not member.bot: + await member.add_roles(role) + + @app_commands.describe(bot='Botのロールも除去する?') + @app_commands.choices(bot=[ + app_commands.Choice(name='はい', value=True), + app_commands.Choice(name='いいえ', value=False), + ]) + @app_commands.command(name="role_all_remove", description="全員からロールを除去します。") + async def roleall_remove(self, i: discord.Interaction, role: discord.Role, bot: bool): + if bot: + for member in i.guild.members: + await member.remove_roles(role) + elif not bot: + for member in i.guild.members: + if not member.bot: + await member.remove_roles(role) + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(roleall(bot)) diff --git a/cogs/role_list.py b/cogs/role_list.py new file mode 100644 index 0000000..4e42275 --- /dev/null +++ b/cogs/role_list.py @@ -0,0 +1,22 @@ +from discord.ext import commands +from discord import app_commands +import discord + + +class role_list(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.command(name="role_list", description="ロールのリストを送信します。") + async def rolelists(self, i: discord.Interaction): + guild = i.guild + if len(guild.roles) > 1: + role = '\n'.join([r.mention for r in guild.roles][1:]) + embed = discord.Embed(title="ロール一覧", description=f"{role}") + await i.response.send_message(embed=embed) + else: + await i.response.send_message('ロールが見つかりませんでした。') + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(role_list(bot)) diff --git a/cogs/trans.py b/cogs/trans.py new file mode 100644 index 0000000..79abb3d --- /dev/null +++ b/cogs/trans.py @@ -0,0 +1,42 @@ +from discord.ext import commands +from discord import app_commands +import discord +import async_google_trans_new + + +class trans_kinou(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.describe(text='翻訳するテキスト', lang="翻訳をする言語") + @app_commands.choices(lang=[ + app_commands.Choice(name='アルメニア語', value='hy'), + app_commands.Choice(name='中国語(簡体)', value='zh'), + app_commands.Choice(name='オランダ語', value='nl'), + app_commands.Choice(name='英語', value='en'), + app_commands.Choice(name='エスペラント語', value='eo'), + app_commands.Choice(name='フランス語', value='fr'), + app_commands.Choice(name='グルジア語', value='ka'), + app_commands.Choice(name='ドイツ語', value='de'), + app_commands.Choice(name='ギリシャ語', value='el'), + app_commands.Choice(name='イタリア語', value='it'), + app_commands.Choice(name='日本語', value='ja'), + app_commands.Choice(name='韓国語', value='ko'), + app_commands.Choice(name='クルド語', value='ku'), + app_commands.Choice(name='ペルシャ語', value='fa'), + app_commands.Choice(name='ポーランド語', value='pl'), + app_commands.Choice(name='ポルトガル語(ポルトガル、ブラジル)', value='pt'), + app_commands.Choice(name='ルーマニア語', value='ro'), + app_commands.Choice(name='スペイン語', value='es'), + app_commands.Choice(name='スウェーデン語', value='sv'), + app_commands.Choice(name='トルコ語', value='tr'), + app_commands.Choice(name='ウルドゥー語', value='ur'), + ]) + @app_commands.command(name="google_trans", description="Google翻訳をします。") + async def trans_cmd(self, i: discord.Interaction, lang: str, text: str): + g = async_google_trans_new.AsyncTranslator() + await i.response.send_message(content=await g.translate(text, lang)) + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(trans_kinou(bot)) diff --git a/cogs/uptime.py b/cogs/uptime.py new file mode 100644 index 0000000..78d34c5 --- /dev/null +++ b/cogs/uptime.py @@ -0,0 +1,16 @@ +from discord.ext import commands +from discord import app_commands +import discord + + +class uptime(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.command(name="up_time", description="Botの起動時間を送信します。") + async def uptime(self, i: discord.Interaction): + await i.response.send_message(f'') + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(uptime(bot)) diff --git a/cogs/userinfo.py b/cogs/userinfo.py index 1ae9eaf..00b9f6d 100644 --- a/cogs/userinfo.py +++ b/cogs/userinfo.py @@ -8,6 +8,7 @@ class Userinfo(commands.Cog): def __init__(self, bot: commands.Bot) -> None: self.bot: commands.Bot = bot + @app_commands.describe(user="ユーザー") @app_commands.command(name="userinfo", description="指定したユーザーの情報を返します。") async def userinfo( self, diff --git a/cogs/verify.py b/cogs/verify.py index 476892e..2597236 100644 --- a/cogs/verify.py +++ b/cogs/verify.py @@ -25,6 +25,17 @@ class verify(commands.Cog): def __init__(self, bot: commands.Bot) -> None: self.bot: commands.Bot = bot + @commands.Cog.listener(name='on_interaction') + async def verify_interaction_callback(self, i: discord.Interaction): + if i.data.get('custom_id') == "verify_type_1": + data = verify_db_get(int(i.message.id)) + await i.guild.get_member(i.user.id).add_roles( + i.guild.get_role(int(data["role_id"])) + ) + await i.response.send_message("ロールを付与しました。", ephemeral=True) + else: + return + @app_commands.describe(name="パネルの名前", description="パネルの説明", role="付与するロール") @app_commands.command( name="verify", diff --git a/cogs/verify_callback.py b/cogs/verify_callback.py deleted file mode 100644 index 6d6bbf3..0000000 --- a/cogs/verify_callback.py +++ /dev/null @@ -1,31 +0,0 @@ -import discord -from discord.ext import commands -import json -from replit import db - - -def verify_db_get(key): - return db[f"verify_1_db_{key}"] - - -class Verify_interaction(commands.Cog): - def __init__(self, bot: commands.Bot) -> None: - self.bot: commands.Bot = bot - - @commands.Cog.listener() - async def on_interaction(self, i: discord.Interaction): - try: - get = json.dumps(i.data) - json_get = json.loads(get) - if json_get["custom_id"] == "verify_type_1": - data = verify_db_get(int(i.message.id)) - await i.guild.get_member(i.user.id).add_roles( - i.guild.get_role(int(data["role_id"])) - ) - await i.response.send_message("ロールを付与しました。", ephemeral=True) - except KeyError: - pass - - -async def setup(bot: commands.Bot) -> None: - await bot.add_cog(Verify_interaction(bot)) diff --git a/cogs/voicetext.py b/cogs/voicetext.py new file mode 100644 index 0000000..c88b8bb --- /dev/null +++ b/cogs/voicetext.py @@ -0,0 +1,31 @@ +from discord.ext import commands +from discord import app_commands +import discord +import string +import random +import requests +# Todo: aiohttpを使うようにする + + +def voicesave(text): + url = f"https://www.google.com/speech-api/v1/synthesize?text={text}&nc=mpeg&lang=ja&speed=0.5&client=lr-language-tts" + randomstring = "".join(random.choices(string.ascii_letters + string.digits, k=10)) + name = "../voice/" + randomstring + ".mp3" + response = requests.get(url, timeout=100) + with open(name, "wb") as file: + file.write(response.content) + + +class voice_text(commands.Cog): + def __init__(self, bot: commands.Bot) -> None: + self.bot: commands.Bot = bot + + @app_commands.describe(text="喋らせるテキスト") + @app_commands.command(name="voice_text", description="googleの声が出力できます。") + async def voice(self, i: discord.Interaction, text: str): + save = voicesave(text) + await i.response.send_message(file=discord.File(save)) + + +async def setup(bot: commands.Bot) -> None: + await bot.add_cog(voice_text(bot)) diff --git a/main.py b/main.py index 8dcbb00..25dae65 100644 --- a/main.py +++ b/main.py @@ -11,10 +11,12 @@ from discord.ext import commands, tasks from os import listdir, getenv from webserver import keep_alive +from datetime import datetime class EightBot(commands.Bot): async def setup_hook(self): + self.kidou = 0 await keep_alive() for name in listdir("cogs"): if not name.startswith(("_", ".")): @@ -27,7 +29,7 @@ async def setup_hook(self): bot = EightBot( command_prefix="eg!", - intents=Intents.all(), + intents=Intents(auto_moderation=False, typing=False), activity=Activity( type=ActivityType.watching, name="起動準備をしています...", @@ -50,6 +52,7 @@ async def status_swap(cycle_d): @bot.listen(name="on_ready") async def bot_ready(): + bot.kidou = int(datetime.now().timestamp()) print("login.") await status_swap.start( cycle( diff --git a/voice/voice.mp3 b/voice/voice.mp3 new file mode 100644 index 0000000..e69de29