Browse Source

go fmt

master
Nicolas Massé 6 years ago
parent
commit
f23dd96988
  1. 44
      main.go

44
main.go

@ -1,21 +1,21 @@
package main
import (
"log"
"os"
"io"
"net/http"
"fmt"
"strings"
"time"
"io/ioutil"
"regexp"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/spf13/viper"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strings"
"time"
"unicode"
)
var chatDB map[string]int64 = make(map[string]int64)
@ -55,7 +55,7 @@ func main() {
}
target_dir := viper.GetString("TargetDir")
if (target_dir == "") {
if target_dir == "" {
panic("No target directory provided!")
}
_, err = os.Stat(target_dir)
@ -73,7 +73,7 @@ func main() {
}
token := viper.GetString("TelegramToken")
if (token == "") {
if token == "" {
panic("No Telegram Bot Token provided!")
}
@ -99,11 +99,11 @@ func main() {
text := update.Message.Text
username := update.Message.From.UserName
if (username == "") {
if username == "" {
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgNoUsername"))
continue
}
if (! authorized_users[username]) {
if !authorized_users[username] {
log.Printf("[%s] unauthorized user", username)
replyToCommandWithMessage(bot, update.Message, viper.GetString("MsgForbidden"))
continue
@ -239,8 +239,8 @@ func updateChatDB(message *tgbotapi.Message) error {
return err
}
os.MkdirAll(target_dir + "/db/", os.ModePerm)
err = ioutil.WriteFile(target_dir + "/db/chatdb.yaml", yamlData, 0644)
os.MkdirAll(target_dir+"/db/", os.ModePerm)
err = ioutil.WriteFile(target_dir+"/db/chatdb.yaml", yamlData, 0644)
if err != nil {
return err
}
@ -284,7 +284,7 @@ func dispatchMessage(bot *tgbotapi.BotAPI, message *tgbotapi.Message) {
func handlePhoto(bot *tgbotapi.BotAPI, message *tgbotapi.Message) error {
fileId := ""
maxWidth := 0
for _, photo := range (*message.Photo) {
for _, photo := range *message.Photo {
if photo.Width > maxWidth {
fileId = photo.FileID
maxWidth = photo.Width
@ -313,7 +313,7 @@ func handlePhoto(bot *tgbotapi.BotAPI, message *tgbotapi.Message) error {
}
target_dir := viper.GetString("TargetDir")
return appendToFile(target_dir + "/data/.current/chat.yaml", yamlData)
return appendToFile(target_dir+"/data/.current/chat.yaml", yamlData)
}
func handleVideo(bot *tgbotapi.BotAPI, message *tgbotapi.Message) error {
@ -345,7 +345,7 @@ func handleVideo(bot *tgbotapi.BotAPI, message *tgbotapi.Message) error {
}
target_dir := viper.GetString("TargetDir")
return appendToFile(target_dir + "/data/.current/chat.yaml", yamlData)
return appendToFile(target_dir+"/data/.current/chat.yaml", yamlData)
}
func getFile(bot *tgbotapi.BotAPI, message *tgbotapi.Message, fileId string) (string, error) {
@ -422,7 +422,7 @@ func closeAlbum() error {
}
folderName := date.Format("2006-01-02") + "-" + sanitizeAlbumName(metadata["title"])
err = os.Rename(target_dir + "/data/.current/", target_dir + "/data/" + folderName)
err = os.Rename(target_dir+"/data/.current/", target_dir+"/data/"+folderName)
if err != nil {
return err
}
@ -454,7 +454,7 @@ func albumAlreadyOpen() bool {
func newAlbum(message *tgbotapi.Message, albumName string) error {
target_dir := viper.GetString("TargetDir")
os.MkdirAll(target_dir + "/data/.current", os.ModePerm)
os.MkdirAll(target_dir+"/data/.current", os.ModePerm)
metadata := map[string]string{
"title": albumName,
@ -469,7 +469,7 @@ func newAlbum(message *tgbotapi.Message, albumName string) error {
return err
}
err = ioutil.WriteFile(target_dir + "/data/.current/meta.yaml", yamlData, 0644)
err = ioutil.WriteFile(target_dir+"/data/.current/meta.yaml", yamlData, 0644)
if err != nil {
return err
}
@ -496,7 +496,7 @@ func addMessageToAlbum(message *tgbotapi.Message) error {
return err
}
return appendToFile(target_dir + "/data/.current/chat.yaml", yamlData)
return appendToFile(target_dir+"/data/.current/chat.yaml", yamlData)
}
func appendToFile(filename string, data []byte) error {

Loading…
Cancel
Save