issues are now managed too main
authorEduardo <[email protected]>
Sat, 30 Mar 2024 18:02:14 +0000 (19:02 +0100)
committerEduardo <[email protected]>
Sat, 30 Mar 2024 18:02:14 +0000 (19:02 +0100)
telegram.go
utils.go

index 65e17d434abbbaf65a1085a620033ac7c75a1145..aa3962679565cb1130d9d4b4bbe92b87db21927b 100644 (file)
@@ -188,7 +188,7 @@ func manageSerieRequest(chatId int64, text string) error {
                response = "🎥"
        }
 
-               // get from text whatever is after the first - and the end of the line
+       // get from text whatever is after the first - and the end of the line
        response += " <b>" + getFirstLine(getTextAfterDash(text)) + "</b>\n"
 
        // request can be: new, available
@@ -207,12 +207,42 @@ func manageSerieRequest(chatId int64, text string) error {
 
 func manageIssueMessage(chatId int64, text string) error {
        var err error
+       var response string = "⚠️"
 
-       // issue can be: comment, resolved, reported
        // issues can be type: video, audio, subtitle
+       var regexVideo = regexp.MustCompile(`(?i)\bVideo\b`)
+       var regexAudio = regexp.MustCompile(`(?i)\bAudio\b`)
+       var regexSubtitle = regexp.MustCompile(`(?i)\bSubtitle\b`)
+
+       if regexVideo.MatchString(text) {
+               response += "📺"
+       } else if regexAudio.MatchString(text) {
+               response += "🔊"
+       } else if regexSubtitle.MatchString(text) {
+               response += "💬"
+       }
 
-       //TODO: manage issues
+       // issue can be: comment, resolved, reported
+       var regexComment = regexp.MustCompile(`(?i)\bComment\b`)
+       var regexResolved = regexp.MustCompile(`(?i)\bResolved\b`)
+       var regexReported = regexp.MustCompile(`(?i)\bReported\b`)
+
+       if regexComment.MatchString(text) {
+               response += " <b>" + getFirstLine(getTextAfterDash(text)) + "</b>\n"
+               response += "🔍 <u>Incidencia:</u>\n" + getSubstringBetween(text, getFirstLine(getTextAfterDash(text)), "Comment from") + "\n\n"
+               response += "🔧 <u>Comentario:</u>\n" + getSubstringBetween(text, "Comment from "+getCommentedBy(text)+": ", "") + "\n"
+       } else if regexResolved.MatchString(text) {
+               response += " <b>" + getFirstLine(getTextAfterDash(text)) + "</b>\n"
+               response += "Reportado por <b>" + getReportedBy(text) + "</b>\n\n"
+               response += "🔍 <u>Incidencia:</u>\n" + getSubstringBetween(text, getFirstLine(getTextAfterDash(text)), "Reported By:") + "\n\n"
+               response += "🎉 <b>Resuelto!</b> "
+       } else if regexReported.MatchString(text) {
+               response += " <b>" + getFirstLine(getTextAfterDash(text)) + "</b>\n"
+               response += "Reportado por <b>" + getReportedBy(text) + "</b>\n\n"
+               response += "🔍 <u>Incidencia:</u>\n" + getSubstringBetween(text, getFirstLine(getTextAfterDash(text)), "Reported By:") + "\n"
+       }
 
+       err = sendTelegramPhoto(chatId, lastMsg.Photo[0].FileID, response)
        return err
 }
 
index 9f1594d2e06206106661c31208189c4b62e9594a..28cae8d7ea246685ba885ca056e5f6d6e9ea7311 100644 (file)
--- a/utils.go
+++ b/utils.go
@@ -45,6 +45,42 @@ func getRequestedBy(s string) string {
        return "???"
 }
 
+// Search for the text after "Reported By:" in a string and returns it
+func getReportedBy(s string) string {
+       re := regexp.MustCompile(`(?i)Reported By:\s*(.*)`)
+       match := re.FindStringSubmatch(s)
+       if len(match) > 1 {
+               return strings.TrimSpace(match[1])
+       }
+       return "???"
+}
+
+func getCommentedBy(s string) string {
+       res := getSubstringBetween(s, "Comment from", ":")
+       return strings.TrimSpace(res)
+}
+
+// Get the substring between two strings in a text
+func getSubstringBetween(s string, from string, to string) string {
+       startIndex := strings.Index(s, from)
+       if startIndex == -1 {
+               return ""
+       }
+       startIndex += len(from)
+
+       if to == "" {
+               return strings.TrimSpace(s[startIndex:])
+       }
+
+       endIndex := strings.Index(s[startIndex:], to)
+       if endIndex == -1 {
+               return ""
+       }
+       endIndex += startIndex
+
+       return strings.TrimSpace(s[startIndex:endIndex])
+}
+
 func normaliceString(s string) string {
 
        t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC, runes.If(runes.In(unicode.Latin), width.Fold, nil))