llimllib / limbo

A simple, clean, easy to modify Slack chatbot
MIT License
402 stars 160 forks source link

Add --botname feature to fetch user-name associated with SLACK_TOKEN #152

Closed rstata closed 6 years ago

rstata commented 6 years ago

When writing deployment scripts and other automation, it is useful to have a Limbo bot's user name as it appears in Slack. For example, in our AWS deployment scripts, we use this botname as the "service name" in Amazon's Elastic Container Service. The Slack API has an API endpoint (auth.test) that returns this user name (among other information). This pull request adds a flag to Limbo that calls this endpoint and then prints the resulting name (and then exits -- when --botname is used, Limbo does not enter its event loop).

eSoares commented 6 years ago

Can't you obtain the username via server.slack.server.username?

Also, instead of adding that feature on the Limbo itself, could this be made via a plugin on the instantiation? This doesn't seem to benefit Limbo it self in anything...

Edit: Example plugin:

#file:  limbo/plugins/print_username.py
def on_init(server):
    print(server.slack.server.username)
rstata commented 6 years ago

Can't you obtain the username via server.slack.username?

Yes I can, which simplifies the code! I've resubmitted the pull request with this simplification, thanks!

Instead of adding that feature on the Limbo itself, could this be made via a plugin on the instantiation?

The intent of the --botname feature is to be used in deployment-automation scripts. The only way to access a plugin in an automation script is to use the -c feature, which doesn't work for automation scripts because, for -c, Limbo uses FakeServer, i.e., it doesn't actually connect to Slack.