Skip to content

Commit

Permalink
Refactor SortTags function to include group ID in generated links
Browse files Browse the repository at this point in the history
Replaced hardcoded group id
  • Loading branch information
Saph1s committed Feb 7, 2024
1 parent fba8112 commit d3271d6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions utils/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d3271d6

Please sign in to comment.