Is there a variable for the user that initiated the command?
kmickeletto opened this issue · comments
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
@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.
PoshBot/PoshBot/Classes/Command.ps1
Lines 87 to 101 in c385b99
Thanks so much! Works like a charm!