lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
if obj.Message.Text == "/dump" {
var str strings.Builder
res, err := db.Query("SELECT `report_id`, `content_type` FROM `xf_report` WHERE `report_state` = 'open'")
if err != nil {
panic(err)
}
for res.Next(){
err := res.Scan(&report.Report_id, &report.Content_type)
if err != nil {
panic(err)
}
str.WriteString("New Report:\r\nId - " + strconv.Itoa(report.Report_id) + " || Type - " + report.Content_type + "\r\nLink - http://cd47468.tmweb.ru/index.php?reports/" + strconv.Itoa(report.Report_id) + "/")
// messages := []string{"New Report:\r\nId - " + strconv.Itoa(report.Report_id) + " || Type - " + report.Content_type + "\r\nLink - http://cd47468.tmweb.ru/index.php?reports/" + strconv.Itoa(report.Report_id) + "/"}
//log.Println(str.String())
send, err2 := vk.MessagesSend(api.Params{
"peer_id": 2000000001,
"random_id": 0,
"message": str.String(),
})
if err2 != nil {
log.Fatal(err2)
}
spew.Dump(send)
}
}
})
// каждый new report - новое сообщение
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/New Report:
Id - 8 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/8/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/New Report:
Id - 8 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/8/New Report:
Id - 9 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/9/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/New Report:
Id - 8 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/8/New Report:
Id - 9 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/9/New Report:
Id - 10 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/10/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/New Report:
Id - 8 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/8/New Report:
Id - 9 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/9/New Report:
Id - 10 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/10/New Report:
Id - 11 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/11/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/New Report:
Id - 8 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/8/New Report:
Id - 9 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/9/New Report:
Id - 10 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/10/New Report:
Id - 11 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/11/New Report:
Id - 12 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/12/
New Report:
Id - 2 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/2/New Report:
Id - 3 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/3/New Report:
Id - 4 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/4/New Report:
Id - 5 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/5/New Report:
Id - 6 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/6/New Report:
Id - 7 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/7/New Report:
Id - 8 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/8/New Report:
Id - 9 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/9/New Report:
Id - 10 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/10/New Report:
Id - 11 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/11/New Report:
Id - 12 || Type - post
Link - http://cd47468.tmweb.ru/index.php?reports/12/New Report:
Id - 13 || Type - profile_post
Link - http://cd47468.tmweb.ru/index.php?reports/13/
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
if obj.Message.Text == "test" {
admins, err := vk.MessagesGetConversationMembers(api.Params{
"peer_id": 2000000001,
})
if err != nil {
log.Fatal(err)
}
spew.Dump(admins.Items)
}})
([]struct { MemberID int "json:\"member_id\""; JoinDate int "json:\"join_date\""; InvitedBy int "json:\"invited_by\""; IsOwner object.BaseBoolInt "json:\"is_owner,omitempty\""; IsAdmin object.BaseBoolInt "json:\"is_admin,omitempty\""; CanKick object.BaseBoolInt "json:\"can_kick,omitempty\"" }) (len=16 cap=19) {
(struct { MemberID int "json:\"member_id\""; JoinDate int "json:\"join_date\""; InvitedBy int "json:\"invited_by\""; IsOwner object.BaseBoolInt "json:\"is_owner,omitempty\""; IsAdmin object.BaseBoolInt "json:\"is_admin,omitempty\""; CanKick object.BaseBoolInt "json:\"can_kick,omitempty\"" }) {
MemberID: (int) 380236476,
JoinDate: (int) 1610476128,
InvitedBy: (int) 380236476,
IsOwner: (object.BaseBoolInt) true,
IsAdmin: (object.BaseBoolInt) true,
CanKick: (object.BaseBoolInt) false
},
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
if obj.Message.FromID != 380236476 {
users, err := vk.MessagesDelete(api.Params{
"conversation_message_ids": obj.Message.ConversationMessageID,
"delete_for_all": 1,
"peer_id": 2000000001,
})
if err != nil {
log.Fatal(err)
}
log.Print(users)
}
})
2021/05/30 14:16:46 map[15545:1]
(api.MessagesGetByConversationMessageIDResponse) {
Count: (int) 1,
Items: ([]object.MessagesMessage) (len=1 cap=4) {
(object.MessagesMessage) {
AdminAuthorID: (int) 0,
Action: (object.MessagesMessageAction) {
ConversationMessageID: (int) 0,
Email: (string) "",
MemberID: (int) 0,
Message: (string) "",
Photo: (object.MessagesMessageActionPhoto) {
Photo100: (string) "",
Photo200: (string) "",
Photo50: (string) ""
},
Text: (string) "",
Type: (string) ""
},
Attachments: ([]object.MessagesMessageAttachment) {
},
ConversationMessageID: (int) 15534,
Date: (int) 1622212093,
FromID: (int) 380236476,
FwdMessages: ([]object.MessagesMessage) {
},
ReplyMessage: (*object.MessagesMessage)(),
Geo: (object.BaseMessageGeo) {
Coordinates: (object.BaseGeoCoordinates) {
Latitude: (float64) 0,
Longitude: (float64) 0
},
Place: (object.BasePlace) {
Address: (string) "",
Checkins: (int) 0,
City: (interface {}) ,
Country: (interface {}) ,
Created: (int) 0,
ID: (int) 0,
Icon: (string) "",
Latitude: (float64) 0,
Longitude: (float64) 0,
Title: (string) "",
Type: (string) "",
IsDeleted: (object.BaseBoolInt) false,
TotalCheckins: (int) 0,
Updated: (int) 0,
CategoryObject: (object.BaseCategoryObject) {
ID: (int) 0,
Title: (string) "",
Icons: ([]object.BaseImage)
}
},
Showmap: (int) 0,
Type: (string) ""
},
PinnedAt: (int) 0,
ID: (int) 0,
Deleted: (object.BaseBoolInt) false,
Important: (object.BaseBoolInt) false,
IsHidden: (object.BaseBoolInt) false,
IsCropped: (object.BaseBoolInt) false,
Out: (object.BaseBoolInt) false,
WasListened: (object.BaseBoolInt) false,
Keyboard: (object.MessagesKeyboard) {
AuthorID: (int) 0,
Buttons: ([][]object.MessagesKeyboardButton) ,
OneTime: (object.BaseBoolInt) false,
Inline: (object.BaseBoolInt) false
},
Template: (object.MessagesTemplate) {
Type: (string) "",
Elements: ([]object.MessagesTemplateElement)
},
Payload: (string) "",
PeerID: (int) 2000000001,
RandomID: (int) 0,
Ref: (string) "",
RefSource: (string) "",
Text: (string) (len=4) "test",
UpdateTime: (int) 0,
MembersCount: (int) 0,
ExpireTTL: (int) 0
}
},
ExtendedResponse: (object.ExtendedResponse) {
Profiles: ([]object.UsersUser) ,
Groups: ([]object.GroupsGroup)
}
}
{AdminAuthorID:0 Action:{ConversationMessageID:0 Email: MemberID:0 Message: Photo:{Photo100: Photo200: Photo50:} Text: Type:} Attachments:[] ConversationMessageID:15533 Date:1622211865 FromID:380236476 FwdMessages:[] ReplyMessage: Geo:{Coordinates:{Latitude:0 Longitude:0} Place:{Address: Checkins:0 City: Country: Created:0 ID:0 Icon: Latitude:0 Longitude:0 Title: Type: IsDeleted:false TotalCheckins:0 Updated:0 CategoryObject:{ID:0 Title: Icons:[]}} Showmap:0 Type:} PinnedAt:0 ID:0 Deleted:false Important:false IsHidden:false IsCropped:false Out:false WasListened:false Keyboard:{AuthorID:0 Buttons:[] OneTime:false Inline:false} Template:{Type: Elements:[]} Payload: PeerID:2000000001 RandomID:0 Ref: RefSource: Text:test UpdateTime:0 MembersCount:0 ExpireTTL:0}
./funcs_vk.go:101:12: no new variables on left side of :=
_, err := vk.MessagesDelete(delParamsBuilder.Params)
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
b := params.NewMessagesGetByConversationMessageIDBuilder()
if obj.Message.FromID != 380236476 {
b.PeerID(2000000001)
b.ConversationMessageIDs([]int{obj.Message.ConversationMessageID})
_, err := vk.MessagesDelete(b.Params)
// log.Printf("%s, %s" , b.Params)
if err != nil {
log.Fatal(err)
}
}
})
2021/05/28 22:07:50 api: Access denied: message can not be deleted (3)
exit status 1
map[conversation_message_ids:[%!s(int=15510)] peer_id:%!s(int=2000000001)], %!s(MISSING)
2021/05/28 17:59:02 map[conversation_message_ids:[15382] delete_for_all:true]
2021/05/28 17:59:02 api: One of the parameters specified was missing or invalid: conversation_message_ids requests peer_id parameter
2021/05/28 17:30:32 api: One of the parameters specified was missing or invalid: conversation_message_ids requests peer_id parameter
api: One of the parameters specified was missing or invalid: message_ids or conversation_message_ids is undefined
./main.go:56:10: use of package params without selector
./main.go:57:9: use of package params without selector
./main.go:59:30: use of package params without selector
https://pkg.go.dev/github.com/SevereCloud/vksdk/v2...
Здравствуйте, Данил!
У таких сообщений нет глобальных id. Для бота нужно использовать поле conversation_message_id и метод https://vk.com/dev/messages.getByConversationMessageId, чтобы получить такое сообщение. В https://vk.com/dev/messages.delete соответственно тоже есть поле conversation_message_ids, нужно использовать именно его.
С уважением,
Команда ВКонтакте
lp.MessageNew(func(_ context.Context, obj events.MessageNewObject) {
var admins = 380236475
var event = 2000000001
if obj.Message.FromID != admins{
if obj.Message.PeerID == event {
b := params.NewMessagesDeleteBuilder()
b.DeleteForAll(true)
b.MessageIDs([]int{obj.Message.ID})
_, err := vk.MessagesDelete(b.Params)
if err != nil {
log.Fatal(err)
}
}
}
})
2021/05/23 14:03:38 api: One of the parameters specified was missing or invalid: message_ids or conversation_message_ids is undefined
2021/05/23 14:05:58 api: Access denied: message can not be found
(object.MessagesMessage) {
AdminAuthorID: (int) 0,
Action: (object.MessagesMessageAction) {
ConversationMessageID: (int) 0,
Email: (string) "",
MemberID: (int) 0,
Message: (string) "",
Photo: (object.MessagesMessageActionPhoto) {
Photo100: (string) "",
Photo200: (string) "",
Photo50: (string) ""
},
Text: (string) "",
Type: (string) ""
},
Attachments: ([]object.MessagesMessageAttachment) {
},
ConversationMessageID: (int) 15116,
Date: (int) 1621701349,
FromID: (int) 259189762,
FwdMessages: ([]object.MessagesMessage) {
},
ReplyMessage: (*object.MessagesMessage)(),
Geo: (object.BaseMessageGeo) {
Coordinates: (object.BaseGeoCoordinates) {
Latitude: (float64) 0,
Longitude: (float64) 0
},
Place: (object.BasePlace) {
Address: (string) "",
Checkins: (int) 0,
City: (interface {}) ,
Country: (interface {}) ,
Created: (int) 0,
ID: (int) 0,
Icon: (string) "",
Latitude: (float64) 0,
Longitude: (float64) 0,
Title: (string) "",
Type: (string) "",
IsDeleted: (object.BaseBoolInt) false,
TotalCheckins: (int) 0,
Updated: (int) 0,
CategoryObject: (object.BaseCategoryObject) {
ID: (int) 0,
Title: (string) "",
Icons: ([]object.BaseImage)
}
},
Showmap: (int) 0,
Type: (string) ""
},
PinnedAt: (int) 0,
ID: (int) 0,
Deleted: (object.BaseBoolInt) false,
Important: (object.BaseBoolInt) false,
IsHidden: (object.BaseBoolInt) false,
IsCropped: (object.BaseBoolInt) false,
Out: (object.BaseBoolInt) false,
WasListened: (object.BaseBoolInt) false,
Keyboard: (object.MessagesKeyboard) {
AuthorID: (int) 0,
Buttons: ([][]object.MessagesKeyboardButton) ,
OneTime: (object.BaseBoolInt) false,
Inline: (object.BaseBoolInt) false
},
Template: (object.MessagesTemplate) {
Type: (string) "",
Elements: ([]object.MessagesTemplateElement)
},
Payload: (string) "",
PeerID: (int) 2000000001,
RandomID: (int) 0,
Ref: (string) "",
RefSource: (string) "",
Text: (string) (len=26) "test",
UpdateTime: (int) 0,
MembersCount: (int) 0,
ExpireTTL: (int) 0
}