shuppet / raku-api-discord

Raku module for interacting with the Discord API.
https://shuppet.com
BSD 3-Clause "New" or "Revised" License
30 stars 3 forks source link

Make debug output more orderly. #55

Closed gfldex closed 3 years ago

gfldex commented 3 years ago

see: https://gfldex.wordpress.com/2021/06/23/being-pragmat-ish/

gfldex commented 3 years ago

I would like to add that this is the first PR do help with logging. Having a lib/Discrod/Debug.rakumod is a precondition for things to follow.

gfldex commented 3 years ago

2nd part is now done. The user can divert output to $*ERR to a Supply and do some filtering via:

    use API::Discord::Debug;

    react whenever debug-say().merge(debug-print()) {
        when HEARTBEAT { $*ERR.print: $_ }
        when CONNECTION { note now.Datetime.Str, ' ', $_ }
        when /your term here/ { .&do-stuff() }
        default {}
    }

This allows to deal with error messages in the main react block. All symbols can be kept lexical to avoid collision with other modules. The raku-bot is using this now in the following fassion, which works nicely.

start react {
        whenever $discord.messages -> $message {
            next unless $channels ~~ $message.channel.name;

            $result.emit: [ $message.channel.&augment, $message.author.&augment, $message.content ];
        }
        # [...]
       {
                use API::Discord::Debug;

                whenever debug-say().merge(debug-print()) {
                        when HEARTBEAT { }
                        default { .note }
                }
        }
}
kawaii commented 3 years ago

Thanks for your contribution, I will try and get around to testing this either tomorrow or Monday and look to getting it merged during the week hopefully.