Skip to content

Commit

Permalink
discord-leveling-super v1.0.5
Browse files Browse the repository at this point in the history
**v1.0.5**

- Fixed bugs.
- Discord.js v14 support.
- Now "options.xp" is accepting a number or an array of numbers [min, max] XP values. Every time user sends a message, a random number of XP between `min` and `max` values will be added to a user.
- Added a new `gainedXP` property `addXP` and `addTotalXP` events that indicates how much XP the user gained.
  • Loading branch information
shadowplay1 authored Aug 17, 2022
1 parent 7d1c58f commit 51800b5
Show file tree
Hide file tree
Showing 34 changed files with 3,281 additions and 136 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 ShadowPlay.
Copyright (c) 2022 ShadowPlay.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 21 additions & 0 deletions dist/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 ShadowPlay.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 45 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Discord Leveling Super

[![Downloads](https://img.shields.io/npm/dt/discord-leveling-super?style=for-the-badge)](https://www.npmjs.com/package/discord-leveling-super)
[![Stable Version](https://img.shields.io/npm/v/discord-leveling-super?style=for-the-badge)](https://www.npmjs.com/package/discord-leveling-super)

<b>Discord Leveling Super</b> - Easy and customizable leveling framework for your [Discord Bot](https://discord.js.org/#/).

## ❓ | Why?
<ul>
<li><b>TypeScript Support 📘</b></li>
<li><b>Object-oriented 📜</b></li>
<li><b>Flexible and Customizable ⚙️</b></li>
<li><b>Easy to use 👍</b></li>
<li><b>Beginner Friendly 😄</b></li>
<li><b>Multi-Server Setup 🏦</b></li>
</ul>

## 📂 | Installation
<b>Note:</br><b>
<b>Node.js >=16.9.0 and Discord.js >=14.0.1 is required.</b><br>
```console
npm i discord-leveling-super
yarn add discord-leveling-super
pnpm add discord-leveling-super
```

## [[Module Documentation]](https://dls-docs.js.org)

## 🤔 | Help
<b>If you don't understand something in the documentation or you are experiencing problems, feel free to join our <a href = "https://discord.gg/4pWKq8vUnb">Support Server</a>.</b>

## ❗ | Useful Links
<ul>
<li><b><a href = "https://dls-docs.js.org">Documentation</a></b></li>
<li><b><a href = "**https://dls-docs.js.org/#/docs/main/1.0.5/general/faq">Frequently Asked Questions</a></b></li>
<li><b><a href = "https://www.npmjs.com/package/discord-leveling-super">NPM</a></b></li>
<li><b><a href = "https://github.com/shadowplay1/discord-leveling-super">GitHub</a></b></li>
<li><b><a href = "https://github.com/shadowplay1/discord-leveling-super/tree/main/examples">Examples</a></b></li>
<li><b><a href = "https://discord.gg/4pWKq8vUnb">Discord Server</a></b></li>
</ul>
<b>If you found a bug, have any questions or need help, join the <a href = "https://discord.gg/4pWKq8vUnb">Support Server</a>.</b>
<br>
<b>Module Created by ShadowPlay.</b>

# ❤️ Thanks for using Discord Leveling Super ❤️
72 changes: 72 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const { existsSync } = require('fs')

const LevelingError = require('./src/classes/LevelingError')

const errors = require('./src/structures/Errors')
const modulePackage = require('./package.json')

const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
reset: '\x1b[0m'
}

function moduleVersion(moduleName) {
const modulePath = __dirname.includes('\\')
? __dirname.split('\\').slice(0, -1).join('\\') + `\\${moduleName}`
: __dirname.split('/').slice(0, -1).join('/') + `/${moduleName}`

if (!modulePackage.dependencies) return {
status: false,
version: null,
error: errors.noDependencies
}

if (!existsSync(modulePath)) return {
status: false,
version: null,
error: errors.noDiscordJS
}

const nodeModulePackage = require(modulePath)
return {
status: true,
version: nodeModulePackage.version,
error: null
}
}


function sendError(err) {
const error = new LevelingError(err)

console.log(`${colors.red}Failed to start the module:${colors.cyan}`)
console.log(error, colors.reset)

process.exit(1)
}

const djsVersion = moduleVersion('discord.js')
const nodeVersionNumbers = process.version.slice(1).split('.').map(x => Number(x))

function start() {
if (nodeVersionNumbers[0] < 16 && nodeVersionNumbers[1] < 6) return sendError(errors.oldNodeVersion + process.version)
if (djsVersion.error) return sendError(djsVersion.error)

const djsVersionNumbers = djsVersion.version.split('.').map(x => Number(x))
if (djsVersionNumbers[0] < 13 && djsVersionNumbers[1] < 1) return sendError(errors.oldDJSVersion + djsVersion.version)

const Leveling = require('./src/index')

module.exports = Object.assign(Leveling, {
version: modulePackage.version,
docs: 'https://dls-docs.js.org'
})
}

start()
16 changes: 16 additions & 0 deletions dist/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const colors = {
green: '\x1b[32m',
cyan: '\x1b[36m',
blue: '\x1b[34m'
}

console.log()
console.log(`${colors.green}╔═══════════════════════════════════════════════════════════════════╗`)
console.log(`${colors.green}║ @ discord-leveling-super - [] X ║`)
console.log(`${colors.green}║═══════════════════════════════════════════════════════════════════║`)
console.log(`${colors.green}${colors.cyan}Thank you for installing Discord Leveling Super! ${colors.green}║`)
console.log(`${colors.green}║═══════════════════════════════════════════════════════════════════║`)
console.log(`${colors.green}║ If you have any questions or need help, join the Support Server: ${colors.green}║`)
console.log(`${colors.green}${colors.blue}https://discord.gg/4pWKq8vUnb ${colors.green}║`)
console.log(`${colors.green}╚═══════════════════════════════════════════════════════════════════╝\x1b[37m`)
console.log()
47 changes: 47 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "discord-leveling-super",
"version": "1.0.5",
"description": "Easy and customizable leveling framework for your Discord bot.",
"types": "./typings/Leveling.d.ts",
"main": "index.js",
"scripts": {
"test": "echo \"ok\" && exit 0",
"postinstall": "node install.js",
"buildfiles": "tsc",
"begin": "npm i typescript"
},
"engines": {
"node": ">=16.6.0",
"npm": ">=7.0.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/shadowplay1/discord-leveling-super.git"
},
"keywords": [
"discord",
"bot",
"discord.js",
"leveling",
"discord-leveling",
"discord-leveling-super",
"ranks",
"ranking",
"discord-ranks",
"discord-js",
"super",
"rank",
"shadowplay"
],
"author": "shadowplay",
"license": "MIT",
"bugs": {
"url": "https://github.com/shadowplay1/discord-leveling-super/issues"
},
"homepage": "https://github.com/shadowplay1/discord-leveling-super#readme",
"dependencies": {
"discord.js": "^14.2.0",
"node-fetch": "^2.6.7",
"typescript": "^4.7.4"
}
}
129 changes: 129 additions & 0 deletions dist/src/classes/DotParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const fs_1 = require("fs");
const FetchManager_1 = __importDefault(require("../managers/FetchManager"));
const DefaultOptions_1 = __importDefault(require("../structures/DefaultOptions"));
/**
* Dot parser class.
* @private
*/
class DotParser {
options;
storagePath;
fetcher;
/**
* Leveling constructor options object. There's only needed options object properties for this manager to work properly.
* @param {Object} options Constructor options object.
* @param {String} options.storagePath Full path to a JSON file. Default: './leveling.json'.
*/
constructor(options = {}) {
/**
* Leveling constructor options object.
* @private
* @type {LevelingOptions}
*/
this.options = options;
/**
* Fetch manager methods object.
* @type {FetchManager}
* @private
*/
this.fetcher = new FetchManager_1.default(options);
if (!options.storagePath)
this.storagePath = DefaultOptions_1.default.storagePath;
}
/**
* Parses the key and fetches the value from database.
* @param {String} key The key in database.
* @returns {any | false} The data from database or 'false' if failed to parse or 'null' if nothing found.
*/
parse(key) {
let parsed = this.fetcher.fetchAll();
if (!key)
return false;
if (typeof key !== 'string')
return false;
const keys = key.split('.');
let tmp = parsed;
for (let i = 0; i < keys.length; i++) {
if ((keys.length - 1) == i) {
parsed = tmp?.[keys[i]] || null;
}
tmp = tmp?.[keys[i]];
}
return parsed || null;
}
/**
* Parses the key and sets the data in database.
* @param {String} key The key in database.
* @param {any} value Any data to set.
* @returns {Boolean} If set successfully: true; else: false
*/
set(key, value) {
const { isObject } = this;
let storageData = this.fetcher.fetchAll();
if (!key)
return false;
if (typeof key !== 'string')
return false;
if (value == undefined)
return false;
if (typeof value == 'function')
return false;
const keys = key.split('.');
let tmp = storageData;
for (let i = 0; i < keys.length; i++) {
if ((keys.length - 1) == i) {
tmp[keys[i]] = value;
}
else if (!isObject(tmp[keys[i]])) {
tmp[keys[i]] = {};
}
tmp = tmp?.[keys[i]];
}
(0, fs_1.writeFileSync)(this.options.storagePath || './leveling.json', JSON.stringify(storageData, null, '\t'));
return true;
}
/**
* Parses the key and removes the data from database.
* @param {String} key The key in database.
* @returns {Boolean} If removed successfully: true; else: false
*/
remove(key) {
const { isObject } = this;
let storageData = this.fetcher.fetchAll();
if (!key)
return false;
if (typeof key !== 'string')
return false;
const data = this.parse(key);
if (data == null)
return false;
const keys = key.split('.');
let tmp = storageData;
for (let i = 0; i < keys.length; i++) {
if ((keys.length - 1) == i) {
delete tmp?.[keys[i]];
}
else if (!isObject(tmp?.[keys[i]])) {
tmp[keys[i]] = {};
}
tmp = tmp[keys[i]];
}
(0, fs_1.writeFileSync)(this.options.storagePath || './leveling.json', JSON.stringify(storageData, null, '\t'));
return true;
}
/**
* Checks for is the item object and returns it.
* @param {any} item The item to check.
* @returns {Boolean} Is the item object or not.
*/
isObject(item) {
return !Array.isArray(item)
&& typeof item == 'object'
&& item !== null;
}
}
module.exports = DotParser;
41 changes: 41 additions & 0 deletions dist/src/classes/Emitter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";
const events_1 = require("events");
const emitter = new events_1.EventEmitter();
/**
* Simple Leveling event emitter with only important emitter methods.
* @private
*/
class Emitter {
/**
* Simple Leveling event emitter with only important emitter methods.
* @private
*/
constructor() { }
/**
* Listens to the event.
* @param {LevelingEvents} event Event name.
* @param {Function} listener Listener function.
*/
on(event, listener) {
emitter.on(event, listener);
return this;
}
/**
* Listens to the event only for once.
* @param {LevelingEvents} event Event name.
* @param {Function} listener Listener function.
*/
once(event, listener) {
emitter.once(event, listener);
return this;
}
/**
* Emits the event.
* @param {LevelingEvents} event Event name.
* @param {Function} args Listener arguments.
*/
emit(event, ...args) {
return emitter.emit(event, ...args);
}
}
module.exports = Emitter;
Loading

0 comments on commit 51800b5

Please sign in to comment.