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
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
}
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))