Skip to content

Commit

Permalink
進数変換コマンド実装v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Syunngiku0402 committed Nov 18, 2024
1 parent cc3a611 commit 7d9b5c0
Showing 1 changed file with 65 additions and 6 deletions.
71 changes: 65 additions & 6 deletions cogs/cradix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@
import discord
from discord import app_commands
import numpy as np
from typing import Optional


class CRadix(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot

@app_commands.command(name="cradix", description="入力した数値を2~16進数に変換します")
@app_commands.describe(num="進数変換したい数字を入れてください")
async def cradix(self, interaction: discord.Interaction, num: int):
@app_commands.describe(num="進数変換したい数字を入れてください", mode="モードを選択してください(任意)")
@app_commands.choices(
mode=[
app_commands.Choice(name="2・4・8・10・16のみ表示します", value="cradix1"),
app_commands.Choice(name="2~16進数を表示させます", value="cradix2"),
app_commands.Choice(name="2~36進数を表示させます(17進数以降は自分のみの表示)", value="cradix3"),
]
)
async def cradix(self, interaction: discord.Interaction, num: int, mode: Optional[str] = None):
absnum = abs(num)
DESCRIPTION = f"""
DESCRIPTION1 = f"""
```
|入力値| = {absnum}
2進数 : {np.base_repr(absnum, 2)}
4進数 : {np.base_repr(absnum, 4)}
8進数 : {np.base_repr(absnum, 8)}
10進数 : {np.base_repr(absnum, 10)}
16進数 : {np.base_repr(absnum, 16)}
```
"""
DESCRIPTION2 = f"""
```
|入力値| = {absnum}
2進数 : {np.base_repr(absnum, 2)}
Expand All @@ -32,12 +50,53 @@ async def cradix(self, interaction: discord.Interaction, num: int):
16進数 : {np.base_repr(absnum, 16)}
```
"""
radix_embed = discord.Embed(
DESCRIPTION3 = f"""
```
|入力値| = {absnum}
17進数 : {np.base_repr(absnum, 17)}
18進数 : {np.base_repr(absnum, 18)}
19進数 : {np.base_repr(absnum, 19)}
20進数 : {np.base_repr(absnum, 20)}
21進数 : {np.base_repr(absnum, 21)}
22進数 : {np.base_repr(absnum, 22)}
23進数 : {np.base_repr(absnum, 23)}
24進数 : {np.base_repr(absnum, 24)}
25進数 : {np.base_repr(absnum, 25)}
26進数 : {np.base_repr(absnum, 26)}
27進数 : {np.base_repr(absnum, 27)}
28進数 : {np.base_repr(absnum, 28)}
29進数 : {np.base_repr(absnum, 29)}
30進数 : {np.base_repr(absnum, 30)}
30進数 : {np.base_repr(absnum, 31)}
30進数 : {np.base_repr(absnum, 32)}
30進数 : {np.base_repr(absnum, 33)}
30進数 : {np.base_repr(absnum, 34)}
30進数 : {np.base_repr(absnum, 35)}
30進数 : {np.base_repr(absnum, 36)}
```
"""
radix_embed1 = discord.Embed(
title="進数変換",
description=DESCRIPTION1,
color=0x58619A
)
radix_embed2 = discord.Embed(
title="進数変換",
description=DESCRIPTION2,
color=0x58619A
)
radix_embed3 = discord.Embed(
title="進数変換",
description=DESCRIPTION,
description=DESCRIPTION3,
color=0x58619A
)
await interaction.response.send_message(embed=radix_embed)
if mode == "cradix2":
await interaction.response.send_message(embed=radix_embed2)
elif mode == "cradix3":
await interaction.channel.send(embed=radix_embed2)
await interaction.response.send_message(embed=radix_embed3, ephemeral=True)
else:
await interaction.response.send_message(embed=radix_embed1)


async def setup(bot: commands.Bot):
Expand Down

0 comments on commit 7d9b5c0

Please sign in to comment.