cibere / kick.py

A python api wrapper for kick.com
MIT License
40 stars 5 forks source link

Added 'username' attribute to 'livestream' and 'author' classes #13

Closed Mister-SOSA closed 1 year ago

Mister-SOSA commented 1 year ago

Quality of life change for quickly pulling the actual username of a user.

For instance, in the use case of chat logging:

async def log_chat_message(msg):
    author = await msg.author.to_user()
    payload = {
        'sent_at': get_timestamp(),
        'author': author.username,
        'author_id': author.id,
        'content': msg.content,
        'message_id': msg.id,
    }

    client.table(CHAT_TABLE).insert(payload).execute()

There is no longer a need for the to_user() coroutine, as the author's username has now already been passed with msg.author

Another example:

async def run(client, msg, args):
    author = await msg.author.to_user()
    await msg.chatroom.send(f"@{author.username} Your balance is {await fetch_user_balance(kick_id=msg.author.id)} coins.")

In commands, you can omit the to_user() coroutine when quickly replying to a message. Performing .replace('-', '_') on msg.author.slug is also not preferred for the sake of prettier and more accurate user-facing usernames.