npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

khlav

v1.2.4

Published

Khlav is a robust and customizable economy and gambling system for your Node.js applications.

Downloads

24

Readme

Khlav - A Comprehensive Economy and Gambling System

Khlav is a robust and customizable economy and gambling system for your Node.js applications. It includes features such as managing user balances, inventory, and various gambling games.

Features

  • Economy Management: Manage user wallets and bank accounts.
  • Inventory System: Add, remove, and manage items in user inventories.
  • Gambling Games: Includes slot machine and spin games.
  • Rewards System: Claim daily, weekly, and other periodic rewards.
  • Transfer System: Transfer money between users.
  • Leaderboard: Display top users based on balance.

Installation

Install Khlav using npm:

npm install khlav

Usage

Setting Up MongoDB

Set your MongoDB connection URL using the setMongoURL method:

const CurrencySystem = require('khlav');
const currencySystem = new CurrencySystem();

const mongoURL = 'your_mongodb_connection_string'; // Replace with your actual MongoDB connection string
currencySystem.setMongoURL(mongoURL);

Economy Functions

Get Balance

const balance = await currencySystem.getBalance(userId);
console.log(`User Balance: ${balance}`);

Get Bank Balance

const bankBalance = await currencySystem.getBankBalance(userId);
console.log(`User Bank Balance: ${bankBalance}`);

Deposit Money

const success = await currencySystem.depositMoney(userId, amount);
console.log(`Deposit Successful: ${success}`);

Withdraw Money

const success = await currencySystem.withdrawMoney(userId, amount);
console.log(`Withdrawal Successful: ${success}`);

Transfer Money

const success = await currencySystem.transferMoney(senderId, receiverId, amount);
console.log(`Transfer Successful: ${success}`);

Gambling Functions

Play Slots

const result = await currencySystem.playSlots(userId, amount);
console.log(`Slots Result: ${result.win ? 'Win' : 'Lose'}, Amount: ${result.amount}`);

Play Spin

const result = await currencySystem.playSpin(userId, amount);
console.log(`Spin Result: ${result.win ? 'Win' : 'Lose'}, Amount: ${result.amount}`);

Rewards Functions

  • hourly
  • Daily
  • Weekly
  • monthly
  • hafly
  • quaterly
  • yearly

Claim Daily Reward

const reward = await currencySystem.claimDailyReward(userId);
if (reward.success) {
  console.log(`Daily Reward Claimed: ${reward.reward}`);
} else {
  console.log(reward.message);
}

Claim Weekly Reward

const reward = await currencySystem.claimWeeklyReward(userId);
if (reward.success) {
  console.log(`Weekly Reward Claimed: ${reward.reward}`);
} else {
  console.log(reward.message);
}

Inventory Functions

Add Item to Inventory

const item = {
  name: 'Sword',
  price: 100,
  description: 'A sharp blade.'
};
const result = await currencySystem.addItem({ guild: { id: guildId }, inventory: item });
console.log(`Item Added: ${result.item.name}`);

Remove Item from Inventory

const result = await currencySystem.removeItem({ guild: { id: guildId }, item: itemId });
console.log(`Item Removed: ${result.inventory.name}`);

Leaderboard Functions

Get Top Users

const topUsers = await currencySystem.getTopUsers();
console.log('Top Users:', topUsers);

Configuration

In the example.js file, the following configuration settings are demonstrated:

const currencySystem = new CurrencySystem();

// Set MongoDB URL!
currencySystem.setMongoURL(mongoURL);

// Set Default Bank Amount when a new user is created!
currencySystem.setDefaultBankAmount(1000);
currencySystem.setDefaultWalletAmount(1000);

// Its bank space limit (can be changed according to per user) here 0 means infinite.
currencySystem.setMaxBankAmount(10000);

// Set Default Maximum Amount of Wallet Currency a user can have! (can be changed according to per user) here 0 means infinite.
currencySystem.setMaxWalletAmount(10000);

// Search for new npm package updates on bot startup! Latest version will be displayed in console.
currencySystem.searchForNewUpdate(true);

Roleplay Commands

const { getGif } = require('khlav');

async function runExample() {
  try {
    const gif = await getGif('hug');
    console.log(gif); // URL of the hug gif
  } catch (error) {
    console.error(error);
  }
}

runExample();
const klv = require('khlav');

//In this example we use the anime bite endpoint
klv.getGif('bite').then((data) => {
  console.log(data) // This return as example: https://apiservice1.kisara.app/satou/interactions/bite/6.gif
})

//OR with async/await function

const data = async() => {
  const data = await klv.getGif('bite');
  console.log(data); // This return as example: https://apiservice1.kisara.app/satou/interactions/bite/3.gif
}

Example Bot

const { Client, Intents } = require('discord.js');
const { CurrencySystem, getGif } = require('khlav');
const cs = new CurrencySystem();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

cs.setMongoURL('your-mongodb-url');

client.once('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
  if (message.content.startsWith('!balance')) {
    const balance = await cs.balance({
      user: message.author,
      guild: message.guild,
    });
    message.channel.send(`You have ${balance.wallet} in your wallet and ${balance.bank} in your bank.`);
  }

  if (message.content.startsWith('!hug')) {
    const gif = await getGif('hug');
    message.channel.send(`${message.author} hugs ${message.mentions.users.first()}\n${gif}`);
  }
});

client.login('your-bot-token');

Roleplay List

  • angry
  • anime
  • bite
  • bored
  • bread
  • chocolate
  • cookie
  • cuddle
  • dance
  • drunk
  • happy
  • hug
  • kick
  • kill
  • kiss
  • laugh
  • lick
  • lonely
  • pat
  • poke
  • pregnant
  • punch
  • run
  • satouselfies
  • slap
  • sleep
  • spank
  • spit
  • steal
  • tickle
  • nomm

Contributing

Feel free to fork this repository and submit pull requests. We welcome all contributions that improve the functionality and usability of Khlav.

License

This project is licensed under the Apache-2.0 License.

NEW

  • Added transferItems().

For Global Economy

To make it global, remove the following line from every command:

guild: interaction.guild,

and add:

guild: { id : null }