616c6b1c62
Release Docker multi arch / docker (push) Has been cancelled
Test Install Script / Test Script Syntax (push) Has been cancelled
Test Install Script / Test on almalinux-10 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-10 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-8 (root) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (default) (push) Has been cancelled
Test Install Script / Test on almalinux-9 (root) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (default) (push) Has been cancelled
Test Install Script / Test on amazonlinux-2 (root) (push) Has been cancelled
Test Install Script / Test on debian-11 (default) (push) Has been cancelled
Test Install Script / Test on debian-11 (root) (push) Has been cancelled
Test Install Script / Test on debian-12 (default) (push) Has been cancelled
Test Install Script / Test on debian-12 (root) (push) Has been cancelled
Test Install Script / Test on debian-13 (default) (push) Has been cancelled
Test Install Script / Test on debian-13 (root) (push) Has been cancelled
Test Install Script / Test on fedora-latest (default) (push) Has been cancelled
Test Install Script / Test on fedora-latest (root) (push) Has been cancelled
Test Install Script / Test on rocky-10 (default) (push) Has been cancelled
Test Install Script / Test on rocky-10 (root) (push) Has been cancelled
Test Install Script / Test on rocky-8 (default) (push) Has been cancelled
Test Install Script / Test on rocky-8 (root) (push) Has been cancelled
Test Install Script / Test on rocky-9 (default) (push) Has been cancelled
Test Install Script / Test on rocky-9 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-22.04 (root) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (default) (push) Has been cancelled
Test Install Script / Test on ubuntu-24.04 (root) (push) Has been cancelled
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
package tgbot
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
tele "gopkg.in/telebot.v4"
|
|
sets "server/settings"
|
|
)
|
|
|
|
func cmdViewed(c tele.Context) error {
|
|
args := c.Args()
|
|
if len(args) == 0 {
|
|
return c.Send(tr(c.Sender().ID, "viewed_usage"))
|
|
}
|
|
|
|
action := strings.ToLower(args[0])
|
|
if action == "set" || action == "rem" {
|
|
if len(args) < 2 {
|
|
return c.Send(fmt.Sprintf(tr(c.Sender().ID, "viewed_usage_action"), action))
|
|
}
|
|
hash := resolveHash(c, args[1])
|
|
if hash == "" {
|
|
return c.Send(tr(c.Sender().ID, "invalid_hash"))
|
|
}
|
|
if action == "set" {
|
|
if len(args) < 3 {
|
|
return c.Send(tr(c.Sender().ID, "viewed_usage_set"))
|
|
}
|
|
index, err := strconv.Atoi(args[2])
|
|
if err != nil || index < 1 {
|
|
return c.Send(tr(c.Sender().ID, "viewed_file_index"))
|
|
}
|
|
sets.SetViewed(&sets.Viewed{Hash: hash, FileIndex: index})
|
|
return c.Send(fmt.Sprintf(tr(c.Sender().ID, "viewed_marked"), hash, index))
|
|
}
|
|
index := -1
|
|
if len(args) >= 3 {
|
|
if i, err := strconv.Atoi(args[2]); err == nil && i >= 1 {
|
|
index = i
|
|
}
|
|
}
|
|
sets.RemViewed(&sets.Viewed{Hash: hash, FileIndex: index})
|
|
if index >= 1 {
|
|
return c.Send(fmt.Sprintf(tr(c.Sender().ID, "viewed_unmarked"), hash, index))
|
|
}
|
|
return c.Send(fmt.Sprintf(tr(c.Sender().ID, "viewed_cleared"), hash))
|
|
}
|
|
|
|
hash := resolveHash(c, args[0])
|
|
if hash == "" {
|
|
return c.Send(tr(c.Sender().ID, "viewed_usage"))
|
|
}
|
|
|
|
list := sets.ListViewed(hash)
|
|
if len(list) == 0 {
|
|
return c.Send(tr(c.Sender().ID, "viewed_empty"))
|
|
}
|
|
|
|
var sb strings.Builder
|
|
sb.WriteString("<b>" + tr(c.Sender().ID, "viewed_list") + "</b>\n\n")
|
|
fmt.Fprintf(&sb, "<code>%s</code>\n\n", hash)
|
|
for _, v := range list {
|
|
fmt.Fprintf(&sb, " #%d\n", v.FileIndex)
|
|
}
|
|
return c.Send(sb.String())
|
|
}
|