Skip to content

[pull] origin from krau:main#7

Merged
Silentely merged 7 commits intoCosr-Backup:originfrom
krau:main
Jun 8, 2025
Merged

[pull] origin from krau:main#7
Silentely merged 7 commits intoCosr-Backup:originfrom
krau:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull bot commented Jun 8, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Enable multilingual support and Telegram userbot fallback mechanism, update dependencies, and enhance logging, configuration, and message handling

New Features:

  • Add i18n framework with embedded locale files and localization utilities
  • Introduce Telegram userbot client fallback for file retrieval with recovery and retry middlewares
  • Provide cmd/gen_i18n tool to generate internationalization message key constants

Enhancements:

  • Extend configuration to include language and userbot settings with defaults and integrate localization in initialization, logging, and error messages
  • Update dispatcher handlers to ignore channel and group messages before processing
  • Refine logger formatting template and include localized log messages for cache cleanup flows
  • Adjust help command to display the full git commit hash

Build:

  • Bump multiple Go module dependencies to their latest minor versions

Chores:

  • Add UseUserClient flags to Task and ReceivedFile models to track client usage

@pull pull bot added the ⤵️ pull label Jun 8, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Jun 8, 2025

Reviewer's Guide

This PR upgrades dependencies, integrates full i18n support, enhances configuration for language and userbot settings, implements a Telegram userbot fallback client for robust file retrieval, refines dispatcher handler registration, and updates logging formatting.

Sequence Diagram for File Fetching with Userbot Fallback

sequenceDiagram
    participant FileRequester as "File Requester\n(e.g., Bot Handler, Task Processor)"
    participant BotClient as "gotgproto.Client (Bot)"
    participant UserClient as "gotgproto.Client (User)"
    participant TelegramAPI

    FileRequester->>BotClient: Request FileFromMessage(chatID, messageID)
    BotClient->>TelegramAPI: Get file metadata/download
    alt Fetch Successful with BotClient
        TelegramAPI-->>BotClient: File data/stream
        BotClient-->>FileRequester: file, err=nil
    else Fetch Failed with BotClient (e.g., peer not found, restricted)
        TelegramAPI-->>BotClient: Error
        BotClient-->>FileRequester: nil, errorDetails
        opt UserClient Enabled AND Error is recoverable by UserClient
            FileRequester->>UserClient: Request FileFromMessage(chatID, messageID)
            UserClient->>TelegramAPI: Get file metadata/download
            alt Fetch Successful with UserClient
                TelegramAPI-->>UserClient: File data/stream
                UserClient-->>FileRequester: file, err=nil
            else Fetch Failed with UserClient
                TelegramAPI-->>UserClient: Error
                UserClient-->>FileRequester: nil, finalError
            end
        end
    end
Loading

Sequence Diagram for Userbot Login Process

sequenceDiagram
    actor Admin as "Admin/Operator"
    participant UserClientApp as "SaveAny-Bot (userclient)"
    participant TerminalAuth as "termialAuthConversator"
    participant GotgprotoLib as "gotgproto Library"
    participant TelegramAPI

    UserClientApp->>GotgprotoLib: Login(appID, appHash, session, termialAuthConversator)
    GotgprotoLib->>TerminalAuth: AskPhoneNumber()
    TerminalAuth->>Admin: "Your Phone Number"
    Admin-->>TerminalAuth: Enters phone number
    TerminalAuth-->>GotgprotoLib: phone number
    GotgprotoLib->>TelegramAPI: Send code request (auth.sendCode)
    TelegramAPI-->>GotgprotoLib: Code sent
    GotgprotoLib->>TerminalAuth: AskCode()
    TerminalAuth->>Admin: "Your Code"
    Admin-->>TerminalAuth: Enters code
    TerminalAuth-->>GotgprotoLib: code
    GotgprotoLib->>TelegramAPI: Sign in (auth.signIn with code)
    alt 2FA Enabled
        TelegramAPI-->>GotgprotoLib: SessionPasswordNeeded
        GotgprotoLib->>TerminalAuth: AskPassword()
        TerminalAuth->>Admin: "Your 2FA Password"
        Admin-->>TerminalAuth: Enters password
        TerminalAuth-->>GotgprotoLib: password
        GotgprotoLib->>TelegramAPI: Check password (auth.checkPassword)
        TelegramAPI-->>GotgprotoLib: Auth result (User)
    else No 2FA / Code sufficient
        TelegramAPI-->>GotgprotoLib: Auth result (User)
    end
    GotgprotoLib-->>UserClientApp: Client instance (UC)
    UserClientApp->>Admin: "User client logged in as [Name]"
