Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from Butterstroke/Beta0.7
Browse files Browse the repository at this point in the history
Beta0.7 Update
  • Loading branch information
AurelicButter authored Oct 31, 2017
2 parents 3912b46 + 2b46aa6 commit 6547958
Show file tree
Hide file tree
Showing 43 changed files with 1,296 additions and 131 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# MargarineBot - Current Version: Beta 0.6 Komada Improvements!
# MargarineBot - Current Version: Beta 0.7 - Economy
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f0cfd83063a4469b8e40bcc824c2600d)](https://www.codacy.com/app/Butterstroke/MargarineBot?utm_source=github.com&utm_medium=referral&utm_content=Butterstroke/MargarineBot&utm_campaign=Badge_Grade)

A Discord bot coded in Node.js using the Discord.js Library and the Komada framework.

<b>Introduction:</b>
Created through part-desire, part-what can I do in Discord, part-I'm going to learn Javascript, and part-it's only 12 am thoughts, Margarine has been my personal project for almost 6 months now. I am quite proud of the functionality and the time I have spend into Margarine. I have recieved plenty of support over the months of developing him and I can't thank those people enough as without that support, Margarine would have never been as big as he is today. I hope that you enjoy either looking at/learning/using Margarine as much as I do.
Created through part-desire, part-what can I do in Discord, part-I'm going to learn Javascript, and part-it's only 12 am thoughts, Margarine has been my personal project for almost 6 months now. I am quite proud of the functionality and the time I have spend into Margarine. I have received plenty of support over the months of developing him and I can't thank those people enough as without that support, Margarine would have never been as big as he is today. I hope that you enjoy either looking at/learning/using Margarine as much as I do.

*Name Origin:* My typical nickname is Butter. As in the stuff that you put on toast. His name comes from the artificial butter (I tends to call it 'Fake Butter') you can buy in stores called, Margarine.

Expand All @@ -15,8 +15,10 @@ Created through part-desire, part-what can I do in Discord, part-I'm going to le
- Permission levels
- Poll command
- Server/User/role info commands
- Economy system (No SQL or any other server needed! All data is local to the folder.)

<b>Updates:</b>
- 31 October 2017: Beta 0.7 Released
- 30 September 2017: Beta 0.6 Released
- 15 August 2017: Beta 0.5 Released
- 14 July 2017: Beta 0.4 Released
Expand Down
1 change: 1 addition & 0 deletions bwd/data/dummy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I'm just a dummy file for the SQLite database to be created here.
47 changes: 47 additions & 0 deletions commands/Economy/Games/chouhan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
exports.run = async (client, message, [credit, bet]) => {
const sqlite3 = require("sqlite3").verbose();
let db = new sqlite3.Database("./bwd/data/score.sqlite");

db.get(`SELECT * FROM scores WHERE userId = "${message.author.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) { return message.reply("You haven't signed up and received your credits yet! D: Use `m~daily` (Using default prefix) to earn your first amount of credits."); }
if (row.credits < credit) { return message.reply("You don't have that many credits, baka!"); }
if (!credit || credit < 1) { return message.reply("You need to bet some credits to play!"); }
else {
var z; let rolls = [];
for (z = 0; z < 6; z++) {
var x = Math.floor(Math.random() * (Math.floor(6) - Math.ceil(1) + 1)) + Math.ceil(1);
rolls.push(x);
}

var sum = rolls[0] + rolls[1] + rolls[2] + rolls[3] + rolls[4] + rolls[5];

if ((sum%2 === 0 && bet === "even") || (sum%2 !== 0 && bet === "odd")) {
credit = Number(credit*1.5).toFixed(0);
db.run(`UPDATE scores SET credits = ${parseInt(row.credits) + parseInt(credit)} WHERE userId = ${message.author.id}`);
return message.reply(`Sum: ${sum} Your Guess: ${bet} You have won ${credit} credits!`);
} else {
db.run(`UPDATE scores SET credits = ${parseInt(row.credits) - parseInt(credit)} WHERE userId = ${message.author.id}`);
return message.reply(`Sum: ${sum} Your Guess: ${bet} You have lost ${credit} credits.`);
}
}
});
db.close();
};

exports.conf = {
enabled: true,
runIn: ["text"],
aliases: ["chō-han", "chōhan", "chou-han"],
permLevel: 0,
botPerms: [],
requiredFuncs: [],
};

exports.help = {
name: "chouhan",
description: "Bet your credits on if the sum of six dice are even or odd.",
usage: "[credits:int] <even|odd>",
usageDelim: " ",
extendedHelp: "A Simple Japanese dice game. Six dice are rolled and the results kept secret. Players bet on whether the sum on the dice is odd or even.",
};
177 changes: 177 additions & 0 deletions commands/Economy/Games/fish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
exports.run = async (client, message, [action, kind, amount]) => {
const sqlite3 = require("sqlite3").verbose();
let db = new sqlite3.Database("./bwd/data/score.sqlite");
let user = message.author;

if (!action) {
db.get(`SELECT * FROM scores WHERE userId = "${user.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) { return message.reply("You haven't signed up and received your credits yet! D: Use `m~daily` (Using default prefix) to earn your first amount of credits."); }
if (row.credits < 5) { return message.reply("You don't have that many credits, baka!"); }
else {
db.run(`UPDATE scores SET credits = ${row.credits - 5} WHERE userId = ${user.id}`);

var die = Math.random();

const Fisher = [
["trash", "common", "uncommon", "rare", "epic"],
["some trash and threw it out", "a common fish. A bit small but still good", "an uncommon catch. This will catch some decent credits", "a rare catch! This will fund your gambling habits for awhile", "an epic fish! O: That's bound to buy you a house *(No guarantees)*"],
[":wastebasket:", ":fish:", ":crab:", ":squid:", ":shark:"],
["You have lost 5 credits", "You have placed the fish in your inventory"]
];

if (0 < die && die < .5) { var results = 0; }
if (.5 < die && die < .75) { var results = 1; }
if (.75 < die && die < .88) { var results = 2; }
if (.88 < die && die < .98) { var results = 3; }
if (.98 < die && die < 1) { var results = 4; }

if (die > .5) { var Fisherbot = 1; }
else { var Fisherbot = 0;}

var kind = Fisher[0][results];
var text = Fisher[1][results];
var image = Fisher[2][results];
var result = Fisher[3][Fisherbot];

db.get(`SELECT * FROM fish_inv WHERE userId = "${user.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) {
return message.reply("Error in finding your information. Fish_inv table is lacking your id!");
} else if (kind === "common") {
db.run(`UPDATE fish_inv SET common = ${row.common + 1} WHERE userId = ${user.id}`);
} else if (kind === "uncommon") {
db.run(`UPDATE fish_inv SET uncommon = ${row.uncommon + 1} WHERE userId = ${user.id}`);
} else if (kind === "rare") {
db.run(`UPDATE fish_inv SET rare = ${row.rare + 1} WHERE userId = ${user.id}`);
} else if (kind === "epic") {
db.run(`UPDATE fish_inv SET epic = ${row.epic + 1} WHERE userId = ${user.id}`);
}
});

db.get(`SELECT * FROM fish_stats WHERE userId = "${user.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) {
return message.reply("Error in finding your information. Fish_stats table is lacking your id!");
} else if (kind === "common") {
db.run(`UPDATE fish_stats SET common = ${row.common + 1} WHERE userId = ${user.id}`);
} else if (kind === "uncommon") {
db.run(`UPDATE fish_stats SET uncommon = ${row.uncommon + 1} WHERE userId = ${user.id}`);
} else if (kind === "rare") {
db.run(`UPDATE fish_stats SET rare = ${row.rare + 1} WHERE userId = ${user.id}`);
} else if (kind === "epic") {
db.run(`UPDATE fish_stats SET epic = ${row.epic + 1} WHERE userId = ${user.id}`);
} else if (kind === "trash") {
db.run(`UPDATE fish_stats SET trash = ${row.trash + 1} WHERE userId = ${user.id}`);
}

message.channel.send(`${user.username}, you have caught ${text}. ${image} ${result}.`);
});
}
});
} if (action === "inv" || action === "inventory") {
db.get(`SELECT * FROM fish_inv WHERE userId = "${user.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) { return message.channel.send("You haven't caught any fish yet!"); }
else {
const embed = new client.methods.Embed()
.setTimestamp()
.setAuthor(message.guild.name, message.guild.iconURL())
.setColor("#4d5fd")
.setThumbnail(user.avatarURL())
.setTitle(`${user.username}'s Fishing Inventory:`)
.setDescription("*:eyes: Let's see what you've caught.*");
if (row.common > 0) { embed.addField("Common fish:", row.common, true); }
if (row.uncommon > 0) { embed.addField("Uncommon fish:", row.uncommon, true); }
if (row.rare > 0) { embed.addField("Rare fish:", row.rare, true); }
if (row.epic > 0) { embed.addField("Epic fish:", row.epic, true); }
if ((row.common === 0) && (row.uncommon === 0) && (row.rare === 0) && (row.epic === 0)) { embed.addField("There's a slight problem here...", "You don't actually have any fish in your inventory."); }
return message.channel.send({embed});
}
});
} if (action === "sell") {
db.get(`SELECT * FROM fish_inv WHERE userId = "${user.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) { return message.channel.send("You haven't caught any fish yet!"); }
else {
if (kind === "common") {
if (!amount) { amount = row.common; }
var rowAmount = row.common;
var income = amount * 5;
} if (kind === "uncommon") {
if (!amount) { amount = row.uncommon; }
var rowAmount = row.uncommon;
var income = amount * 10;
} if (kind === "rare") {
if (!amount) { amount = row.rare; }
var rowAmount = row.rare;
var income = amount * 25;
} if (kind === "epic") {
if (!amount) { amount = row.epic; }
var rowAmount = row.epic;
var income = amount * 50;
}

if (rowAmount === 0) { return message.channel.send(`You don't have any ${kind} fish to sell! D:`); }
if (rowAmount < amount) { return message.channel.send("You don't have that much fish to sell."); }

db.run(`UPDATE fish_inv SET ${kind} = ${row.epic - amount} WHERE userId = ${user.id}`);

message.channel.send(`You have sold ${amount} ${kind} fish and earned ${income} credits!`);

db.get(`SELECT * FROM scores WHERE userId = "${user.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
db.run(`UPDATE scores SET credits = ${parseInt(row.credits) + parseInt(income)} WHERE userId = ${user.id}`);
});
}
});
} if (action === "stats") {
var User = client.funcs.userSearch(client, message, kind);
if (User.username === undefined) { return; }
if (User.bot === true) { return message.reply("Bots can't fish!"); }

db.get(`SELECT * FROM fish_stats WHERE userId = "${User.id}"`, [], (err, row) => {
if (err) { return console.log(err); }
if (!row) {
if (User.id === message.author.id) { return message.channel.send("You haven't caught any fish yet!"); }
else { return message.channel.send("That user has not caught any fish yet!"); }
} else {
var sum = row.common + row.uncommon + row.rare + row.epic + row.trash;
const embed = new client.methods.Embed()
.setTimestamp()
.setAuthor(message.guild.name, message.guild.iconURL())
.setColor("#4d5fd")
.setThumbnail(User.avatarURL())
.setTitle(`${User.username}'s Fishing Statistics:`)
.setDescription(`*Total catch amount: ${sum}*`)
.addField("Trash:", row.trash, true)
.addField("Common fish:", row.common, true)
.addField("Uncommon fish:", row.uncommon, true)
.addField("Rare fish:", row.rare, true)
.addField("Epic fish:", row.epic, true);
return message.channel.send({embed});
}
});
} if (action !== null && action !== "stats" && action !== "inv" && action !== "inventory" && action !== "sell") {
return message.reply("You didn't provide a valid action. I can either provide you with selling `m~fish sell [type]`, showing your inventory `m~fish inv`, showing your stats `m~fish stats`, or fishing `m~fish`");
}
db.close();
};

exports.conf = {
enabled: true,
runIn: ["text"],
aliases: [],
permLevel: 0,
botPerms: [],
requiredFuncs: [],
cooldown: 15,
};

exports.help = {
name: "fish",
description: "Fish and try to turn your credits into a fortune!",
usage: "[action:str] [kind:str] [amount:int]",
usageDelim: " ",
extendedHelp: "Spend 10 credits to fish and catch yourself a fortune! Check someone's stats with `m~fish stats [user]`. Or check your inventory with `m~fish inv`.",
};
Loading

0 comments on commit 6547958

Please sign in to comment.