Implement file recieving via user tokens
This commit is contained in:
parent
27d5e06585
commit
05766eed21
20
README.md
20
README.md
|
@ -107,11 +107,11 @@ https://oauth.vk.com/authorize?client_id=<CLIENT_ID>&display=page&redirect_uri=h
|
||||||
- [x] Auth as a user instead of group
|
- [x] Auth as a user instead of group
|
||||||
- [x] Text content
|
- [x] Text content
|
||||||
- [x] Forwards
|
- [x] Forwards
|
||||||
- [ ] Image content
|
- [x] Image content
|
||||||
- [ ] Audio content
|
- [ ] Audio content - unavailable via user tokens
|
||||||
- [ ] Video content
|
- [ ] Video content - unavailable via user tokens
|
||||||
- [ ] Stickers
|
- [x] Stickers
|
||||||
- [ ] Other files
|
- [x] Other files
|
||||||
- [ ] Presence
|
- [ ] Presence
|
||||||
- [x] Typing notifs
|
- [x] Typing notifs
|
||||||
- [x] User profiles
|
- [x] User profiles
|
||||||
|
@ -223,11 +223,11 @@ https://oauth.vk.com/authorize?client_id=<CLIENT_ID>&display=page&redirect_uri=h
|
||||||
- Вконтакте (как пользователь) -> Matrix
|
- Вконтакте (как пользователь) -> Matrix
|
||||||
- [x] Текстовые сообщения
|
- [x] Текстовые сообщения
|
||||||
- [x] Пересланные сообщения
|
- [x] Пересланные сообщения
|
||||||
- [ ] Изображения
|
- [x] Изображения
|
||||||
- [ ] Аудио
|
- [ ] Аудио - недоступно через токен пользователя
|
||||||
- [ ] Видео
|
- [ ] Видео - недоступно через токен пользователя
|
||||||
- [ ] Стикеры
|
- [x] Стикеры
|
||||||
- [ ] Прочие файлы
|
- [x] Прочие файлы
|
||||||
- [ ] Индикатор "в сети"
|
- [ ] Индикатор "в сети"
|
||||||
- [x] Индикатор печати
|
- [x] Индикатор печати
|
||||||
- [x] Имена и аватарки пользователей
|
- [x] Имена и аватарки пользователей
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "mx-puppet-vk",
|
"name": "mx-puppet-vk",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
38
src/vk.ts
38
src/vk.ts
|
@ -507,11 +507,39 @@ export class VkPuppet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context.hasAttachments()) {
|
if (context.hasAttachments()) {
|
||||||
for (const f of context.attachments) {
|
const attachments = p.data.isUserToken
|
||||||
|
? (await p.client.api.messages.getById({message_ids: context.id})).items[0].attachments!
|
||||||
|
: context.attachments;
|
||||||
|
for (const f of attachments) {
|
||||||
switch (f.type) {
|
switch (f.type) {
|
||||||
case AttachmentType.PHOTO:
|
case AttachmentType.PHOTO:
|
||||||
try {
|
try {
|
||||||
await this.puppet.sendFileDetect(params, f["largeSizeUrl"]);
|
if (p.data.isUserToken) {
|
||||||
|
// VK API is weird. Very weird.
|
||||||
|
let url: string = "";
|
||||||
|
f["photo"]["sizes"].forEach((element) => {
|
||||||
|
if (element["type"] === "w") {
|
||||||
|
url = element["url"] || "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (url === "") {
|
||||||
|
f["photo"]["sizes"].forEach((element) => {
|
||||||
|
if (element["type"] === "z") {
|
||||||
|
url = element["url"] || "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (url === undefined) {
|
||||||
|
f["photo"]["sizes"].forEach((element) => {
|
||||||
|
if (element["type"] === "y") {
|
||||||
|
url = element["url"];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
await this.puppet.sendFileDetect(params, url);
|
||||||
|
} else {
|
||||||
|
await this.puppet.sendFileDetect(params, f["largeSizeUrl"]);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const opts: IMessageEvent = {
|
const opts: IMessageEvent = {
|
||||||
body: `Image was sent: ${f["largeSizeUrl"]}`,
|
body: `Image was sent: ${f["largeSizeUrl"]}`,
|
||||||
|
@ -521,7 +549,8 @@ export class VkPuppet {
|
||||||
break;
|
break;
|
||||||
case AttachmentType.STICKER:
|
case AttachmentType.STICKER:
|
||||||
try {
|
try {
|
||||||
await this.puppet.sendFileDetect(params, f["imagesWithBackground"][4]["url"]);
|
p.data.isUserToken ? await this.puppet.sendFileDetect(params, f["sticker"]["images_with_background"][4]["url"])
|
||||||
|
: await this.puppet.sendFileDetect(params, f["imagesWithBackground"][4]["url"]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const opts: IMessageEvent = {
|
const opts: IMessageEvent = {
|
||||||
body: `Sticker was sent: ${f["imagesWithBackground"][4]["url"]}`,
|
body: `Sticker was sent: ${f["imagesWithBackground"][4]["url"]}`,
|
||||||
|
@ -541,7 +570,8 @@ export class VkPuppet {
|
||||||
break;
|
break;
|
||||||
case AttachmentType.DOCUMENT:
|
case AttachmentType.DOCUMENT:
|
||||||
try {
|
try {
|
||||||
await this.puppet.sendFileDetect(params, f["url"], f["title"]);
|
p.data.isUserToken ? await this.puppet.sendFileDetect(params, f["doc"]["url"], f["doc"]["title"])
|
||||||
|
: await this.puppet.sendFileDetect(params, f["url"], f["title"]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const opts: IMessageEvent = {
|
const opts: IMessageEvent = {
|
||||||
body: `Document was sent: ${f["url"]}`,
|
body: `Document was sent: ${f["url"]}`,
|
||||||
|
|
Loading…
Reference in a new issue