Archived
0

Начальный коммит

This commit is contained in:
eleksir
2021-07-25 12:08:40 +03:00
commit 000a780cb1
8 changed files with 274 additions and 0 deletions

55
main.go Normal file
View File

@@ -0,0 +1,55 @@
package main
import (
"io/ioutil"
"log"
"math/rand"
"os"
"strings"
"time"
"github.com/onrik/micha"
"gopkg.in/ini.v1"
)
func main() {
cfg, err := ini.Load("galichbot.ini")
if err != nil {
log.Println(err)
os.Exit(1)
}
token := cfg.Section("").Key("BotApiKey").String()
victim, err := cfg.Section("").Key("VictimID").Int64()
if err != nil {
log.Println(err)
os.Exit(1)
}
fileName := "phrases.txt"
fileBytes, err := ioutil.ReadFile(fileName)
if err != nil {
log.Println(err)
os.Exit(1)
}
speeches := strings.Split(string(fileBytes), "--")
bot, err := micha.NewBot(token)
if err != nil {
log.Println(err)
return
}
go bot.Start()
rand.Seed(time.Now().Unix())
for update := range bot.Updates() {
if update.Message != nil {
if update.Message.From.ID == victim {
n := rand.Int() % len(speeches)
var options = micha.SendMessageOptions{ReplyToMessageID: update.Message.MessageID}
_, _ = bot.SendMessage(update.Message.Chat.ID, speeches[n], &options)
}
}
}
}