Skip to content

Commit 664eec2

Browse files
authored
Add files via upload
1 parent 97b70ff commit 664eec2

File tree

7 files changed

+266
-0
lines changed

7 files changed

+266
-0
lines changed

config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"TOKEN": "",
3+
"PREFIX": "?"
4+
}

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const Discord = require("discord.js"); //load the Discord.js Library
2+
const client = new Discord.Client(); //make a new Client
3+
const config = require("./config.json"); //load the config.json file
4+
const Enmap = require("enmap") //load the enmap library
5+
const canvacord = require("canvacord") //load the canvacord library
6+
client.points = new Enmap({ name: "points" }); //For ranking system
7+
client.on("ready", ()=>console.log("READY")); //log when the bot gets ready
8+
const leveling = require("./ranking"); //load the leveling file
9+
leveling(client); //call the leveling file with the client
10+
client.login(config.TOKEN); //start the bot with the bot token
11+
//Bot coded by Tomato#6966

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "jointocreatebot",
3+
"version": "1.0.0",
4+
"description": "A Basic OP JointoCreate BOT",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "node index.js"
9+
},
10+
"author": "Tomato#6966",
11+
"license": "GPL-3.0",
12+
"dependencies": {
13+
"canvacord": "^5.0.8",
14+
"discord.js": "^12.4.1",
15+
"enmap": "^5.8.2",
16+
"node.js": "0.0.1-security"
17+
}
18+
}

