- изменение для работы с alr

This commit is contained in:
2025-08-13 21:37:43 +03:00
parent a2e672fd73
commit c315329c11
16 changed files with 187 additions and 74 deletions

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ import (
"strings"
"go.elara.ws/logger/log"
"lure.sh/lure-updater/internal/config"
"gitea.plemya-x.ru/Plemya-x/ALR-updater/internal/config"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
"golang.org/x/crypto/bcrypt"

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -8,7 +8,7 @@ import (
"strings"
"github.com/vmihailenco/msgpack/v5"
"lure.sh/lure-updater/internal/convert"
"gitea.plemya-x.ru/Plemya-x/ALR-updater/internal/convert"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
)

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -36,6 +36,8 @@ var regexModule = &starlarkstruct.Module{
Members: starlark.StringDict{
"compile": starlark.NewBuiltin("regex.compile", regexCompile),
"compile_glob": starlark.NewBuiltin("regex.compile_glob", regexCompileGlob),
"find": starlark.NewBuiltin("regex.find", regexFind),
"replace": starlark.NewBuiltin("regex.replace", regexReplace),
},
}
@@ -143,3 +145,55 @@ func matchesToStarlark1D(match []string) *starlark.List {
}
return starlark.NewList(list)
}
func regexFind(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var pattern, text string
err := starlark.UnpackArgs("regex.find", args, kwargs, "pattern", &pattern, "text", &text)
if err != nil {
return nil, err
}
cacheMtx.Lock()
regex, ok := regexCache[pattern]
if !ok {
regex, err = pcre.Compile(pattern)
if err != nil {
cacheMtx.Unlock()
return nil, err
}
regexCache[pattern] = regex
}
cacheMtx.Unlock()
matches := regex.FindStringSubmatch(text)
if len(matches) > 1 {
return starlark.String(matches[1]), nil
}
if len(matches) > 0 {
return starlark.String(matches[0]), nil
}
return starlark.String(""), nil
}
func regexReplace(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var text, pattern, replacement string
err := starlark.UnpackArgs("regex.replace", args, kwargs, "text", &text, "pattern", &pattern, "replacement", &replacement)
if err != nil {
return nil, err
}
cacheMtx.Lock()
regex, ok := regexCache[pattern]
if !ok {
regex, err = pcre.Compile(pattern)
if err != nil {
cacheMtx.Unlock()
return nil, err
}
regexCache[pattern] = regex
}
cacheMtx.Unlock()
result := regex.ReplaceAllString(text, replacement)
return starlark.String(result), nil
}

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@ package builtins
import (
"net/http"
"lure.sh/lure-updater/internal/config"
"gitea.plemya-x.ru/Plemya-x/ALR-updater/internal/config"
"go.etcd.io/bbolt"
"go.starlark.net/starlark"
"go.starlark.net/starlarkjson"
@@ -35,7 +35,7 @@ type Options struct {
}
func Register(sd starlark.StringDict, opts *Options) {
sd["run_every"] = starlark.NewBuiltin("run_every", runEvery)
sd["run_every"] = runEveryModule
sd["sleep"] = starlark.NewBuiltin("sleep", sleep)
sd["http"] = httpModule
sd["regex"] = regexModule

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -100,3 +100,76 @@ func newTickerHandle(handle int) starlark.Value {
"stop": stopTicker(handle),
})
}
var runEveryModule = &starlarkstruct.Module{
Name: "run_every",
Members: starlark.StringDict{
"minute": starlark.NewBuiltin("run_every.minute", runEveryMinute),
"hour": starlark.NewBuiltin("run_every.hour", runEveryHour),
"day": starlark.NewBuiltin("run_every.day", runEveryDay),
"week": starlark.NewBuiltin("run_every.week", runEveryWeek),
},
}
func runEveryMinute(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var fn *starlark.Function
err := starlark.UnpackArgs("run_every.minute", args, kwargs, "function", &fn)
if err != nil {
return nil, err
}
return runScheduled(thread, fn, "1m")
}
func runEveryHour(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var fn *starlark.Function
err := starlark.UnpackArgs("run_every.hour", args, kwargs, "function", &fn)
if err != nil {
return nil, err
}
return runScheduled(thread, fn, "1h")
}
func runEveryDay(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var fn *starlark.Function
err := starlark.UnpackArgs("run_every.day", args, kwargs, "function", &fn)
if err != nil {
return nil, err
}
return runScheduled(thread, fn, "24h")
}
func runEveryWeek(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var fn *starlark.Function
err := starlark.UnpackArgs("run_every.week", args, kwargs, "function", &fn)
if err != nil {
return nil, err
}
return runScheduled(thread, fn, "168h")
}
func runScheduled(thread *starlark.Thread, fn *starlark.Function, duration string) (starlark.Value, error) {
d, err := time.ParseDuration(duration)
if err != nil {
return nil, err
}
tickerMtx.Lock()
t := time.NewTicker(d)
handle := tickerCount
tickers[handle] = t
tickerCount++
tickerMtx.Unlock()
log.Debug("Created new scheduled ticker").Int("handle", handle).Str("duration", duration).Stringer("pos", thread.CallFrame(1).Pos).Send()
go func() {
for range t.C {
log.Debug("Calling scheduled function").Str("name", fn.Name()).Stringer("pos", fn.Position()).Send()
_, err := starlark.Call(thread, fn, nil, nil)
if err != nil {
log.Warn("Error while executing scheduled function").Str("name", fn.Name()).Stringer("pos", fn.Position()).Err(err).Send()
}
}
}()
return newTickerHandle(handle), nil
}

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"go.elara.ws/logger/log"
"lure.sh/lure-updater/internal/config"
"gitea.plemya-x.ru/Plemya-x/ALR-updater/internal/config"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
)

View File

@@ -1,6 +1,6 @@
/*
* LURE Updater - Automated updater bot for LURE packages
* Copyright (C) 2023 Elara Musayelyan
* ALR Updater - Automated updater bot for ALR packages
* Copyright (C) 2025 The ALR Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by