Fix channel id changing
This commit is contained in:
parent
c2e3ff8e74
commit
37097eb58f
@ -86,7 +86,9 @@ func (bc BotController) GetBotContent(Literal string) string {
|
|||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
func (bc BotController) SetBotContent(Literal string, Content string) {
|
func (bc BotController) SetBotContent(Literal string, Content string) {
|
||||||
bc.db.Create(&BotContent{Literal: Literal, Content: Content})
|
c := BotContent{Literal: Literal, Content: Content}
|
||||||
|
bc.db.FirstOrCreate(&c, "Literal", Literal)
|
||||||
|
bc.db.Model(&c).Update("Content", Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -130,7 +132,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
img, err := bc.GetBotContentVerbose("preview_image")
|
img, err := bc.GetBotContentVerbose("preview_image")
|
||||||
if err != nil {
|
if err != nil || img == "" {
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, bc.GetBotContent("start"))
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, bc.GetBotContent("start"))
|
||||||
// msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hello, [user](tg://user?id=958170391)")
|
// msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Hello, [user](tg://user?id=958170391)")
|
||||||
msg.ParseMode = "markdown"
|
msg.ParseMode = "markdown"
|
||||||
@ -185,7 +187,7 @@ func main() {
|
|||||||
if update.Message.Text == "unset" {
|
if update.Message.Text == "unset" {
|
||||||
var l BotContent
|
var l BotContent
|
||||||
bc.db.First(&l, "Literal", Literal)
|
bc.db.First(&l, "Literal", Literal)
|
||||||
bc.db.Delete(l)
|
bc.SetBotContent(Literal, "")
|
||||||
}
|
}
|
||||||
maxsize := 0
|
maxsize := 0
|
||||||
fileid := ""
|
fileid := ""
|
||||||
@ -196,13 +198,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bc.SetBotContent(Literal, fileid)
|
bc.SetBotContent(Literal, fileid)
|
||||||
} else if strings.HasPrefix(user.State, "stringset:") {
|
|
||||||
Literal := strings.Split(user.State, ":")[1]
|
|
||||||
bc.SetBotContent(Literal, update.Message.Text)
|
|
||||||
}
|
|
||||||
bc.db.Model(&user).Update("state", "start")
|
bc.db.Model(&user).Update("state", "start")
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Succesfully set new image!")
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Succesfully set new image!")
|
||||||
bc.bot.Send(msg)
|
bc.bot.Send(msg)
|
||||||
|
} else if strings.HasPrefix(user.State, "stringset:") {
|
||||||
|
Literal := strings.Split(user.State, ":")[1]
|
||||||
|
bc.SetBotContent(Literal, update.Message.Text)
|
||||||
|
bc.db.Model(&user).Update("state", "start")
|
||||||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Succesfully set new text!")
|
||||||
|
bc.bot.Send(msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if user.State == "leaveticket" {
|
if user.State == "leaveticket" {
|
||||||
@ -216,7 +221,7 @@ func main() {
|
|||||||
chatidstr, err := bc.GetBotContentVerbose("supportchatid")
|
chatidstr, err := bc.GetBotContentVerbose("supportchatid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var admins []User
|
var admins []User
|
||||||
bc.db.Where("RoleBitmask & 1 = ?", 1).Find(&admins)
|
bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins)
|
||||||
for _, admin := range admins {
|
for _, admin := range admins {
|
||||||
msg := tgbotapi.NewMessage(admin.ID, "Support ChatID is not set!!!")
|
msg := tgbotapi.NewMessage(admin.ID, "Support ChatID is not set!!!")
|
||||||
msg.Entities = []tgbotapi.MessageEntity{tgbotapi.MessageEntity{
|
msg.Entities = []tgbotapi.MessageEntity{tgbotapi.MessageEntity{
|
||||||
@ -248,7 +253,7 @@ func main() {
|
|||||||
chatidstr, err := bc.GetBotContentVerbose("channelid")
|
chatidstr, err := bc.GetBotContentVerbose("channelid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var admins []User
|
var admins []User
|
||||||
bc.db.Where("RoleBitmask & 1 = ?", 1).Find(&admins)
|
bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins)
|
||||||
for _, admin := range admins {
|
for _, admin := range admins {
|
||||||
bc.bot.Send(tgbotapi.NewMessage(admin.ID, "ChannelID is not set!!!"))
|
bc.bot.Send(tgbotapi.NewMessage(admin.ID, "ChannelID is not set!!!"))
|
||||||
}
|
}
|
||||||
@ -308,6 +313,19 @@ func main() {
|
|||||||
bc.bot.Send(msg)
|
bc.bot.Send(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if update.ChannelPost != nil { // TODO
|
||||||
|
post := update.ChannelPost
|
||||||
|
if post.Text == "setchannelid" {
|
||||||
|
bc.SetBotContent("channelid", strconv.FormatInt(post.SenderChat.ID, 10))
|
||||||
|
|
||||||
|
var admins []User
|
||||||
|
bc.db.Where("role_bitmask & 1 = ?", 1).Find(&admins)
|
||||||
|
for _, admin := range admins {
|
||||||
|
bc.bot.Send(tgbotapi.NewMessage(admin.ID, "ChannelID is set to " + strconv.FormatInt(post.SenderChat.ID, 10)))
|
||||||
|
delcmd := tgbotapi.NewDeleteMessage(post.SenderChat.ID, post.MessageID)
|
||||||
|
bc.bot.Send(delcmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user