Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Create a profile and statistics system
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Ray committed Oct 25, 2018
1 parent 68f2fb7 commit 36be4da
Show file tree
Hide file tree
Showing 9 changed files with 1,211 additions and 9 deletions.
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "install",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
2 changes: 1 addition & 1 deletion commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports.run = async (client, message) => {
embed.setAuthor(`${client.user.username}`, `${client.user.avatarURL}`);
embed.setColor('RANDOM');
embed.setDescription('This is a clone of the [Moonglow](https://github.com/FCCouncil/Moonglow) GitHub repo. Join us today, and help contribute!');
embed.addField('Version', '4.1.1', true);
embed.addField('Version', '4.3.0', true);
embed.addField('Created At', `${client.user.createdAt.toLocaleString('en-US')}`, true);
embed.addField('Library', '[Discord.js](https://github.com/discordjs/discord.js)', true);
embed.addField('Language', 'JavaScript', true);
Expand Down
49 changes: 49 additions & 0 deletions commands/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const Discord = require('discord.js');

exports.run = async (client, message, args) => {
const resolvedUser = (args[0] !== undefined) ? message.guild.members.get(args[0].match(/[0-9]/g).join('')) : null;
const botuser = resolvedUser ? message.guild.members.get(resolvedUser.id) : message.member;
const thisUser = botuser.id;

const myMessages = await client.stats.get(`${thisUser} | ${message.guild.id}`);
const repPoints = await client.repPoints.get(thisUser);

const embed = new Discord.RichEmbed();
embed.setAuthor(botuser.user.tag, botuser.user.avatarURL);
embed.setTitle('Profile Card');
embed.setColor(botuser.displayHexColor);
embed.setThumbnail(botuser.user.avatarURL);
if (myMessages === undefined) {
embed.addField('Messages', 'Unknown', true);
} else {
embed.addField('Messages', myMessages, true);
}
if (repPoints === undefined) {
embed.addField('Reputation Points', '0', true);
} else {
embed.addField('Reputation Points', repPoints, true);
}
try {
embed.addField('Last Seen', botuser.lastMessage.createdAt.toLocaleString('en-US'));
} catch (err) {
embed.addField('Last Seen', 'Unknown', true);
}
embed.setFooter(client.user.username, client.user.avatarURL);
embed.setTimestamp();
await message.channel.send(embed);
};


exports.conf = {
enabled: true,
guildOnly: true,
aliases: [],
permLevel: 'Standard User'
};

exports.help = {
name: 'profile',
category: 'Fun',
description: 'Displays your profile.',
usage: 'profile'
};
41 changes: 41 additions & 0 deletions commands/rep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const cooldown = new Set();

exports.run = async (client, message, args) => {
const msg = await message.channel.send('Authenticating...');
if (cooldown.has(message.author.id)) {

const botmessage = await msg.edit(`<@!${message.author.id}>, you are being ratelimited. Chill out for a minute.`);
botmessage.delete(10000);
return;
}
const resolvedUser = (args[0] !== undefined) ? message.guild.members.get(args[0].match(/[0-9]/g).join('')) : null;
const botuser = resolvedUser ? message.guild.members.get(resolvedUser.id) : message.member;
const thisUser = botuser.id;
if (client.repPoints.get(thisUser) === undefined) {
await client.repPoints.set(thisUser, 1);
msg.edit(`***You have given a reputation point to ${botuser.user.tag}!***`);
message.channel.send('This is also their first reputation point, congratulations!');
} else {
await client.repPoints.inc(thisUser);
msg.edit(`***You have given a reputation point to ${botuser.user.tag}!***`);
}
cooldown.add(message.author.id);
setTimeout(() => {
// Removes the user from the set after a minute
cooldown.delete(message.author.id);
}, 64800000);
};

exports.conf = {
enabled: true,
guildOnly: true,
aliases: [],
permLevel: 'Standard User'
};

exports.help = {
name: 'rep',
category: 'Fun',
description: 'Gives a reputation point to another person.',
usage: 'rep [...user]'
};
2 changes: 1 addition & 1 deletion commands/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.run = (client, message) => {
embed.setAuthor(`${client.user.username}`, `${client.user.avatarURL}`);
embed.setTitle('STATISTICS');
embed.setColor('RANDOM');
embed.addField('Version', '4.1.1', false);
embed.addField('Version', '4.5.0', false);
embed.addField('• Memory Usage', `${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)} MB`, true);
embed.addField('• Uptime', `${duration}`, true);
embed.addField('• Users ', `${client.users.size.toLocaleString()}`, true);
Expand Down
10 changes: 9 additions & 1 deletion events/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ module.exports = async (client, message) => {
// If there is no guild, get default conf (DMs)
const settings = message.settings = client.getGuildSettings(message.guild);

//if (settings.stats === true) {
if (client.stats.get(`${message.member.id} | ${message.guild.id}`) === undefined) {
client.stats.set(`${message.member.id} | ${message.guild.id}`, 1);
} else {
client.stats.inc(`${message.member.id} | ${message.guild.id}`);
}
//}

// Checks if the bot was mentioned, with no message after it, returns the prefix.
const prefixMention = new RegExp(`^<@!?${client.user.id}>( |)$`);
if (message.content.match(prefixMention)) {
Expand Down Expand Up @@ -86,6 +94,6 @@ module.exports = async (client, message) => {
embed.setTimestamp();
//client.channels.get('503391943452000257').send(embed);
hook.send(embed);

cmd.run(client, message, args, level);
};
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ client.commands = new Enmap();
client.aliases = new Enmap();


client.settings = new Enmap({provider: new EnmapLevel({name: 'settings'})});
client.settings = new Enmap({provider: new EnmapLevel({name: 'settings', autoFetch: true})});

client.stats = new Enmap({provider: new EnmapLevel({name: 'stats', autoFetch: true, fetchAll: true})});

client.activatedServers = new Enmap({provider: new EnmapLevel({name: 'activatedServers', autofetch: true, fetchAll: true})});

client.repPoints = new Enmap({
name: 'reputation',
autoFetch: true,
fetchAll: true
});


const init = async () => {
Expand Down
Loading

0 comments on commit 36be4da

Please sign in to comment.