MCPcopy Create free account
hub / github.com/AudDMusic/RedditBot / GetVideoLink

Method GetVideoLink

main.go:307–349  ·  view source on GitHub ↗
(mention *reddit1.Message, comment *models.Comment)

Source from the content-addressed store, hash-verified

305}
306
307func (r *auddBot) GetVideoLink(mention *reddit1.Message, comment *models.Comment) (string, string, error) {
308 var post *models.Post
309 if mention == nil && comment == nil {
310 return "", "", fmt.Errorf("empty mention and comment")
311 }
312 var parentId models.RedditID
313 commentsTree := make([]*models.Comment, 0)
314 if mention != nil {
315 parentId = models.RedditID(mention.ParentID)
316 } else {
317 parentId = comment.ParentID
318 commentsTree = append(commentsTree, comment)
319 }
320 postId := parentId
321 for parentId != "" {
322 postId = parentId
323 //posts, comments, _, _, err := r.client.Listings.Get(context.Background(), parentId)
324 parent, err := r.r.SubmissionInfoID(parentId)
325 //r.bot.Listing(parentId, )
326 j, _ := json.Marshal(parent)
327 fmt.Printf("parent [%s]: %s\n", string(parentId), string(j))
328 if err != nil && err.Error() != "no results" {
329 return "", "", err
330 }
331 if err == nil {
332 if p, ok := parent.(*models.Post); ok {
333 post = p
334 break
335 }
336 if c, ok := parent.(*models.Comment); ok {
337 commentsTree = append(commentsTree, c)
338 parentId = c.ParentID
339 } else {
340 return "", "", fmt.Errorf("got a result that's neither a post nor a comment, parent ID %s, %v",
341 parentId, parent)
342 }
343 } else {
344 parentId = ""
345 }
346 }
347 l, err := r.GetLinkFromComment(mention, commentsTree, post)
348 return l, string(postId), err
349}
350
351func isEmpty(e ...string) bool {
352 for _, s := range e {

Callers 1

HandleQueryMethod · 0.95

Calls 1

GetLinkFromCommentMethod · 0.95

Tested by

no test coverage detected