Example #1
0
// addStoryVote adjusts the story points, and adds a vote record for this user
func addStoryVote(story *stories.Story, user *users.User, ip string, delta int64) error {

	if story.Points < -5 && delta < 0 {
		return router.InternalError(nil, "Vote Failed", "Story is already hidden")
	}

	// Update the story points by delta
	err := story.Update(map[string]string{"points": fmt.Sprintf("%d", story.Points+delta)})
	if err != nil {
		return router.InternalError(err, "Vote Failed", "Sorry your adjust vote points")
	}

	return recordStoryVote(story, user, ip, delta)
}
Example #2
0
// TweetStory tweets the given story
func TweetStory(context schedule.Context, story *stories.Story) {

	// Base url from config
	baseURL := context.Config("root_url")

	// Link to the primary url for this type of story
	url := story.PrimaryURL()

	// Check for relative urls
	if strings.HasPrefix(url, "/") {
		url = baseURL + url
	}

	tweet := fmt.Sprintf("%s #golang %s", story.Name, url)

	// If the tweet will be too long for twitter, use GN url
	if len(tweet) > 140 {
		tweet = fmt.Sprintf("%s #golang %s", story.Name, baseURL+story.URLShow())
	}

	context.Logf("#info sending tweet:%s", tweet)

	_, err := twitter.Tweet(tweet)
	if err != nil {
		context.Logf("#error tweeting top story %s", err)
		return
	}

	// Record that this story has been tweeted in db
	params := map[string]string{"tweeted_at": query.TimeString(time.Now().UTC())}
	err = story.Update(params)
	if err != nil {
		context.Logf("#error updating top story tweet %s", err)
		return
	}

}