This repository has been archived by the owner on May 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 8d0218c
Showing
8 changed files
with
688 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,27 @@ | ||
<p align="center"><b>VimeWidget</b></p> | ||
<p align="center">Виджет с информацией о гильдии VimeWorld для группы VK.COM</p> | ||
<p align="center"> | ||
<a href="https://github.com/MrZillaGold/VimeWidget/wiki/%D0%98%D0%BD%D1%81%D1%82%D1%80%D1%83%D0%BA%D1%86%D0%B8%D1%8F">Инструкция по настройке</a> | <a href="https://vk.com/id233731786">По всем вопросам</a> | ||
</p> | ||
|
||
<p align="center"> | ||
Перед началом работы настройте <b>config.json</b>! | ||
<br/> | ||
Скрипт запускается командой <b>npm start</b>! | ||
</p> | ||
|
||
<p align="center"> | ||
<img src="https://repository-images.githubusercontent.com/252363489/813d0d80-75d4-11ea-9993-ab2755652e62"> | ||
</p> | ||
|
||
*** | ||
|
||
<p align="center"> | ||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> | ||
<img alt="Лицензия Creative Commons" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png"/> | ||
</a> | ||
<br/> | ||
<b>VimeWidget</b> доступен по | ||
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> | ||
лицензии Creative Commons «Attribution-NonCommercial-ShareAlike» («Атрибуция — Некоммерческое использование — На тех же условиях») 4.0 Всемирная</a>. | ||
</p> |
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,5 @@ | ||
{ | ||
"widget_token": "", | ||
"guild_id": 1, | ||
"icon_id": null | ||
} |
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,15 @@ | ||
import { Widget } from "./modules/widget"; | ||
|
||
const widget = new Widget(); | ||
|
||
widget.UpdateWidget(); | ||
|
||
setInterval(() => widget.UpdateWidget(), 5000); // Обновление виджета происходит раз в 15 минут, так как информация о гильдии обновляется раз в 10-15 минут. | ||
|
||
console.log("[VimeWidget] Запущен!"); | ||
|
||
// | ||
// Made with ♥ by MrZillaGold (https://vk.com/mrzillagold) | ||
// | ||
// VimeWidget доступен по лицензии Creative Commons «Attribution-NonCommercial-ShareAlike» («Атрибуция — Некоммерческое использование — На тех же условиях») 4.0 Всемирная. | ||
// |
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,27 @@ | ||
// https://gist.github.com/realmyst/1262561#gistcomment-2299442 | ||
function declOfNum(n, titles) { | ||
return titles[(n % 10 === 1 && n % 100 !== 11) ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] | ||
} | ||
|
||
function getDate(time) { | ||
const currentDate = new Date(time * 1000); | ||
|
||
const day = currentDate.getDate(); | ||
const month = currentDate.getMonth() + 1; | ||
const year = currentDate.getFullYear(); | ||
|
||
const hours = currentDate.getUTCHours() + 3; | ||
const minutes = currentDate.getMinutes(); | ||
const seconds = currentDate.getSeconds(); | ||
|
||
return `${pad(day)}.${pad(month)}.${year} ${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; | ||
|
||
function pad(s){ | ||
return (s > 9 ? "" : "0") + s; | ||
} | ||
} | ||
|
||
export { | ||
declOfNum, | ||
getDate | ||
}; |
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,188 @@ | ||
import axios from "axios"; | ||
import config from "../config"; | ||
import { declOfNum, getDate } from "./functions"; | ||
|
||
const { guild_id, widget_token, icon_id } = config; | ||
|
||
const API_ENDPOINT = "https://api.vimeworld.ru"; | ||
|
||
export class Widget { | ||
state = { | ||
guild: null, | ||
tops: [], | ||
widget: { // https://vk.com/dev/objects/appWidget?f=2.%20List | ||
title: "Гильдия - ", | ||
rows: [ | ||
{ | ||
title: "Лидер: ", | ||
descr: "", | ||
address: "", | ||
time: "Создана: ", | ||
text: "", | ||
icon_id | ||
}, | ||
{ | ||
title: "Больше всего заработали опыта:", | ||
text: "", | ||
icon_id | ||
}, | ||
{ | ||
title: "Больше всего вложили коинов:", | ||
text: "", | ||
icon_id | ||
} | ||
], | ||
more: "Хочу себе такой виджет", | ||
more_url: "https://vk.com/@mrzillagold-vimewidget" | ||
} | ||
}; | ||
|
||
async UpdateWidget() { | ||
let { guild, widget, tops } = this.state; | ||
|
||
await axios.get(`${API_ENDPOINT}/guild/get?id=${guild_id}`) // Получаем информацию о гильдии с API VimeWorld | ||
.then(response => guild = response.data) | ||
.catch(console.log); | ||
|
||
if (guild) { | ||
if (guild.error) return console.log(`[!] Ошибка при получении информации о гильдии.\n\n${guild.error.error_code} - ${guild.error.error_msg}`); | ||
|
||
widget.title += guild.name; // Имя гильдии в шапку виджета | ||
|
||
widget.rows[0].title += guild.members.filter(member => member.status === "LEADER")[0].user.username; // Ищем лидера гильдии | ||
|
||
widget.rows[0].time += getDate(guild.created); // Превращаем дату создания гильдии в человеческий вид и записываем в виджет | ||
|
||
widget.rows[0].address += `${declOfNum(guild.members.length, ["Участник", "Участника", "Участников"])}: ${guild.members.length}/${20 + guild.perks.MEMBERS.level * 5} | `; // Количество участников гильдии | ||
widget.rows[0].address += `Последний вступивший: ${guild.members.sort((a, b) => b.joined - a.joined)[0].user.username}`; // Последний вступивший в гильдию | ||
|
||
widget.rows[0].text += `Уровень: ${guild.level} [${this.GetGuildExp(guild)}/${50000 + (guild.level - 1) * 10000}] [${Math.floor(guild.levelPercentage * 100)}%]\n`; // Информация о уровне | ||
widget.rows[0].text += `Коинов вложено: ${guild.totalCoins}\n`; // Информация об общих коинах | ||
widget.rows[0].text += `Заработано опыта: ${guild.totalExp}\n\nПодробнее: vimetop.ru/guild/${guild_id}`; // Информация об общем опыте | ||
|
||
await this.GetTop(); // Получаем индекс гильдии в топе по уровню и коинам | ||
|
||
widget.rows[0].descr += `Место топа по опыту: ${tops[0] ? tops[0] : "Нет"} | Место топа по коинам: ${tops[1] ? tops[1] : "Нет"}`; // Глобальный топ по коинам и уровню | ||
|
||
await this.SortTops(guild); // Формируем топ по коинам и уровню внутри гильдии | ||
|
||
axios.get(`https://api.vk.com/method/appWidgets.update?type=list&code=return ${encodeURIComponent(JSON.stringify(widget))}%3B&access_token=${widget_token}&v=5.103`) // Обновляем виджет | ||
.then((res) => { | ||
const error = res.data.error; | ||
|
||
if (error) return console.log(`[!] Ошибка при обновлении виджета:\nКод ошибки: ${error.error_code}\n${error.error_msg}`); | ||
|
||
console.log("[VimeWidget] Виджет обновлён!") | ||
}) | ||
.catch(error => console.log(`[!] Произошла ошибка при обновлении виджета!\n${error}`)); | ||
} else { | ||
return console.log("[!] Не удалось получить информацию о гильдии, возможно произошла ошибка.") | ||
} | ||
} | ||
|
||
async GetTop() { | ||
const { tops } = this.state; | ||
|
||
const topTypes = [ | ||
{ | ||
type: "level" | ||
}, | ||
{ | ||
type: "total_coins" | ||
} | ||
]; | ||
|
||
for (let i = 0; i <= topTypes.length - 1; i++) { | ||
let top = await axios.get(`${API_ENDPOINT}/leaderboard/get/guild/${topTypes[i].type}?size=1000`); | ||
|
||
top = top.data; | ||
|
||
if (top.records[0]) { | ||
top = top.records; | ||
|
||
const index = top.findIndex(element => element.id === guild_id); | ||
|
||
tops.push(index !== -1 ? index + 1 : null); | ||
} | ||
} | ||
} | ||
|
||
SortTops(guild) { | ||
let { widget } = this.state; | ||
|
||
const sorts = [ | ||
{ | ||
forEach: member => { | ||
widget.rows[1].text += `${this.GetRank(member.user.rank)} ${member.user.username} - ${member.guildExp}\n` | ||
}, | ||
sort: (a, b) => b.guildExp - a.guildExp | ||
}, | ||
{ | ||
forEach: member => { | ||
widget.rows[2].text += `${this.GetRank(member.user.rank)} ${member.user.username} - ${member.guildCoins}\n` | ||
}, | ||
sort: (a, b) => b.guildCoins - a.guildCoins | ||
} | ||
]; | ||
|
||
sorts.forEach(functions => guild.members.sort(functions.sort).slice(0, 3).forEach(functions.forEach)) | ||
} | ||
|
||
GetGuildExp(guild) { | ||
let totalExp = guild.totalExp; | ||
|
||
for (let i = 0; i <= guild.level - 2; i++) { | ||
totalExp = totalExp - (50000 + i * 10000); | ||
} | ||
|
||
return totalExp; | ||
} | ||
|
||
GetRank(rank) { | ||
let rankName = ""; | ||
|
||
switch (rank) { | ||
case "PLAYER": | ||
break; | ||
case "VIP": | ||
rankName = "VIP"; | ||
break; | ||
case "PREMIUM": | ||
rankName = "Premium"; | ||
break; | ||
case "HOLY": | ||
rankName = "Holy"; | ||
break; | ||
case "IMMORTAL": | ||
rankName = "Immortal"; | ||
break; | ||
case "BUILDER": | ||
rankName = "Билдер"; | ||
break; | ||
case "MAPLEAD": | ||
rankName = "Гл. билдер"; | ||
break; | ||
case "YOUTUBE": | ||
rankName = "YouTube"; | ||
break; | ||
case "DEV": | ||
rankName = "Dev"; | ||
break; | ||
case "ORGANIZER": | ||
rankName = "Организатор"; | ||
break; | ||
case "MODER": | ||
case "WARDEN": | ||
rankName = "Модер"; | ||
break; | ||
case "CHIEF": | ||
rankName = "Гл. модер"; | ||
break; | ||
case "ADMIN": | ||
rankName = "Гл. админ"; | ||
break; | ||
} | ||
|
||
return rankName ? `[${rankName}]` : ""; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,31 @@ | ||
{ | ||
"name": "vimewidget", | ||
"version": "1.0.0", | ||
"description": "Виджет с информацией о гильдии VimeWorld для группы VK.COM", | ||
"main": "index.mjs", | ||
"dependencies": { | ||
"axios": "^0.19.2" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"start": "node --experimental-modules --experimental-json-modules --es-module-specifier-resolution=node index.mjs" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/MrZillaGold/VimeWidget.git" | ||
}, | ||
"keywords": [ | ||
"vimeworld", | ||
"widget", | ||
"guild" | ||
], | ||
"author": { | ||
"name": "MrZillaGold", | ||
"url": "https://vk.com/mrzillagold" | ||
}, | ||
"license": "SEE LICENSE IN LICENSE.txt", | ||
"bugs": { | ||
"url": "https://github.com/MrZillaGold/VimeWidget/issues" | ||
}, | ||
"homepage": "https://github.com/MrZillaGold/VimeWidget#readme" | ||
} |