diff --git a/commands/Economy/profile.js b/commands/Economy/profile.js
index 8489b82e..ae23fd60 100644
--- a/commands/Economy/profile.js
+++ b/commands/Economy/profile.js
@@ -63,6 +63,7 @@ class Profile extends Command {
})
})
.setImage("attachment://achievements.png")
+ .addField(this.client.customEmojis.link + " " + message.translate("economy/profile:LINK"), `[${message.translate("economy/profile:LINK_TEXT")}](https://jaba.pp.ua/user/${member.user.id}/${message.guild.id})`)
.addField(message.translate("economy/profile:BIO"), userData.bio ? userData.bio : message.translate("economy/profile:NO_BIO"))
.addField(message.translate("economy/profile:CASH"), `**${memberData.money}** ${message.getNoun(memberData.money, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`, true)
.addField(message.translate("economy/profile:BANK"), `**${memberData.bankSold}** ${message.getNoun(memberData.bankSold, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`, true)
diff --git a/commands/General/serverinfo.js b/commands/General/serverinfo.js
index a4c42b0a..5d741827 100644
--- a/commands/General/serverinfo.js
+++ b/commands/General/serverinfo.js
@@ -41,13 +41,14 @@ class Serverinfo extends Command {
.setThumbnail(guild.iconURL({
dynamic: true
}))
+ .addField(this.client.customEmojis.link + " " + message.translate("general/serverinfo:LINK"), `[${message.translate("general/serverinfo:LINK_TEXT")}](https://jaba.pp.ua/stats/${guild.id})`)
.addField(this.client.customEmojis.title + message.translate("common:NAME"), guild.name, true)
.addField(this.client.customEmojis.calendar + message.translate("common:CREATION"), message.printDate(guild.createdAt), true)
.addField(this.client.customEmojis.users + message.translate("common:MEMBERS"),
`${guild.members.cache.filter(m => !m.user.bot).size} ${message.getNoun(guild.members.cache.filter(m => !m.user.bot).size, message.translate("misc:NOUNS:MEMBERS:1"), message.translate("misc:NOUNS:MEMBERS:2"), message.translate("misc:NOUNS:MEMBERS:5"))}` +
"\n" + `${guild.members.cache.filter(m => m.user.bot).size} ${message.getNoun(guild.members.cache.filter(m => m.user.bot).size, message.translate("misc:NOUNS:BOTS:1"), message.translate("misc:NOUNS:BOTS:2"), message.translate("misc:NOUNS:BOTS:5"))}`, true
)
- .addField(this.client.customEmojis.afk + message.translate("general/serverinfo:AFK_CHANNEL"), guild.afkChannel.toString() || message.translate("general/serverinfo:NO_AFK_CHANNEL"), true)
+ .addField(this.client.customEmojis.afk + message.translate("general/serverinfo:AFK_CHANNEL"), guild.afkChannel ? guild.afkChannel.toString() : message.translate("general/serverinfo:NO_AFK_CHANNEL"), true)
.addField(this.client.customEmojis.id + message.translate("common:ID"), guild.id, true)
.addField(this.client.customEmojis.crown + message.translate("common:OWNER"), owner.toString(), true)
.addField(this.client.customEmojis.boost + message.translate("general/serverinfo:BOOSTS"), guild.premiumSubscriptionCount.toString() || "0", true)
diff --git a/commands/General/someone.js b/commands/General/someone.js
index 26925fcc..4419c69a 100644
--- a/commands/General/someone.js
+++ b/commands/General/someone.js
@@ -6,7 +6,7 @@ class Someone extends Command {
super(client, {
name: "someone",
dirname: __dirname,
- enabled: true,
+ enabled: false,
guildOnly: true,
aliases: ["somebody"],
memberPermissions: [],
diff --git a/commands/General/stats.js b/commands/General/stats.js
index a790a14f..9cb445c7 100644
--- a/commands/General/stats.js
+++ b/commands/General/stats.js
@@ -46,14 +46,13 @@ class Stats extends Command {
.addField(message.translate("general/stats:CREDITS_TITLE"), message.translate("general/stats:CREDITS_CONTENT", {
donators: ["**`Добрый Спецназ#8801`** - Тестер, генератор идей"].join("\n"),
translators: ["**`Jonny_Bro#4226`** (:flag_ru:)"].join("\n")
+ }))
+ .addField(this.client.customEmojis.link + " " + message.translate("general/stats:LINKS_TITLE"), message.translate("misc:STATS_FOOTER", {
+ dashboardLink: "https://jaba.pp.ua/",
+ docsLink: "https://jaba.pp.ua/docs/",
+ donateLink: "https://qiwi.com/n/JONNYBRO/",
+ owner: this.client.config.owner.id
}));
-
- statsEmbed.addField(this.client.customEmojis.link + " " + message.translate("general/stats:LINKS_TITLE"), message.translate("misc:STATS_FOOTER", {
- dashboardLink: "https://jaba.pp.ua/",
- docsLink: "https://jaba.pp.ua/docs/",
- donateLink: "https://qiwi.com/n/JONNYBRO/",
- owner: this.client.config.owner.id
- }));
message.channel.send({
embeds: [statsEmbed]
});
diff --git a/commands/Owner/eval.js b/commands/Owner/eval.js
index 291808a5..4fc8d174 100644
--- a/commands/Owner/eval.js
+++ b/commands/Owner/eval.js
@@ -1,3 +1,4 @@
+/* eslint-disable no-unused-vars */
const Command = require("../../base/Command");
class Eval extends Command {
@@ -16,7 +17,7 @@ class Eval extends Command {
});
}
- async run(message) {
+ async run(message, data) {
const content = message.content.split(" ").slice(1).join(" ");
const result = new Promise((resolve) => resolve(eval(content)));
diff --git a/dashboard/app.js b/dashboard/app.js
index f57aed21..ec107f41 100644
--- a/dashboard/app.js
+++ b/dashboard/app.js
@@ -14,6 +14,7 @@ module.exports.load = async(client) => {
discordAPIRouter = require("./routes/discord"),
logoutRouter = require("./routes/logout"),
profileRouter = require("./routes/profile"),
+ userRouter = require("./routes/user"),
guildStatsRouter = require("./routes/guild-stats"),
guildManagerRouter = require("./routes/guild-manager"),
docsManagerRouter = require("./routes/docs");
@@ -52,6 +53,7 @@ module.exports.load = async(client) => {
.use("/manage", guildManagerRouter)
.use("/stats", guildStatsRouter)
.use("/profile", profileRouter)
+ .use("/user", userRouter)
.use("/", mainRouter)
.use("/docs", docsManagerRouter)
.use(CheckAuth, function(req, res) {
diff --git a/dashboard/public/docs/updates.md b/dashboard/public/docs/updates.md
index 4fbf2ec8..6369d0a4 100644
--- a/dashboard/public/docs/updates.md
+++ b/dashboard/public/docs/updates.md
@@ -1,3 +1,12 @@
+### JaBa v3.2.7
+* Добавлено
+ * Статистика сервера на сайте ([пример](https://jaba.pp.ua/stats/651412418202959872)).
+ * Профиль пользователя определённого сервера на сайте ([пример](https://jaba.pp.ua/user/281361531411890186/651412418202959872))
+ Ссылки на статистику сервера и профиль пользователя можно найти в *serverinfo* и *profile (@пользователь)* соответственно.
+
+* Изменения
+ * Отключены команда *someone* и тэг *@someone*.
+
### JaBa v3.2.7
* Добавлено
* Некоторая информация о вашем профиле на сайте, на страницах серверов и в настройках.
@@ -15,7 +24,6 @@
* Команда *setafk* и ответ бота автоматически удаляются через 10 секунд.
* Новые карточки при входе и выходе пользователей
(Я не дизайнер, не бейте :().
- * Обновлена локализация для карточек.
### JaBa v3.2.5
* Изменения
@@ -77,7 +85,6 @@
* Некорректное описание *seek*.
* Некорректная работа *seek*.
* Некорректное описание *unban*.
- * Мелкие правки в локализации.
### JaBa v3.1.5
* Изменено
@@ -114,7 +121,7 @@
### JaBa v3.1
* Изменено
- * Обновлена русская локализация, исправлены орфографические ошибки.
+ * Исправлены орфографические ошибки в русской локализации.
* Отключёна английская локализация.
* Исправлены ошибки.
diff --git a/dashboard/routes/commands.js b/dashboard/routes/commands.js
deleted file mode 100644
index e73018bb..00000000
--- a/dashboard/routes/commands.js
+++ /dev/null
@@ -1,19 +0,0 @@
-const express = require("express"),
- router = express.Router(),
- fs = require("fs"),
- marked = require("marked");
-
-router.get("/", function (req, res) {
- var md = function (filename) {
- return marked.parse(fs.readFileSync("./dashboard/views/docs/" + filename, "utf8"));
- };
-
- res.render("commands", {
- user: req.userInfos,
- translate: req.translate,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`,
- "md": md
- });
-});
-
-module.exports = router;
\ No newline at end of file
diff --git a/dashboard/routes/docs.js b/dashboard/routes/docs.js
index 3745d7c3..40f55f68 100644
--- a/dashboard/routes/docs.js
+++ b/dashboard/routes/docs.js
@@ -5,7 +5,7 @@ router.get("/", function (req, res) {
res.render("docs", {
user: req.userInfos,
translate: req.translate,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
});
diff --git a/dashboard/routes/guild-manager.js b/dashboard/routes/guild-manager.js
index ecaa3a99..61b59151 100644
--- a/dashboard/routes/guild-manager.js
+++ b/dashboard/routes/guild-manager.js
@@ -10,7 +10,7 @@ router.get("/:serverID", CheckAuth, async(req, res) => {
return res.render("404", {
user: req.userInfos,
translate: req.translate,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
}
@@ -25,7 +25,7 @@ router.get("/:serverID", CheckAuth, async(req, res) => {
translate: req.translate,
bot: req.client,
convertTime: req.convertTime,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
});
@@ -36,7 +36,7 @@ router.post("/:serverID", CheckAuth, async(req, res) => {
return res.render("404", {
user: req.userInfos,
translate: req.translate,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
}
@@ -44,7 +44,7 @@ router.post("/:serverID", CheckAuth, async(req, res) => {
const data = req.body;
if (data.language) {
- const language = req.client.languages.find((language) => language.aliases[0].toLowerCase() === data.language.toLowerCase());
+ const language = req.client.languages.find((language) => language.nativeName.toLowerCase() === data.language.toLowerCase());
if (language) guildData.language = language.name;
if (data.prefix.length >= 1 && data.prefix.length < 2000) guildData.prefix = data.prefix;
diff --git a/dashboard/routes/guild-stats.js b/dashboard/routes/guild-stats.js
index f0057c03..09184d74 100644
--- a/dashboard/routes/guild-stats.js
+++ b/dashboard/routes/guild-stats.js
@@ -1,28 +1,27 @@
const express = require("express"),
utils = require("../utils"),
CheckAuth = require("../auth/CheckAuth"),
- router = express.Router(),
- generator = require("colors-generator");
+ router = express.Router();
-router.get("/:serverID", CheckAuth, async(req, res) => {
+router.get("/:serverID", CheckAuth, async (req, res) => {
// Check if the user has the permissions to edit this guild
const guild = req.client.guilds.cache.get(req.params.serverID);
if (!guild || !req.userInfos.displayedGuilds || !req.userInfos.displayedGuilds.find((g) => g.id === req.params.serverID)) {
return res.render("404", {
user: req.userInfos,
- language: req.language,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ translate: req.translate,
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
}
// Fetch guild informations
- const guildInfos = await utils.fetchGuild(guild.id, req.client, req.user.guilds);
-
- const membersData = await req.client.membersData.find({ guildID: guild.id }).lean();
+ const membersData = await req.client.membersData.find({
+ guildID: guild.id
+ }).lean();
const leaderboards = {
- money: sortArrayOfObjects("money", membersData),
- level: sortArrayOfObjects("level", membersData)
+ money: utils.sortArrayOfObjects("money", membersData),
+ level: utils.sortArrayOfObjects("level", membersData)
};
for (const cat in leaderboards) {
@@ -36,77 +35,13 @@ router.get("/:serverID", CheckAuth, async(req, res) => {
};
res.render("stats/guild", {
- stats,
- commands: getCommands(guildInfos.commands.filter((c) => c.date > Date.now()-604800000)),
- commandsUsage: getCommandsUsage(guildInfos.commands),
user: req.userInfos,
- language: req.language,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`,
+ stats,
+ bot: req.client,
+ guildID: guild.id,
+ translate: req.translate,
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`,
});
});
-module.exports = router;
-
-function getCommands(commands) {
- const aDateCommand = {};
- commands.forEach((cmd) => {
- const tDate = formatDate(new Date(cmd.date));
- if (aDateCommand[tDate]) aDateCommand[tDate]++;
- else aDateCommand[tDate] = 1;
- });
- return aDateCommand;
-}
-
-function getCommandsUsage(commands) {
- const objectCount = commands.reduce((acc, curr) => {
- if (typeof acc[curr.command] == "undefined") acc[curr.command] = 1;
- else acc[curr.command] += 1;
-
- return acc;
- }, {});
- const percentages = getPercentagePerKey(objectCount); // [ { key: "help", percentage: 20 } ]
- const colors = generator.generate("#86bff2", percentages.length).get();
- let i = 0;
- percentages.forEach((p) => {
- p.color = colors[i];
- i++;
- });
-
- return percentages;
-}
-
-function getPercentagePerKey(myArray) {
- const sum = getSum(myArray);
- const arrayWithPercentages = [];
- for (const key in myArray) {
- const val = myArray[key];
- const percentage = Math.round((val / sum) * 100);
- arrayWithPercentages.push({key, percentage});
- }
-
- return arrayWithPercentages;
-}
-
-function getSum(myArray) {
- let sum = 0;
- for (const key in myArray) sum += myArray[key];
-
- return sum;
-}
-
-function sortArrayOfObjects(key, arr) {
- const array = arr.slice(0);
- return array.sort((a, b) => {
- return b[key] - a[key];
- });
-}
-
-function formatDate(date) {
- let dd = date.getDate();
- let mm = date.getMonth() + 1;
- if (dd < 10) dd = `0${dd}`;
- if (mm < 10) mm = `0${mm}`;
- date = `${mm}/${dd}`;
-
- return date;
-}
\ No newline at end of file
+module.exports = router;
\ No newline at end of file
diff --git a/dashboard/routes/index.js b/dashboard/routes/index.js
index a69a610c..0b1a60e4 100644
--- a/dashboard/routes/index.js
+++ b/dashboard/routes/index.js
@@ -10,7 +10,7 @@ router.get("/selector", CheckAuth, async(req, res) => {
res.render("selector", {
user: req.userInfos,
translate: req.translate,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
});
diff --git a/dashboard/routes/profile.js b/dashboard/routes/profile.js
index 7097787c..8420c0e4 100644
--- a/dashboard/routes/profile.js
+++ b/dashboard/routes/profile.js
@@ -6,9 +6,10 @@ const express = require("express"),
router.get("/", CheckAuth, async function(req, res) {
res.render("profile", {
user: req.userInfos,
+ bot: req.client,
translate: req.translate,
printDate: req.printDate,
- currentURL: `${req.client.config.dashboard.baseURL}/${req.originalUrl}`
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
});
diff --git a/dashboard/routes/user.js b/dashboard/routes/user.js
new file mode 100644
index 00000000..3ed3e3d3
--- /dev/null
+++ b/dashboard/routes/user.js
@@ -0,0 +1,38 @@
+const express = require("express"),
+ utils = require("../utils"),
+ CheckAuth = require("../auth/CheckAuth"),
+ router = express.Router();
+
+// Gets user page
+router.get("/:userID/:serverID", CheckAuth, async function (req, res) {
+ const guild = req.client.guilds.cache.get(req.params.serverID);
+ if (!guild || !req.userInfos.displayedGuilds || !req.userInfos.displayedGuilds.find((g) => g.id === req.params.serverID)) {
+ return res.render("404", {
+ user: req.userInfos,
+ translate: req.translate,
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
+ });
+ }
+
+ const guildData = await req.client.findOrCreateGuild({ id: guild.id });
+ await utils.fetchUser({
+ id: req.params.userID
+ }, req.client).catch(() => {
+ res.render("404", {
+ user: req.userInfos,
+ translate: req.translate,
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
+ });
+ });
+
+ res.render("user", {
+ user: req.userInfos,
+ guild: guildData,
+ bot: req.client,
+ translate: req.translate,
+ printDate: req.printDate,
+ currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
+ });
+});
+
+module.exports = router;
\ No newline at end of file
diff --git a/dashboard/utils.js b/dashboard/utils.js
index a3697953..1ce1ec31 100644
--- a/dashboard/utils.js
+++ b/dashboard/utils.js
@@ -1,18 +1,5 @@
const { Permissions } = require("discord.js");
-/**
- * Fetch guild informations
- * @param {string} guildID The ID of the guild to fetch
- * @param {object} client The discord client instance
- * @param {array} guilds The user guilds
- */
-async function fetchGuild(guildID, client, guilds) {
- const guild = client.guilds.cache.get(guildID);
- const conf = await client.findOrCreateGuild({ id:guild.id });
-
- return { ...guild, ...conf.toJSON(), ...guilds.find((g) => g.id === guild.id) };
-}
-
/**
* Fetch user informations (stats, guilds, etc...)
* @param {object} userData The oauth2 user informations
@@ -24,6 +11,7 @@ async function fetchUser(userData, client, query) {
if (userData.guilds) {
userData.guilds.forEach((guild) => {
if (!client.guilds.cache.get(guild.id)) return;
+ // eslint-disable-next-line no-undef
const perms = new Permissions(BigInt(guild.permissions));
if (perms.has(Permissions.FLAGS.MANAGE_GUILD)) guild.admin = true;
@@ -36,10 +24,72 @@ async function fetchUser(userData, client, query) {
if (userData.displayedGuilds.length < 1) delete userData.displayedGuilds;
}
const user = await client.users.fetch(userData.id);
- const userDb = await client.findOrCreateUser({ id: user.id }, true);
- const userInfos = { ...user.toJSON(), ...userDb, ...userData };
+ const userDb = await client.findOrCreateUser({
+ id: user.id
+ }, true);
+ const userInfos = {
+ ...user.toJSON(),
+ ...userDb,
+ ...userData
+ };
return userInfos;
}
-module.exports = { fetchUser, fetchGuild };
\ No newline at end of file
+/**
+ * Fetch users informations
+ * @param {object} array The array of users
+ * @param {object} client The discord client instance
+ * @returns {object} The user informations
+ */
+async function fetchUsers(array, client) {
+ return new Promise((resolve) => {
+ const users = [];
+ array.filter((e) => e.id).forEach((element) => {
+ client.users.fetch(element.id).then((user) => {
+ user.username = user.username.replace(/[\W_]+/g, " ");
+ if (user.username.length > 13) {
+ user.username = user.username.substr(0, 10) + "...";
+ }
+ users.push({
+ ...{
+ money: element.money,
+ level: element.level,
+ rep: element.rep
+ },
+ ...user.toJSON()
+ });
+ });
+ });
+ resolve(users);
+ });
+}
+
+/**
+ * Fetch guild informations
+ * @param {string} guildID The ID of the guild to fetch
+ * @param {object} client The discord client instance
+ * @param {array} guilds The user guilds
+ * @returns {object} The guild informations
+ */
+async function fetchGuild(guildID, client, guilds) {
+ const guild = client.guilds.cache.get(guildID);
+ const conf = await client.findOrCreateGuild({
+ id: guild.id
+ });
+
+ return {
+ ...guild,
+ ...conf.toJSON(),
+ ...guilds.find((g) => g.id === guild.id)
+ };
+}
+
+function sortArrayOfObjects(key, arr) {
+ const array = arr.slice(0);
+ return array.sort((a, b) => {
+ return b[key] - a[key];
+ });
+}
+
+module.exports = { fetchUser, fetchUsers, fetchGuild, sortArrayOfObjects };
\ No newline at end of file
diff --git a/dashboard/views/404.ejs b/dashboard/views/404.ejs
index 4693dacd..5186618f 100644
--- a/dashboard/views/404.ejs
+++ b/dashboard/views/404.ejs
@@ -16,7 +16,7 @@
- 404 Error Page
+ Ошибка 404
- 500 Error Page
+ Ошибка 500