Esempio n. 1
0
File: game.go Progetto: errows/slick
func (g *Game) Launch() {
	g.GameCount++
	if g.GameCount > 100 {
		log.Println("Ran enough Faceoff games.. stopping this run until we're asked again")
		return
	}

	c := newChallenge()
	g.Challenges = append(g.Challenges, c)

	c.PickUsers(g.Faceoff.users)

	var profileURLs []string
	var lookedForUser slack.User
	for idx, userID := range c.UsersShown {
		u := g.Faceoff.bot.Users[userID]
		if u.ID == "" {
			log.Println("faceoff: error finding user with ID", userID)
			g.OriginalMessage.Reply("error finding user with ID %q", userID)
			return
		}

		profileURLs = append(profileURLs, u.Profile.Image192)
		if idx == c.RightAnswerIndex {
			lookedForUser = u
		}
	}

	pngContent, err := c.BuildImage(profileURLs)
	if err != nil {
		log.Println("error building faceoff image:", err)
		go func() {
			time.Sleep(100 * time.Millisecond)
			g.Launch()
		}()
		return
	}

	// Trigger a line with who we're looking for..
	// Add the reactions, slowly, in order..
	// Send the image, after a good second..
	prepared := g.OriginalMessage.Reply(fmt.Sprintf("---\nBe prepared! We're looking for *%s* in the next image:", lookedForUser.RealName))
	prepared.OnAck(func(ev *slack.AckMessage) {
		go func() {
			delay := 750 * time.Millisecond
			g.Faceoff.bot.Slack.AddReaction("one", slack.NewRefToMessage(prepared.Channel, ev.Timestamp))
			time.Sleep(delay)
			g.Faceoff.bot.Slack.AddReaction("two", slack.NewRefToMessage(prepared.Channel, ev.Timestamp))
			time.Sleep(delay)
			g.Faceoff.bot.Slack.AddReaction("three", slack.NewRefToMessage(prepared.Channel, ev.Timestamp))
			time.Sleep(delay)
			g.Faceoff.bot.Slack.AddReaction("four", slack.NewRefToMessage(prepared.Channel, ev.Timestamp))

			g.showChallenge(c, lookedForUser, pngContent, ev.Timestamp)
		}()
	})

}
Esempio n. 2
0
func (s *SlackLink) forwardSlackMessageToChatLink(msg *slack.MessageEvent, specialAcknowledgement bool) {
	if strings.HasPrefix(msg.Text, ".") {
		msg.Text = "/" + msg.Text[1:]
	}

	minecraftAccount := s.getMinecraftFromSlack(msg.User)
	if minecraftAccount == nil {
		// They aren't associated with an account. Ignore.
		return
	}

	muuid, _ := uuid.NewRandom()

	cmi := &ChatMessageIn{
		Server:  "Slack",
		Context: muuid,
		Type:    messages.MessageType_TEXT,

		From: minecraftAccount,

		Timestamp: parseSlackTimestamp(msg.Timestamp),

		Contents: msg.Text,
	}

	s.addContextAssociation(cmi.Context, msg.Channel)
	if specialAcknowledgement {
		cleanedMessage := cmi.Contents
		if strings.HasPrefix(cleanedMessage, "#") {
			cleanedMessage = cleanedMessage[1:]
		}

		ref := slack.NewRefToMessage(msg.Channel, msg.Timestamp)
		s.addSpecialAcknowledgementContext(cmi.Context, &ref, cleanedMessage)
	}

	s.chatLinkOut <- CMIToProtoCMI(cmi)
}
Esempio n. 3
0
File: pins.go Progetto: ffrree/slack
/*
   WARNING: This example is destructive in the sense that it create a channel called testpinning
*/
func main() {
	var (
		apiToken string
		debug    bool
	)

	flag.StringVar(&apiToken, "token", "YOUR_TOKEN_HERE", "Your Slack API Token")
	flag.BoolVar(&debug, "debug", false, "Show JSON output")
	flag.Parse()

	api := slack.New(apiToken)
	if debug {
		api.SetDebug(true)
	}

	var (
		postAsUserName  string
		postAsUserID    string
		postToChannelID string
	)

	// Find the user to post as.
	authTest, err := api.AuthTest()
	if err != nil {
		fmt.Printf("Error getting channels: %s\n", err)
		return
	}

	channelName := "testpinning"

	// Post as the authenticated user.
	postAsUserName = authTest.User
	postAsUserID = authTest.UserID

	// Create a temporary channel
	channel, err := api.CreateChannel(channelName)

	if err != nil {
		// If the channel exists, that means we just need to unarchive it
		if err.Error() == "name_taken" {
			err = nil
			channels, err := api.GetChannels(false)
			if err != nil {
				fmt.Println("Could not retrieve channels")
				return
			}
			for _, archivedChannel := range channels {
				if archivedChannel.Name == channelName {
					if archivedChannel.IsArchived {
						err = api.UnarchiveChannel(archivedChannel.ID)
						if err != nil {
							fmt.Printf("Could not unarchive %s: %s\n", archivedChannel.ID, err)
							return
						}
					}
					channel = &archivedChannel
					break
				}
			}
		}
		if err != nil {
			fmt.Printf("Error setting test channel for pinning: %s\n", err)
			return
		}
	}
	postToChannelID = channel.ID

	fmt.Printf("Posting as %s (%s) in channel %s\n", postAsUserName, postAsUserID, postToChannelID)

	// Post a message.
	postParams := slack.PostMessageParameters{}
	channelID, timestamp, err := api.PostMessage(postToChannelID, "Is this any good?", postParams)
	if err != nil {
		fmt.Printf("Error posting message: %s\n", err)
		return
	}

	// Grab a reference to the message.
	msgRef := slack.NewRefToMessage(channelID, timestamp)

	// Add message pin to channel
	if err := api.AddPin(channelID, msgRef); err != nil {
		fmt.Printf("Error adding pin: %s\n", err)
		return
	}

	// List all of the users pins.
	listPins, _, err := api.ListPins(channelID, slack.NewListPinsParameters())
	if err != nil {
		fmt.Printf("Error listing pins: %s\n", err)
		return
	}
	fmt.Printf("\n")
	fmt.Printf("All pins by %s...\n", authTest.User)
	for _, item := range listPins {
		fmt.Printf(" > Item type: %s\n", item.Type)
	}

	// Remove the pin.
	err = api.RemovePin(channelID, msgRef)
	if err != nil {
		fmt.Printf("Error remove pin: %s\n", err)
		return
	}

	if err = api.ArchiveChannel(channelID); err != nil {
		fmt.Printf("Error archiving channel: %s\n", err)
		return
	}

}
Esempio n. 4
0
func (r *Reply) AddReaction(emoji string) *Reply {
	r.OnAck(func(ev *slack.AckMessage) {
		go r.bot.Slack.AddReaction(emoji, slack.NewRefToMessage(r.Channel, ev.Timestamp))
	})
	return r
}
Esempio n. 5
0
func main() {
	var (
		apiToken string
		debug    bool
	)

	flag.StringVar(&apiToken, "token", "YOUR_TOKEN_HERE", "Your Slack API Token")
	flag.BoolVar(&debug, "debug", false, "Show JSON output")
	flag.Parse()

	api := slack.New(apiToken)
	if debug {
		api.SetDebug(true)
	}

	var (
		postAsUserName  string
		postAsUserID    string
		postToUserName  string
		postToUserID    string
		postToChannelID string
	)

	// Find the user to post as.
	authTest, err := api.AuthTest()
	if err != nil {
		fmt.Printf("Error getting channels: %s\n", err)
		return
	}

	// Post as the authenticated user.
	postAsUserName = authTest.User
	postAsUserID = authTest.UserID

	// Posting to DM with self causes a conversation with slackbot.
	postToUserName = authTest.User
	postToUserID = authTest.UserID

	// Find the channel.
	_, _, chanID, err := api.OpenIMChannel(postToUserID)
	if err != nil {
		fmt.Printf("Error opening IM: %s\n", err)
		return
	}
	postToChannelID = chanID

	fmt.Printf("Posting as %s (%s) in DM with %s (%s), channel %s\n", postAsUserName, postAsUserID, postToUserName, postToUserID, postToChannelID)

	// Post a message.
	postParams := slack.PostMessageParameters{}
	channelID, timestamp, err := api.PostMessage(postToChannelID, "Is this any good?", postParams)
	if err != nil {
		fmt.Printf("Error posting message: %s\n", err)
		return
	}

	// Grab a reference to the message.
	msgRef := slack.NewRefToMessage(channelID, timestamp)

	// React with :+1:
	if err := api.AddReaction("+1", msgRef); err != nil {
		fmt.Printf("Error adding reaction: %s\n", err)
		return
	}

	// React with :-1:
	if err := api.AddReaction("cry", msgRef); err != nil {
		fmt.Printf("Error adding reaction: %s\n", err)
		return
	}

	// Get all reactions on the message.
	msgReactions, err := api.GetReactions(msgRef, slack.NewGetReactionsParameters())
	if err != nil {
		fmt.Printf("Error getting reactions: %s\n", err)
		return
	}
	fmt.Printf("\n")
	fmt.Printf("%d reactions to message...\n", len(msgReactions))
	for _, r := range msgReactions {
		fmt.Printf("  %d users say %s\n", r.Count, r.Name)
	}

	// List all of the users reactions.
	listReactions, _, err := api.ListReactions(slack.NewListReactionsParameters())
	if err != nil {
		fmt.Printf("Error listing reactions: %s\n", err)
		return
	}
	fmt.Printf("\n")
	fmt.Printf("All reactions by %s...\n", authTest.User)
	for _, item := range listReactions {
		fmt.Printf("%d on a %s...\n", len(item.Reactions), item.Type)
		for _, r := range item.Reactions {
			fmt.Printf("  %s (along with %d others)\n", r.Name, r.Count-1)
		}
	}

	// Remove the :cry: reaction.
	err = api.RemoveReaction("cry", msgRef)
	if err != nil {
		fmt.Printf("Error remove reaction: %s\n", err)
		return
	}

	// Get all reactions on the message.
	msgReactions, err = api.GetReactions(msgRef, slack.NewGetReactionsParameters())
	if err != nil {
		fmt.Printf("Error getting reactions: %s\n", err)
		return
	}
	fmt.Printf("\n")
	fmt.Printf("%d reactions to message after removing cry...\n", len(msgReactions))
	for _, r := range msgReactions {
		fmt.Printf("  %d users say %s\n", r.Count, r.Name)
	}
}
Esempio n. 6
0
func (msg *Message) RemoveReaction(emoticon string) *Message {
	msg.bot.Slack.RemoveReaction(emoticon, slack.NewRefToMessage(msg.Channel, msg.Timestamp))
	return msg
}