Archived
0

Чистка кода, конфигов, док-ции, прогон lint-ера

* Подчищены импорты
* Исправлен формат printf
* Исправлены концы строк с dos-формата на unix-формат
* Задавлена часть "лишних" сообщений golangci-lint
This commit is contained in:
eleksir
2021-10-17 17:24:45 +03:00
parent 7a01ede0c8
commit 01bb29ff21
6 changed files with 166 additions and 161 deletions

4
README
View File

@@ -13,8 +13,8 @@
Для сборки понадобятся интернеты и компилятор go версии 1.16.5. Собиралось и тестировалось всё на нём. Для сборки понадобятся интернеты и компилятор go версии 1.16.5. Собиралось и тестировалось всё на нём.
Чтобы запустить бота понадобится: Чтобы запустить бота понадобится:
* Файлик galichbot.ini, в котором нужно всего 2 значения telegram id пользователя и * Файлик galichbot.ini, в котором нужно всего 2 значения: telegram id пользователя и ключ бота, который можно получить у
ключ бота, который можно получить у BotFather в Телеграме. BotFather в Телеграме.
* А ещё нужен файлик phrases.txt, в котором через разделитель "--" (без кавычек) будут перечислены фразы, которыми бот * А ещё нужен файлик phrases.txt, в котором через разделитель "--" (без кавычек) будут перечислены фразы, которыми бот
будет отвечать на любое сообщение пользователя-жертвы. будет отвечать на любое сообщение пользователя-жертвы.
* Устойчивое соединение с интернетами. * Устойчивое соединение с интернетами.

27
main.go
View File

@@ -4,7 +4,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand" "math/rand"
"os"
"strings" "strings"
"time" "time"
@@ -14,24 +13,28 @@ import (
func main() { func main() {
cfg, err := ini.Load("galichbot.ini") cfg, err := ini.Load("galichbot.ini")
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
token := cfg.Section("").Key("BotApiKey").String() token := cfg.Section("").Key("BotApiKey").String()
victim, err := cfg.Section("").Key("VictimID").Int64() victim, err := cfg.Section("").Key("VictimID").Int64()
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
fileName := "phrases.txt" fileName := "phrases.txt"
fileBytes, err := ioutil.ReadFile(fileName) fileBytes, err := ioutil.ReadFile(fileName)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
speeches := strings.Split(string(fileBytes), "--") speeches := strings.Split(string(fileBytes), "--")
bot, err := micha.NewBot(token) bot, err := micha.NewBot(token)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@@ -42,20 +45,22 @@ func main() {
for update := range bot.Updates() { for update := range bot.Updates() {
if update.Message != nil { if update.Message != nil {
log.Printf( log.Printf(
"%s %s %s (%d) from %s (%d) says: $s", "%s %s %s (%d) from %s (%s) says: %s",
update.Message.From.Username, update.Message.From.Username,
update.Message.From.FirstName, update.Message.From.FirstName,
update.Message.From.LastName, update.Message.From.LastName,
update.Message.From.ID, update.Message.From.ID,
update.Message.Chat.Title, update.Message.Chat.Title,
update.Message.Chat.ID, update.Message.Chat.ID,
update.Message.Text update.Message.Text,
) )
if update.Message.From.ID == victim { if update.Message.From.ID == victim {
n := rand.Int() % len(speeches) n := rand.Int() % len(speeches) //nolint:gosec
var options = micha.SendMessageOptions{ReplyToMessageID: update.Message.MessageID}
var options = micha.SendMessageOptions{ReplyToMessageID: update.Message.MessageID} //nolint:exhaustivestruct
_, err = bot.SendMessage(update.Message.Chat.ID, speeches[n], &options) _, err = bot.SendMessage(update.Message.Chat.ID, speeches[n], &options)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} else { } else {