LTC Send Bot
Send Intentを使う外部LTC送金
ENV
.env.example
DISCORD_TOKEN=
DWALLET_API_KEY=
DWALLET_BASE_URL=https://dwallet-api.nikoroyal.com
TEXT
requirements.txt
discord.py>=2.5
dwsdk>=2.0.0
python-dotenv>=1.0
PYTHON
bot.py
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from dwallet import DWalletClient
load_dotenv()
TOKEN = os.environ["DISCORD_TOKEN"]
class SendModal(discord.ui.Modal, title="LTC外部送金"):
destination = discord.ui.TextInput(label="LTC送金先アドレス", max_length=120)
amount = discord.ui.TextInput(label="送金額 LTC", placeholder="0.01000000")
password = discord.ui.TextInput(
label="D-Walletパスワード",
style=discord.TextStyle.short,
required=True,
)
def __init__(self, bot):
super().__init__()
self.bot = bot
async def on_submit(self, interaction: discord.Interaction):
# Password is used only for this API request. Never log or persist it.
intent = await self.bot.dw.create_send_intent(
interaction.user.id,
password=str(self.password),
destination=str(self.destination).strip(),
unit="LTC",
amount=str(self.amount).strip(),
)
q = intent["quote"]
await interaction.response.send_message(
"送金Intentを作成しました。\n"
f"Intent ID: `{intent['intent_id']}`\n"
f"送金額: `{q['amount_ltc']} LTC`\n"
f"Network Fee: `{q['network_fee_ltc']} LTC`\n"
"最終実行はD-Wallet公式の確認フローで行われます。",
ephemeral=True,
)
class Bot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!", intents=discord.Intents.default())
self.dw = DWalletClient.from_env()
async def setup_hook(self):
await self.dw.__aenter__()
await self.tree.sync()
async def close(self):
await self.dw.close()
await super().close()
bot = Bot()
@bot.tree.command(name="ltc_send", description="D-Walletから外部LTCアドレスへ送金します")
async def ltc_send(interaction: discord.Interaction):
await interaction.response.send_modal(SendModal(bot))
bot.run(TOKEN)
