Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
feat(unsub): inline button in group
Browse files Browse the repository at this point in the history
  • Loading branch information
indes committed Dec 4, 2019
1 parent 47dfe73 commit 220ce81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bot/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,12 @@ func unsubCmdCtr(m *tb.Message) {
}

func unsubFeedItemBtnCtr(c *tb.Callback) {
//model.UnsubAllByUserID()
log.Print(c.Data)

if (c.Message.Chat.Type == tb.ChatGroup || c.Message.Chat.Type == tb.ChatSuperGroup) &&
!userIsAdminOfGroup(c.Sender.ID, c.Message.Chat) {
return
}

data := strings.Split(c.Data, ":")
if len(data) == 2 {
userID, _ := strconv.Atoi(data[0])
Expand Down
17 changes: 17 additions & 0 deletions bot/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,23 @@ func CheckAdmin(upd *tb.Update) bool {
return false
}

func userIsAdminOfGroup(userID int, groupChat *tb.Chat) (isAdmin bool) {

adminList, err := B.AdminsOf(groupChat)
isAdmin = false

if err != nil {
return
}

for _, admin := range adminList {
if userID == admin.User.ID {
isAdmin = true
}
}
return
}

func UserIsAdminChannel(userID int, channelChat *tb.Chat) (isAdmin bool) {
adminList, err := B.AdminsOf(channelChat)
isAdmin = false
Expand Down

0 comments on commit 220ce81

Please sign in to comment.