ranking.js

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
const config = require("./config.json");
2+
const canvacord = require("canvacord");
3+
const Discord = require("discord.js");
4+
5+
module.exports = function (client) {
6+
const description = {
7+
name: "leveling",
8+
filename: "leveling.js",
9+
version: "2.0"
10+
}
11+
//log that the module is loaded
12+
console.log(` :: ⬜️ Module: ${description.name} | Loaded version ${description.version} from ("${description.filename}")`)
13+
//voice state update event to check joining/leaving channels
14+
client.on("message", async (message) => {
15+
16+
if (message.author.bot) return;
17+
if (!message.guild) return;
18+
if (message.channel.type === `dm`) return;
19+
//////////////////////////////////////////
20+
/////////////RANKING SYSTEM///////////////
21+
//////////////////////////////////////////
22+
//get the key of the user for this guild
23+
const key = `${message.guild.id}-${message.author.id}`;
24+
// do some databasing
25+
client.points.ensure(`${message.guild.id}-${message.author.id}`, {
26+
user: message.author.id,
27+
guild: message.guild.id,
28+
points: 0,
29+
level: 1
30+
});
31+
//create message length basically math for not too much xp for too long messages
32+
var msgl = message.content.length / (Math.floor(Math.random() * (message.content.length - message.content.length / 100 + 1) + 10));
33+
//if too short the message
34+
if (msgl < 10) {
35+
//get a random num between 0 and 2 rounded
36+
var randomnum = Math.floor((Math.random() * 2) * 100) / 100
37+
//basically databasing again
38+
client.points.math(key, `+`, randomnum, `points`)
39+
client.points.inc(key, `points`);
40+
}
41+
//if not too short do this
42+
else {
43+
//get a random num between rounded but it belongs to message length
44+
var randomnum = 1 + Math.floor(msgl * 100) / 100
45+
//basically databasing again
46+
client.points.math(key, `+`, randomnum, `points`)
47+
client.points.inc(key, `points`);
48+
}
49+
//get current level
50+
const curLevel = Math.floor(0.1 * Math.sqrt(client.points.get(key, `points`)));
51+
//if its a new level then do this
52+
if (client.points.get(key, `level`) < curLevel) {
53+
//define ranked embed
54+
const embed = new Discord.MessageEmbed()
55+
.setTitle(`Ranking of: ${message.author.username}`)
56+
.setTimestamp()
57+
.setDescription(`You've leveled up to Level: **\`${curLevel}\`**! (Points: \`${Math.floor(client.points.get(key, `points`) * 100) / 100}\`) `)
58+
.setColor("GREEN");
59+
//send ping and embed message
60+
message.channel.send(`<@` + message.author.id + `>`);
61+
message.channel.send(embed);
62+
//set the new level
63+
client.points.set(key, curLevel, `level`);
64+
}
65+
//else continue or commands...
66+
//
67+
if (message.content.toLowerCase().startsWith(`${config.PREFIX}rank`)) {
68+
//get the rankuser
69+
rankuser = message.mentions.users.first() || message.author;
70+
//do some databasing
71+
const filtered = client.points.filter(p => p.guild === message.guild.id).array();
72+
const sorted = filtered.sort((a, b) => b.points - a.points);
73+
const top10 = sorted.splice(0, message.guild.memberCount);
74+
let i = 0;
75+
//count server rank sometimes an error comes
76+
for (const data of top10) {
77+
await delay(15);
78+
try {
79+
i++;
80+
if (client.users.cache.get(data.user).tag === rankuser.tag) break;
81+
} catch {
82+
i = `Error counting Rank`;
83+
break;
84+
}
85+
}
86+
const key = `${message.guild.id}-${rankuser.id}`;
87+
//math
88+
let curpoints = Number(client.points.get(key, `points`).toFixed(2));
89+
//math
90+
let curnextlevel = Number(((Number(1) + Number(client.points.get(key, `level`).toFixed(2))) * Number(10)) * ((Number(1) + Number(client.points.get(key, `level`).toFixed(2))) * Number(10)));
91+
//if not level == no rank
92+
if (client.points.get(key, `level`) === undefined) i = `No Rank`;
93+
//define a temporary embed so its not coming delayed
94+
let tempmsg = await message.channel.send(new Discord.MessageEmbed().setColor("RED").setAuthor("Calculating...", "https://cdn.discordapp.com/emojis/769935094285860894.gif"))
95+
//global local color var.
96+
let color;
97+
//define status of the rankuser
98+
let status = rankuser.presence.status;
99+
//do some coloring for user status cause cool
100+
if (status === "dnd") { color = "#ff0048"; }
101+
else if (status === "online") { color = "#00fa81"; }
102+
else if (status === "idle") { color = "#ffbe00"; }
103+
else { status = "streaming"; color = "#a85fc5"; }
104+
//define the ranking card
105+
const rank = new canvacord.Rank()
106+
.setAvatar(rankuser.displayAvatarURL({ dynamic: false, format: 'png' }))
107+
.setCurrentXP(Number(curpoints.toFixed(2)), color)
108+
.setRequiredXP(Number(curnextlevel.toFixed(2)), color)
109+
.setStatus(status, false, 7)
110+
.renderEmojis(true)
111+
.setProgressBar(color, "COLOR")
112+
.setRankColor(color, "COLOR")
113+
.setLevelColor(color, "COLOR")
114+
.setUsername(rankuser.username, color)
115+
.setRank(Number(i), "Rank", true)
116+
.setLevel(Number(client.points.get(key, `level`)), "Level", true)
117+
.setDiscriminator(rankuser.discriminator, color);
118+
rank.build()
119+
.then(async data => {
120+
//add rankcard to attachment
121+
const attachment = new Discord.MessageAttachment(data, "RankCard.png");
122+
//define embed
123+
const embed = new Discord.MessageEmbed()
124+
.setTitle(`Ranking of: ${rankuser.username}`)
125+
.setColor(color)
126+
.setImage("attachment://RankCard.png")
127+
.attachFiles(attachment)
128+
//send that embed
129+
await message.channel.send(embed);
130+
//delete that temp message
131+
await tempmsg.delete();
132+
return;
133+
});
134+
}
135+
//leaderboard command
136+
if (message.content.toLowerCase() === `${config.PREFIX}leaderboard`) {
137+
//some databasing and math
138+
const filtered = client.points.filter(p => p.guild === message.guild.id).array();
139+
const sorted = filtered.sort((a, b) => b.points - a.points);
140+
const top10 = sorted.splice(0, 10);
141+
const embed = new Discord.MessageEmbed()
142+
.setTitle(`${message.guild.name}: Leaderboard`)
143+
.setTimestamp()
144+
.setDescription(`Top 10 Ranking:`)
145+
.setColor("ORANGE");
146+
//set counter to 0
147+
let i = 0;
148+
//get rank
149+
for (const data of top10) {
150+
await delay(15); try {
151+
i++;
152+
embed.addField(`**${i}**. ${client.users.cache.get(data.user).tag}`, `Points: \`${Math.floor(data.points * 100) / 100}\` | Level: \`${data.level}\``);
153+
} catch {
154+
i++; //if usernot found just do this
155+
embed.addField(`**${i}**. ${client.users.cache.get(data.user)}`, `Points: \`${Math.floor(data.points * 100) / 100}\` | Level: \`${data.level}\``);
156+
}
157+
}
158+
//schick das embed
159+
return message.channel.send(embed);
160+
}
161+
162+
})
163+
function delay(delayInms) {
164+
return new Promise(resolve => {
165+
setTimeout(() => {
166+
resolve(2);
167+
}, delayInms);
168+
});
169+
}
170+
}
171+
172+
//Coded by Tomato#6966!

