leobot

Simple Telegram Logging Bot
git clone git://bsandro.tech/leobot
Log | Files | Refs

commit 218d845baa43a9bdd102f120928029f67d8e5fbd
parent 87a18f36b6957c3fae730d0c25acf68fb7c465c2
Author: bsandro <email@bsandro.tech>
Date:   Sat,  5 Nov 2022 09:09:06 +0200

Logs path = binary exe path, not "working path"

Diffstat:
Mmain.go | 12+++++++++++-
Areadme.txt | 12++++++++++++
Areadme_ru.txt | 14++++++++++++++
3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/main.go b/main.go @@ -6,12 +6,22 @@ import ( tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "log" "os" + "path/filepath" "strings" "sync" "time" ) +var logPath string + func main() { + binPath, err := filepath.Abs(os.Args[0]) + if err != nil { + log.Fatal(err) + } + logPath = filepath.Dir(binPath) + log.Println("Logs path:", logPath) + cfg, err := ini.Load("config.ini") if err != nil { log.Fatal("Invalid config.ini: ", err) @@ -63,7 +73,7 @@ func writeLog(msg *tgbotapi.Message, mtx *sync.Mutex) { ts := time.Unix(int64(msg.Date), 0) ps := string(os.PathSeparator) - fpath := "logs" + ps + chat + ps + ts.Format("2006"+ps+"01"+ps+"02") + fpath := logPath + ps + "logs" + ps + chat + ps + ts.Format("2006"+ps+"01"+ps+"02") fname := fpath + ps + "log.txt" if err := os.MkdirAll(fpath, 0750); err != nil { diff --git a/readme.txt b/readme.txt @@ -0,0 +1,12 @@ +Simple bot for logging messages from public channels that it have been added to and private ones. + +How to run? + +There is a special bot @BotFather in Telegram - message /newbot to it and follow instructions. It will provide a oken for the bot - put it inside the config.ini file so it looks like: +token = 123123:bunchofletters + +Then you have to permit your bot to access messages in public channels - send @BotFather the command /setprivacy and choose "Disable" after a selector appears. + +Bot can be added to public chats afterwards. + +Logs are being written into the "logs" folder placed the same directory where your bot executable is. Folder structure is "channel/year/month/day/log.txt" diff --git a/readme_ru.txt b/readme_ru.txt @@ -0,0 +1,14 @@ +Простой бот, логирующий чаты в которые он добавлен и приватные сообщения. + +Как запустить? + +В самом Telegram нужно написать специальному боту @BotFather - начать с /newbot и дальше следовать инструкциям. +Он выдаст токен для бота - нужно его скопипастить в config.ini, чтобы содержимое было вида: +token = 123123:многобукв + +Далее нужно разрешить боту доступ к сообщениям в публичных каналах - снова отправить команду @BotFather: +/setprivacy +И выбрать вариант "Disable". + +После этого бота можно добавлять в публичные каналы. +Логи пишутся в папку "logs" прямо рядом с бинарником, иерархия "канал/год/месяц/день/log.txt"