NOTICE: THIS IS CURRENTLY A DEVELOPMENT BUILD AND NOT MEANT TO BE AN OFFICIAL RELEASE
If you have ideas or suggestions to improve MultiConomy I would be glad to hear about that .
There will be still some changes though, this library is meant only as Interface and will not bring any commands
You can even create a own Storage Provider Plugin to Store the currency for example inside a MySQL Database, for default it will use the Sinusbot Storage
MultiConomy is an interface to connect scripts which use one virtual currency,
it allows you to add coins or remove coins from an user, create Transaction between Users and have a History about the Balances and TransActions of each user
the complete Documentation for all functions and their Parameters can be found HERE
here is an example on how to use the Script
If you have ideas or suggestions to improve MultiConomy I would be glad to hear about that .
There will be still some changes though, this library is meant only as Interface and will not bring any commands
You can even create a own Storage Provider Plugin to Store the currency for example inside a MySQL Database, for default it will use the Sinusbot Storage
MultiConomy is an interface to connect scripts which use one virtual currency,
it allows you to add coins or remove coins from an user, create Transaction between Users and have a History about the Balances and TransActions of each user
the complete Documentation for all functions and their Parameters can be found HERE
here is an example on how to use the Script
JavaScript:
/* eslint-disable no-shadow */
registerPlugin({
name: "MultiConomy Example",
engine: ">= 1.0.0",
version: "0.1.0",
description: "MultiConomy Example Script",
author: "Multivitamin <[email protected]"
}, (_, config) => {
const engine = require("engine")
const event = require("event")
const backend = require("backend")
const format = require("format")
function getNameFromUid(uid) {
const client = backend.getClientByUID(uid)
return client ? client.nick() : uid
}
event.on("load", () => {
const eco = require("MultiConomy")
if (!eco) return engine.log("MultiConomy.js not found! Please be sure to install and enable MultiConomy.js")
const Command = require("command")
if (!Command) return engine.log("command.js not found! Please be sure to install and enable Command.js")
const { createCommandGroup, createArgument } = Command
//wallet - view your balance
const walletCommand = createCommandGroup("wallet")
.help("manges your wallet")
.exec(async (client, _, reply) => {
const wallet = await eco.getWallet(client)
reply(`You own ${wallet.getBalance()}${eco.getCurrencySign()}`)
})
//wallet history - gets the last 50 transactions you made
walletCommand
.addCommand("history")
.help("view your transaction history")
.manual(`displays details about your 50 last transactions`)
.exec(async (client, _, reply) => {
try {
const wallet = await eco.getWallet(client)
const history = await wallet.getHistory(50)
if (history.length === 0) return reply("No transactions found!")
history.forEach(({ change, reason }) => reply(`${format.bold(change < 0 ? `[color=red]${change}[/color]` : `[color=green]${change}[/color]`)} - ${reason}`))
} catch (e) {
engine.log(e.stack)
}
})
//wallet pay <client> <amount> - sends the amount of money to another client
walletCommand
.addCommand("pay")
.help("sends money to another client")
.manual(`The first parameter should be a user which receives the money`)
.manual(`The Second Parameter is the amount which the users receives`)
.addArgument(createArgument("client").setName("receiver"))
.addArgument(createArgument("number").setName("amount").positive().integer())
.exec(async (client, { receiver, amount }, reply) => {
try {
const [receiverWallet, senderWallet] = await Promise.all([eco.getWallet(receiver), eco.getWallet(client)])
if (!senderWallet.hasFunds(amount)) return reply("You do not have enough funds to do this transaction!")
receiverWallet.addBalance(amount, `Received from ${senderWallet.getOwner()}`)
senderWallet.removeBalance(amount, `Sent to ${receiverWallet.getOwner()}`)
reply(`You have sent ${amount}${eco.getCurrencySign()} to ${getNameFromUid(receiver)}!`)
const receiverClient = backend.getClientByUID(receiver)
if (!receiverClient) return
receiverClient.chat(`You have received ${amount}${eco.getCurrencySign()} from ${getNameFromUid(client.nick())}!`)
} catch (e) {
engine.log(e.stack)
}
})
})
})