From d3271d6164dd9d36e5fb9c73721516b333b6ccdf Mon Sep 17 00:00:00 2001 From: Saph1s Date: Wed, 7 Feb 2024 23:10:16 +0300 Subject: [PATCH] Refactor SortTags function to include group ID in generated links Replaced hardcoded group id --- main.go | 2 +- utils/main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 590c51d..e13d1d5 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func main() { defer discordbot.Close() vkbot.WallPostNew(func(ctx context.Context, obj events.WallPostNewObject) { - sortedtext := utils.SortTags(string(obj.Text)) + sortedtext := utils.SortTags(string(obj.Text), int(obj.OwnerID)) group, err := vkbot.VK.GroupsGetByID(api.Params{"group_id": -obj.OwnerID}) if err != nil { log.Fatalf("Error getting group name: %s", err) diff --git a/utils/main.go b/utils/main.go index 41a6f04..ed92b69 100644 --- a/utils/main.go +++ b/utils/main.go @@ -8,7 +8,7 @@ import ( re "github.com/dlclark/regexp2" ) -func SortTags(text string) string { +func SortTags(text string, groupID int) string { var ( mentions = re.MustCompile(`\[([^\s\|]+)+\|(.*?)\]`, 0) subReg = re.MustCompile(`^(?=id|club).*`, 0) @@ -38,7 +38,7 @@ func SortTags(text string) string { for result != nil { r0 = result.GroupByNumber(0).String() r1 = result.GroupByNumber(1).String() - link := "https://vk.com/wall-27055949?q=%23" + r1 + link := fmt.Sprintf("https://vk.com/wall%d?q=%%23%s", groupID, r1) text = strings.Replace(text, result.String(), "["+r0+"]("+link+")", 1) result, _ = hashtagGroup.FindStringMatch(text) }