or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/py-cord@2.6.x
tile.json

tessl/pypi-py-cord

tessl install tessl/pypi-py-cord@2.6.0

A modern, async-ready Python API wrapper for Discord with comprehensive bot development features

Agent Success

Agent success rate when using this tile

93%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.11x

Baseline

Agent success rate without this tile

84%

task.mdevals/scenario-8/

Discord Bot Utility Helper

Build a utility module for a Discord bot that provides helper functions for common operations involving Discord IDs, timestamps, and user mentions.

Capabilities

Snowflake ID Analysis

Extract timestamp information from Discord snowflake IDs.

  • Given snowflake ID 175928847299117063, return a datetime object representing 2016-04-30 11:18:25.796 UTC @test
  • Given snowflake ID 1234567890123456789, correctly extract and return its creation timestamp as a datetime @test

Safe Message Formatting

Clean user input to prevent markdown injection and unintended mentions.

  • Given text **Hello** _world_, return \\*\\*Hello\\*\\* \\_world\\_ (escaped markdown) @test
  • Given text @everyone look at this!, return text that won't trigger the everyone mention @test

Timestamp Formatting

Format datetime objects as Discord timestamps with different display styles.

  • Given datetime 2024-01-15 10:30:00 UTC with short time style, return <t:1705314600:t> @test
  • Given datetime 2024-01-15 10:30:00 UTC with relative style, return <t:1705314600:R> @test

Smart Resource Fetching

Implement efficient resource fetching that checks cache before making API calls.

  • When fetching a user that exists in cache, return the cached user without making an API call @test
  • When fetching a user not in cache, make API call and return the fetched user @test

Implementation

@generates

API

from datetime import datetime
from typing import Optional
import discord

def extract_id_timestamp(snowflake_id: int) -> datetime:
    """
    Convert a Discord snowflake ID to a datetime object.

    Args:
        snowflake_id: The Discord snowflake ID

    Returns:
        A datetime object representing when the ID was created
    """
    pass

def sanitize_markdown(text: str) -> str:
    """
    Escape markdown formatting characters in text.

    Args:
        text: The text to escape

    Returns:
        Text with markdown characters escaped
    """
    pass

def sanitize_mentions(text: str) -> str:
    """
    Escape user, role, and everyone/here mentions in text.

    Args:
        text: The text to escape

    Returns:
        Text with mentions escaped to prevent pinging
    """
    pass

def create_discord_timestamp(dt: datetime, style: str = "f") -> str:
    """
    Format a datetime as a Discord timestamp string.

    Args:
        dt: The datetime to format
        style: Display style - 't' (short time), 'T' (long time),
               'd' (short date), 'D' (long date),
               'f' (short datetime), 'F' (long datetime),
               'R' (relative)

    Returns:
        Discord timestamp string like <t:1234567890:R>
    """
    pass

async def fetch_user_smart(bot: discord.Bot, user_id: int) -> Optional[discord.User]:
    """
    Get a user from cache or fetch from API if not cached.

    Args:
        bot: The Discord bot instance
        user_id: The user ID to fetch

    Returns:
        The User object, or None if not found
    """
    pass

Dependencies { .dependencies }

py-cord { .dependency }

Provides Discord API wrapper functionality for bot operations and utility functions.

@satisfied-by