Loading

Class Diagram for Configuration Structure Changes

classDiagram
    direction LR
    class Config {
        +Lang: string "new"
        +Workers: int
        +Retry: int
        +NoCleanCache: bool
        +Threads: int
        +Stream: bool
        +AsPublicCopyMediaBot: bool
        +Log: logConfig
        +DB: dbConfig
        +Telegram: telegramConfig
        +Temp: tempConfig
        +Storages: []storage.StorageConfig
    }
    class telegramConfig {
        +Token: string
        +AppID: int
        +AppHash: string
        +Timeout: int
        +Proxy: proxyConfig
        +FloodRetry: int
        +RpcRetry: int
        +Userbot: userbotConfig "new"
    }
    class userbotConfig {
        +Enable: bool "new"
        +Session: string "new"
    }
    Config "1" *-- "1" telegramConfig : contains
    telegramConfig "1" *-- "1" userbotConfig : contains
Loading

Class Diagram for DAO and Core Type Changes

classDiagram
    direction LR
    class ReceivedFile {
        +gorm.Model
        +ChatID: int64
        +MessageID: int
        +ReplyMessageID: int
        +ReplyChatID: int64
        +FileName: string
        +IsTelegraph: bool
        +TelegraphURL: string
        +UseUserClient: bool  "new"
    }
    class Task {
        +Ctx: context.Context
        +Cancel: context.CancelFunc
        +Error: error
        +UseUserClient: bool "new"
        +Status: TaskStatus
        +StorageName: string
        +StoragePath: string
        +StartTime: time.Time
        +FileDBID: uint
        +File: *File
        +FileMessageID: int
        +FileChatID: int64
        +CallbackMessageID: int
        +UserID: int64
    }
Loading

File-Level Changes

Change Details Files
Upgraded dependencies
  • Bumped various module versions
  • Updated go.sum for new dependencies
go.mod
go.sum
Integrated internationalization (i18n) support
  • Added i18n bundle, locale files, and generator
  • Replaced hardcoded messages with i18n.T calls across codebase
  • Initialized localizer based on config language
i18n/i18n.go
i18n/i18nk/keys.go
i18n/locale/zh-Hans.toml
cmd/gen_i18n/main.go
config/viper.go
cmd/run.go
common/os.go
common/logger.go
bot/handle_start.go
Enhanced configuration for language and userbot
  • Added Lang and userbot settings with defaults
  • Used i18n.TWithoutInit for config validation errors
config/viper.go
Added Telegram userbot fallback client
  • Introduced userclient package with auth and middlewares
  • Implemented tryFetchFileFromMessage with fallback
  • Propagated UseUserClient flag through DAO, Task, core, and handlers
userclient/auth.go
userclient/userclient.go
userclient/middlewares/recovery/recovery.go
userclient/middlewares/retry/retry.go
userclient/middlewares/middlewares.go
bot/handle_link.go
bot/handle_add_task.go
types/task.go
dao/model.go
core/download.go
Refined handler registration
  • Renamed dispatcher parameter and handlers variable
  • Added chat type filters before permission check
bot/handlers.go
Adjusted logging formatter
  • Removed default channel name
  • Set custom template for console and file handlers
common/logger.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 8, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Silentely Silentely merged commit b35f748 into Cosr-Backup:origin Jun 8, 2025
4 of 5 checks passed
@guardrails
Copy link
Copy Markdown

guardrails bot commented Jun 8, 2025

⚠️ We detected 2 security issues in this pull request:

Vulnerable Libraries (2)
Severity Details
Medium pkg:golang/golang.org/x/net@v0.41.0 upgrade to: > v0.41.0
Medium pkg:golang/github.com/charmbracelet/huh@v0.7.0 upgrade to: > v0.7.0

More info on how to fix Vulnerable Libraries in Go.


👉 Go to the dashboard for detailed results.

📥 Happy? Share your feedback with us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants