Created
June 1, 2019 04:54
-
-
Save chtzvt/0857f4b9bc57cbb84473ebb60fe1cc67 to your computer and use it in GitHub Desktop.
How to shut down an entire birthdaybot.io installation for the good of mankind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// step (1) register for the free premium trial | |
// step (2) create a new team using the participants list of one of the default channels | |
// step (3) run this script | |
package main | |
import ( | |
"fmt" | |
"github.com/nlopes/slack" | |
"time" | |
) | |
func main() { | |
token := "<legacy API token here>" | |
dmChanID := "<birthday bot's direct message channel ID here>" | |
targetDate := "<tomorrow's date here>" | |
wait := 2 * time.Second | |
api := slack.New(token) | |
users, err := api.GetUsers() | |
if err != nil { | |
fmt.Printf("getting users: %s\n", err) | |
return | |
} | |
params := slack.NewPostMessageParameters() | |
params.AsUser = true | |
params.LinkNames = 1 | |
params.EscapeText = false | |
for _, user := range users { | |
channelID, timestamp, err := api.PostMessage(dmChanID, slack.MsgOptionText(fmt.Sprintf("@%s birthday is on %s", user.Name, targetDate), false), slack.MsgOptionPostMessageParameters(params)) | |
if err != nil { | |
fmt.Printf("error setting birthday for user %s: %s\n", user.ID, err) | |
return | |
} | |
fmt.Printf("Message successfully sent to channel %s at %s: ID: %s, Name: %s\n", channelID, timestamp, user.ID, user.Name) | |
time.Sleep(wait) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment