poshbotio / PoshBot

Powershell-based bot framework
MIT License
536 stars 108 forks source link

Is there a variable for the user that initiated the command? #218

Closed kmickeletto closed 3 years ago

kmickeletto commented 3 years ago

Example, user executes whoami command. How can the function lookup who actually executed the command?

Expected Behavior

If user executed custom whoami command, there would be a variable or lookup function to determine who executed the command.

Current Behavior

I am not sure

Possible Solution

Variable or lookup function

devblackops commented 3 years ago

@kmickeletto Yes, when the command is executed, PoshBot populates a variable called $global:PoshBotContext. In that, you'll find properties like the ID and name of the user who executed the command, the channel ID and name, the raw message PoshBot received, and other info.

Here is a demo command dump the variable contents back to the the backend: https://github.com/poshbotio/PoshBot.Demo/blob/master/PoshBot.Demo/PoshBot.Demo.psm1#L421

Here is the code showing how PoshBot populates it. https://github.com/poshbotio/PoshBot/blob/c385b9902497856e95527e524ab1d997037998dd/PoshBot/Classes/Command.ps1#L87-L101

kmickeletto commented 3 years ago

Thanks so much! Works like a charm!