-
Notifications
You must be signed in to change notification settings - Fork 0
Fix build errors: implement missing handler methods and remove unused imports #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ package bot | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ package bot | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "os" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "os/exec" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "path/filepath" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -309,6 +310,258 @@ func (b *Bot) handleExecCommand(chatID int64, session *UserSession, text string) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.api.Send(msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // handleFileUpload handles file uploads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (b *Bot) handleFileUpload(chatID int64, document *tgbotapi.Document) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.logger.Infof("📤 File upload request: %s (%s)", document.FileName, document.FileID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Get file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fileURL, err := b.api.GetFileDirectURL(document.FileID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.logger.Errorf("❌ Failed to get file URL: %v", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.sendMessage(chatID, "❌ Failed to download file") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.logger.Infof("✅ File uploaded: %s, URL: %s", document.FileName, fileURL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.sendMessage(chatID, fmt.Sprintf("✅ File received: **%s** (%d bytes)\n\nUse /ls to see uploaded files", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| b.sendMessage(chatID, fmt.Sprintf("✅ File received: **%s** (%d bytes)\n\nUse /ls to see uploaded files", | |
| b.sendMessage(chatID, fmt.Sprintf("✅ File received from Telegram: **%s** (%d bytes)\n\nThe file remains stored on Telegram and is not saved on this server.", |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The maxSize constant is defined locally within the function. Since this is a Telegram message length limit (which is consistently 4096 characters throughout the codebase), consider defining it as a package-level constant to avoid magic numbers and enable reuse. For example, define "const maxTelegramMessageLength = 4096" at the package level.
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading arbitrary files with os.ReadFile and converting to string may cause issues with binary files, as binary content cannot be properly represented as UTF-8 text. This could result in corrupted output or panic. Consider checking if the file is a text file first (e.g., using file extension or content sniffing), or handle binary files separately by sending them as documents instead of displaying their content.
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PID threshold of 300 to prevent killing critical system processes is arbitrary and platform-dependent. On some systems, user processes can have PIDs below 300, and on others, system processes may have higher PIDs. A more robust approach would be to check the process owner (prevent killing root-owned processes) or maintain a list of protected process names (init, systemd, sshd, etc.).
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Unix-like systems, os.FindProcess always succeeds regardless of whether the process exists. The actual error only occurs when trying to send a signal. This means the function will not properly detect non-existent processes before attempting to kill them. Consider using proc.Signal(syscall.Signal(0)) to test if the process exists first, or handle the kill error more specifically to distinguish between "process not found" and other errors.
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name "logsText" mixes plural "logs" with singular "Text". For consistency with Go naming conventions and the codebase style, consider using either "logText" (singular) or "logsOutput" to be more descriptive of what it contains.
| logsText := string(output) | |
| if len(logsText) > 4000 { | |
| logsText = logsText[len(logsText)-4000:] | |
| } | |
| response := fmt.Sprintf("📝 **System Logs (last %d lines):**\n\n```\n%s\n```", lines, logsText) | |
| logText := string(output) | |
| if len(logText) > 4000 { | |
| logText = logText[len(logText)-4000:] | |
| } | |
| response := fmt.Sprintf("📝 **System Logs (last %d lines):**\n\n```\n%s\n```", lines, logText) |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When logs exceed 4000 characters, the truncation takes characters from the end of the output, which means the most recent log entries are shown but earlier context is lost. This makes the log message potentially confusing since it says "last N lines" but then shows a truncated middle portion. Consider either truncating from the beginning to show the most recent entries, or better yet, split into multiple messages to show all requested lines.
| if len(logsText) > 4000 { | |
| logsText = logsText[len(logsText)-4000:] | |
| } | |
| response := fmt.Sprintf("📝 **System Logs (last %d lines):**\n\n```\n%s\n```", lines, logsText) | |
| msg := tgbotapi.NewMessage(chatID, response) | |
| msg.ParseMode = "Markdown" | |
| b.api.Send(msg) | |
| // Telegram has a message length limit (~4096 chars), so we send logs in chunks. | |
| // Use a conservative chunk size to account for Markdown formatting and header text. | |
| const maxChunkSize = 3500 | |
| for start := 0; start < len(logsText); start += maxChunkSize { | |
| end := start + maxChunkSize | |
| if end > len(logsText) { | |
| end = len(logsText) | |
| } | |
| chunk := logsText[start:end] | |
| var response string | |
| if start == 0 { | |
| // First chunk includes the header. | |
| response = fmt.Sprintf("📝 **System Logs (last %d lines):**\n\n```\n%s\n```", lines, chunk) | |
| } else { | |
| // Subsequent chunks are continuations. | |
| response = fmt.Sprintf("```\n%s\n```", chunk) | |
| } | |
| msg := tgbotapi.NewMessage(chatID, response) | |
| msg.ParseMode = "Markdown" | |
| b.api.Send(msg) | |
| } |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message for unknown admin subcommands reveals all available admin commands to any authorized user. While this may be intentional for usability, it could be considered information disclosure. Consider whether listing available admin operations in error responses aligns with your security model, especially since some of these operations (reboot, shutdown) are currently disabled but their existence is advertised.
| b.sendMessage(chatID, "❓ Unknown admin command. Available: reboot, shutdown, update") | |
| b.sendMessage(chatID, "❓ Unknown admin command. Use /admin to view available admin options.") |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This formatBytes function is duplicated from internal/system/info.go (lines 379-390). The duplicate implementation creates maintainability issues as changes to one won't automatically apply to the other. Consider moving this to a shared utility package or importing it from the existing location to avoid duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function comment states "Acknowledges file uploads, returns download URL" but the implementation doesn't return anything - it's a void function. Additionally, it doesn't acknowledge in the sense of storing/saving the file, only logging the URL. The comment should be updated to accurately reflect what the function actually does, for example: "Handles file upload notifications from Telegram and logs the file URL".