Repository navigation
Bot Recipes
Make one Client per token and keep it around, don't build a new one for every message. The login, the account
list and the cache get reused that way. login_file keeps the login across restarts too.
clients: dict[int, akef.Client] = {}
def client_for(user_id: int, token: str) -> akef.Client:
if user_id not in clients:
clients[user_id] = akef.Client(token, login_file=f"logins/{user_id}.json")
return clients[user_id]Close them when the bot shuts down: await client.close().
Tokens are full logins. If your bot stores them, store them like passwords, and only ever ask for them in DMs.
@tree.command(description="your sanity")
async def sanity(interaction: discord.Interaction):
client = clients.get(interaction.user.id)
if client is None:
return await interaction.response.send_message("link your token first", ephemeral=True)
try:
card = await client.card()
except akef.AuthError:
return await interaction.response.send_message("your token expired, send a new one", ephemeral=True)
s = card.stamina
await interaction.response.send_message(f"sanity {s.current}/{s.max}")async def check_in_everyone():
for user_id, client in clients.items():
try:
await client.check_in()
except akef.AlreadyCheckedIn:
pass
except akef.AuthError:
... # tell that user to send a new token
except akef.NetworkError:
... # try again laterRun it once a day with whatever scheduler your bot uses, discord.ext.tasks.loop(time=...) in discord.py or a job
queue in python-telegram-bot / aiogram.
akef-cards draws the same data as images, and has full discord.py and Telegram bot examples in its docs.
The snippets here aren't a whole bot, plug them into yours.
akef · MIT · not affiliated with Hypergryph or Gryphline
akef
- 🏠 Home
- 🚀 Getting Started
- 🎲 Pull History
- 📅 Daily Check-in
- 🧮 Enka and Final Stats
- 🤖 Bot Recipes
- ⚡ Caching and Logins
- ❓ FAQ
📖 Docs site
📦 PyPI
💻 Repo
🃏 akef-cards