go fmt
This commit is contained in:
parent
ccc98b4298
commit
14afe8ff4d
@ -1,14 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"strconv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
|
||||
@ -27,11 +27,11 @@ type User struct {
|
||||
}
|
||||
|
||||
func (u User) IsAdmin() bool {
|
||||
return u.RoleBitmask & 1 == 1
|
||||
return u.RoleBitmask&1 == 1
|
||||
}
|
||||
|
||||
func (u User) IsEffectiveAdmin() bool {
|
||||
return u.RoleBitmask & 0b10 == 0b10
|
||||
return u.RoleBitmask&0b10 == 0b10
|
||||
}
|
||||
|
||||
type BotContent struct {
|
||||
@ -121,11 +121,11 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
|
||||
bc.db.First(&user, "id", UserID)
|
||||
if user == (User{}) {
|
||||
log.Printf("New user: [%d]", UserID)
|
||||
user = User{ID: UserID , State: "start"}
|
||||
user = User{ID: UserID, State: "start"}
|
||||
bc.db.Create(&user)
|
||||
}
|
||||
|
||||
bc.db.Model(&user).Update("MsgCounter", user.MsgCounter + 1)
|
||||
bc.db.Model(&user).Update("MsgCounter", user.MsgCounter+1)
|
||||
log.Printf("User[%d] messages: %d", user.ID, user.MsgCounter)
|
||||
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
@ -170,13 +170,13 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
|
||||
bc.bot.Send(tgbotapi.NewMessage(update.Message.Chat.ID, strconv.FormatInt(update.Message.Chat.ID, 10)))
|
||||
} else if possibleCommand == "/secret" && len(args) > 0 && args[0] == bc.cfg.AdminPass {
|
||||
bc.db.Model(&user).Update("state", "start")
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask | 0b11) // set real admin ID (0b1) and effective admin toggle (0b10)
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask|0b11) // set real admin ID (0b1) and effective admin toggle (0b10)
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "You are admin now!")
|
||||
bc.bot.Send(msg)
|
||||
|
||||
} else if possibleCommand == "/panel" && user.IsAdmin() {
|
||||
if !user.IsEffectiveAdmin() {
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask | 0b10)
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask|0b10)
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "You was in usermode, turned back to admin mode...")
|
||||
bc.bot.Send(msg)
|
||||
}
|
||||
@ -196,7 +196,7 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
|
||||
bc.bot.Send(msg)
|
||||
|
||||
} else if possibleCommand == "/usermode" && user.IsEffectiveAdmin() {
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask & (^uint(0b10)))
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask&(^uint(0b10)))
|
||||
log.Printf("Set role bitmask (%b) for user: %d", user.RoleBitmask, user.ID)
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Simulating user experience!")
|
||||
bc.bot.Send(msg)
|
||||
@ -326,9 +326,9 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
|
||||
if strings.HasPrefix(update.CallbackQuery.Data, "update:") {
|
||||
Label := strings.Split(update.CallbackQuery.Data, ":")[1]
|
||||
if Label == "preview_image" {
|
||||
bc.db.Model(&user).Update("state", "imgset:" + Label)
|
||||
bc.db.Model(&user).Update("state", "imgset:"+Label)
|
||||
} else {
|
||||
bc.db.Model(&user).Update("state", "stringset:" + Label)
|
||||
bc.db.Model(&user).Update("state", "stringset:"+Label)
|
||||
}
|
||||
bc.bot.Send(tgbotapi.NewMessage(user.ID, "Send me asset (text or picture (NOT as file))"))
|
||||
}
|
||||
@ -336,7 +336,7 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
|
||||
if user.IsAdmin() {
|
||||
if update.CallbackQuery.Data == "panel" {
|
||||
if !user.IsEffectiveAdmin() {
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask | 0b10)
|
||||
bc.db.Model(&user).Update("RoleBitmask", user.RoleBitmask|0b10)
|
||||
msg := tgbotapi.NewMessage(user.ID, "You was in usermode, turned back to admin mode...")
|
||||
bc.bot.Send(msg)
|
||||
}
|
||||
@ -366,7 +366,7 @@ func ProcessUpdate(bc BotController, update tgbotapi.Update) {
|
||||
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)))
|
||||
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