feat: implement watch for monitoring chat messages
- Added a new command handler for /watch that allows users to listen to messages from a specified chat and save them according to storage rules. - Introduced filtering options for messages using regular expressions. - Implemented functionality to start and stop watching chats, including error handling for invalid inputs and user settings. - Created a new utility package for message element handling related to the watch feature. - Updated the user model to manage watched chats, including methods to add, remove, and check if a chat is being watched.
This commit is contained in:
@@ -16,7 +16,9 @@ import (
|
||||
|
||||
func (t *Task) Execute(ctx context.Context) error {
|
||||
logger := log.FromContext(ctx).WithPrefix(fmt.Sprintf("file[%s]", t.File.Name()))
|
||||
t.Progress.OnStart(ctx, t)
|
||||
if t.Progress != nil {
|
||||
t.Progress.OnStart(ctx, t)
|
||||
}
|
||||
if t.stream {
|
||||
return executeStream(ctx, t)
|
||||
}
|
||||
@@ -34,7 +36,9 @@ func (t *Task) Execute(ctx context.Context) error {
|
||||
wrAt := newWriterAt(ctx, localFile, t.Progress, t)
|
||||
|
||||
defer func() {
|
||||
t.Progress.OnDone(ctx, t, err)
|
||||
if t.Progress != nil {
|
||||
t.Progress.OnDone(ctx, t, err)
|
||||
}
|
||||
}()
|
||||
_, err = tfile.NewDownloader(t.File).Parallel(ctx, wrAt)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,7 +32,9 @@ func executeStream(ctx context.Context, task *Task) error {
|
||||
})
|
||||
var err error
|
||||
defer func() {
|
||||
task.Progress.OnDone(ctx, task, err)
|
||||
if task.Progress != nil {
|
||||
task.Progress.OnDone(ctx, task, err)
|
||||
}
|
||||
}()
|
||||
if err = errg.Wait(); err != nil {
|
||||
return err
|
||||
|
||||
@@ -20,7 +20,9 @@ func (w *ProgressWriterAt) WriteAt(p []byte, off int64) (int, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
w.progress.OnProgress(w.ctx, w.info, w.downloaded.Add(int64(at)), w.total)
|
||||
if w.progress != nil {
|
||||
w.progress.OnProgress(w.ctx, w.info, w.downloaded.Add(int64(at)), w.total)
|
||||
}
|
||||
return at, nil
|
||||
}
|
||||
|
||||
@@ -54,7 +56,9 @@ func (w *ProgressWriter) Write(p []byte) (int, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
w.progress.OnProgress(w.ctx, w.info, w.downloaded.Add(int64(at)), w.total)
|
||||
if w.progress != nil {
|
||||
w.progress.OnProgress(w.ctx, w.info, w.downloaded.Add(int64(at)), w.total)
|
||||
}
|
||||
return at, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user