Files
SaveAny-Bot/database/rule.go
Krau 900823cdb9 refactor: refactor task logic for better scalability (#76)
* refactor: a big refactor. wip

* refactor: port handle file

* refactor: place all handlers

* fix: task info nil pointer

* feat: enhance task progress tracking and context management

* feat: cancel task

* feat: stream mode

* feat: silent mode

* feat: dir cmd

* refactor: remove unused old file

* feat: rule cmd

* feat: handle silent mode

* feat: batch task

* fix: batch task progress and temp file cleanup

* refactor: update file creation and cleanup methods for better resource management

* feat: add save command with silent mode handling

* feat: message link

* feat: update message prompts to include file count in storage selection

* feat: slient save links

* refactor: reduce dup code

* feat: rule type

* feat: chose dir

* feat: refactor file handling and storage rules, improve error handling and logging

* feat: rule mode

* feat: telegraph pics

* fix: tphpics nil pointer and inaccurate dirpath

* feat: silent save telegraph

* feat: add suffix to avoid file overwrite

* feat: new storage telegram

* chore: tidy go mod
2025-06-15 23:57:49 +08:00

25 lines
741 B
Go

package database
import "context"
func CreateRule(ctx context.Context, rule *Rule) error {
return db.WithContext(ctx).Create(rule).Error
}
func DeleteRule(ctx context.Context, ruleID uint) error {
return db.WithContext(ctx).Unscoped().Delete(&Rule{}, ruleID).Error
}
func UpdateUserApplyRule(ctx context.Context, chatID int64, applyRule bool) error {
return db.WithContext(ctx).Model(&User{}).Where("chat_id = ?", chatID).Update("apply_rule", applyRule).Error
}
func GetRulesByUserChatID(ctx context.Context, chatID int64) ([]Rule, error) {
var rules []Rule
err := db.WithContext(ctx).Where("user_id = (SELECT id FROM users WHERE chat_id = ?)", chatID).Find(&rules).Error
if err != nil {
return nil, err
}
return rules, nil
}