readme.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
## Discord-Leveling-system-Ranking-system
2+
3+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
4+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Tomato6966/)
5+
[![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](https://GitHub.com/Tomato6966/Ask-Me-Anything)
6+
[![Support Server](https://img.shields.io/discord/591914197219016707.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/fS6qBSm)
7+
8+
A easy to setup and easy to use ranking system, and clean interfase using canvacord, using enmap for the database.
9+
10+
## Installation | How to use the Bot
11+
12+
**1.** Install [node.js v12](https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode) or higher
13+
**1.1** Install [python 3.9](https://www.python.org/downloads/) or higher
14+
15+
**2.** Download this repo and unzip it | or git clone it
16+
17+
**3.** Install all of the packages with **`npm install`** | the packages are **`npm install node.js discord.js enmap canvacord`**
18+
19+
**4.** start the bot with **`node index.js`**
20+
21+
**NOTE** you can also use **`setup.bat`** and afterwards **`run.bat`** to install packages and run the bot
22+
23+
## Usage - index.js
24+
25+
```javascript
26+
const Discord = require("discord.js"); //load the Discord.js Library
27+
const client = new Discord.Client(); //make a new Client
28+
const config = require("./config.json"); //load the config.json file
29+
const Enmap = require("enmap") //load the enmap library
30+
const canvacord = require("canvacord") //load the canvacord library
31+
client.points = new Enmap({ name: "points" }); //For ranking system
32+
client.on("ready", ()=>console.log("READY")); //log when the bot gets ready
33+
const leveling = require("./ranking"); //load the leveling file
34+
leveling(client); //call the leveling file with the client
35+
client.login(config.TOKEN); //start the bot with the bot token
36+
//Coded by Tomato#6966
37+
```
38+
39+
## How it looks like!
40+
41+
![](https://cdn.discordapp.com/attachments/751863584681885777/775632780057903124/RankCard.png)
42+
43+
44+
## **NOTE:**
45+
46+
*If you are having errors/problems with starting delete the package.json file and do, before you install the packages `npm init`*
47+
48+
## SUPPORT ME
49+
50+
You can always Support me by inviting one of my **own Discord Bots**
51+
52+
[![Musicium Music Bot](https://cdn.discordapp.com/attachments/742446682381221938/770055673965707264/test1.png)](https://bit.ly/Musicium)
53+
[![Milrato Muslti Bot](https://cdn.discordapp.com/attachments/742446682381221938/770056826724679680/test1.png)](https://bit.ly/Milrato)
54+
55+
[| fork my repository |](https://github.com/user/repository/fork)
56+
[watch this repo |](https://github.com/user/repository/subscription)
57+
[create issue |](https://github.com/user/repository/issues/new)
58+
59+
*Both bots are still in Development, and will always be in development, this means always uptodate and always online and always improving!*

run.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node .

setup.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm install

0 commit comments

Comments
 (0)