Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/chatter/updaters.go
2018-02-13 22:05:32 +04:00

44 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package chatter
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
)
// UpdateChatTitle updates chat title in database
func (ct *Chatter) UpdateChatTitle(chatRaw *dbmapping.Chat, newTitle string) (*dbmapping.Chat, bool) {
chatRaw.Name = newTitle
_, err := c.Db.NamedExec("UPDATE chats SET name=:name WHERE id=:id", &chatRaw)
if err != nil {
c.Log.Error(err)
return chatRaw, false
}
return chatRaw, true
}
// UpdateChatTelegramID updates chat's TelegramID when it converts to supergroup
func (ct *Chatter) UpdateChatTelegramID(update *tgbotapi.Update) (*dbmapping.Chat, bool) {
c.Log.Debug("Updating existing Telegram chat ID...")
chatRaw := dbmapping.Chat{}
err := c.Db.Get(&chatRaw, c.Db.Rebind("SELECT * FROM chats WHERE telegram_id=?"), update.Message.MigrateFromChatID)
if err != nil {
c.Log.Error(err.Error())
return &chatRaw, false
}
if update.Message.SuperGroupChatCreated {
chatRaw.ChatType = "supergroup"
}
chatRaw.TelegramID = update.Message.MigrateToChatID
_, err = c.Db.NamedExec("UPDATE chats SET chat_type=:chat_type, telegram_id=:telegram_id WHERE id=:id", &chatRaw)
if err != nil {
c.Log.Error(err.Error())
return &chatRaw, false
}
return &chatRaw, true
}