-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
343 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
worker: node index.js | ||
worker: npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./modules/handler"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import webhook from "webhook-discord"; | ||
|
||
import config from "../config"; | ||
|
||
const name = config.discord.bot_name.slice(0, 32); | ||
const color = config.discord.color.match(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/m) ? config.discord.color : "#aabbcc"; | ||
const urls = config.discord.webhook_urls; | ||
/*const sendAll = config.discord.send_all;*/ | ||
|
||
export { | ||
webhook, | ||
name, | ||
color, | ||
urls, | ||
/*sendAll*/ | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { updates, api, longpoll, groupId, interval, filter } from "./vk"; | ||
|
||
import { webhook } from "./discord"; | ||
|
||
import { Sender } from "./sender"; | ||
|
||
if (!longpoll) { | ||
if (interval < 30000) console.log("[!] Не рекомендуем ставить интервал получения постов меньше 30 секунд, во избежания лимитов ВКонтакте!"); | ||
|
||
setInterval(() => { | ||
const sender = new Sender(); | ||
|
||
const groupIdMatch = groupId.match(/^(?:public|group)([\d]+)$/); | ||
const userIdMatch = groupId.match(/^id([\d]+)$/); | ||
const id = groupIdMatch ? | ||
{ | ||
owner_id: -groupIdMatch[1] | ||
} | ||
: | ||
userIdMatch ? | ||
{ | ||
owner_id: userIdMatch[1] | ||
} | ||
: | ||
{ | ||
domain: groupId | ||
}; | ||
|
||
api.wall.get({ | ||
...id, | ||
count: 2, | ||
extended: 1, | ||
filter: filter ? "owner" : "all", | ||
v: "5.103" | ||
}) | ||
.then(data => { | ||
const builder = new webhook.MessageBuilder(); | ||
|
||
if (data.groups.length > 0 && groupIdMatch) { // Устанавливаем footer от типа отправителя записи | ||
builder.setFooter(data.groups[0].name, data.groups[0].photo_50); | ||
} else if (data.profiles.length > 0) { | ||
builder.setFooter(`${data.profiles[0].first_name} ${data.profiles[0].last_name}`, data.profiles[0].photo_50); | ||
} | ||
|
||
const posts = data.items; // Проверяем наличие закрепа, если он есть берем свежую запись | ||
const post1 = posts[0]; | ||
const post2 = posts[1]; | ||
|
||
if (posts.length > 0) { | ||
const postData = posts.length === 2 && post2.date > post1.date ? post2 : post1; | ||
|
||
sender.Post(builder, postData); | ||
} else { | ||
console.log("[!] Не получено ни одной записи. Проверьте наличие записей в группе или измените значение фильтра в конфигурации."); | ||
} | ||
|
||
}) | ||
.catch(err => errorHandler(err)); | ||
}, interval); | ||
} else { | ||
updates.on("new_wall_post", context => { | ||
const sender = new Sender(); | ||
|
||
sender.Post(new webhook.MessageBuilder(), context.wall) | ||
}); | ||
|
||
updates.start() | ||
.then(() => console.log("[VK2DISCORD] Подключен к ВКонтакте!")) | ||
.catch(err => errorHandler(err)); | ||
} | ||
|
||
console.log("[VK2DISCORD] Запущен."); | ||
|
||
function errorHandler(error) { | ||
console.log(`[!] Возникла ошибка: ${error}. Если не понимаете в чем причина, свяжитесь со мной: https://vk.com/id233731786`); | ||
} | ||
|
||
export { | ||
errorHandler | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.