first update to dev branch
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
node_modules
|
||||
.env
|
||||
.eslintrc.js
|
||||
|
||||
dsabot.db
|
||||
|
||||
|
0
Dockerfile
Normal file
0
Dockerfile
Normal file
0
hooks/post_checkout
Normal file
0
hooks/post_checkout
Normal file
0
hooks/pre_build
Normal file
0
hooks/pre_build
Normal file
14381
package-lock.json
generated
14381
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -12,10 +12,9 @@
|
||||
"dependencies": {
|
||||
"discord.js": "^12.0.2",
|
||||
"dotenv": "^8.2.0",
|
||||
"mysql": "^2.18.1",
|
||||
"nodemon": "^2.0.2"
|
||||
"nedb": "^1.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.8.0"
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,49 @@
|
||||
module.exports = async (message, args, db) => {
|
||||
try {
|
||||
console.log(message.author.tag + ': ' + args)
|
||||
if (!isNaN(args[0])) {
|
||||
message.reply(args[1])
|
||||
console.log('1: ' + args[1] + ', 2: ' + args[2])
|
||||
const money = ["gold", "silver", "bronce", "iron", "hp"]
|
||||
if (money.indexOf(args[1].toLowerCase()) < 0) {
|
||||
message.reply(
|
||||
'Sorry, Aber du musst eins der folgenden Wörter angeben: ' + money.join(",")
|
||||
)
|
||||
return;
|
||||
}
|
||||
db.find({
|
||||
user: message.author.tag
|
||||
}, function (err, docs) {
|
||||
|
||||
gold = docs[0].gold
|
||||
silver = docs[0].silver
|
||||
bronce = docs[0].bronce
|
||||
iron = docs[0].iron
|
||||
hp = docs[0].hp
|
||||
|
||||
})
|
||||
db.update({
|
||||
user: message.author.tag
|
||||
}, {
|
||||
gold: gold,
|
||||
silver: silver,
|
||||
bronce: bronce,
|
||||
iron: iron,
|
||||
hp: hp
|
||||
}, function (err, docs) {
|
||||
if (!docs.length > 0) {
|
||||
message.reply('Sorry, Für dich habe ich keinen Eintrag 😥')
|
||||
return;
|
||||
}
|
||||
message.reply(`ich habe ${args[2]} zu ${args[1]} hinzugefügt.`)
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
module.exports = async (message, args, db) => {
|
||||
var n;
|
||||
|
||||
@ -31,3 +77,4 @@ module.exports = async (message, args, db) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
*/
|
@ -1,6 +1,31 @@
|
||||
module.exports = async (message, args, db) => {
|
||||
try {
|
||||
console.log(message)
|
||||
db.find({
|
||||
user: message.author.tag
|
||||
}, function (err, docs) {
|
||||
// docs is an array containing documents Mars, Earth, Jupiter If no document is
|
||||
// found, docs is equal to []
|
||||
if(!docs.length>0)
|
||||
db.insert({user: message.author.tag,
|
||||
gold: 0,
|
||||
silver: 0,
|
||||
bronce: 0,
|
||||
iron: 0,
|
||||
hp: 0
|
||||
|
||||
})
|
||||
|
||||
console.log(docs)
|
||||
});
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
db.query('SELECT * FROM dsageld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data
|
||||
/*db.query('SELECT * FROM dsageld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data
|
||||
if(row.length < 1) {
|
||||
// eslint-disable-next-line no-undef
|
||||
db.query('INSERT INTO `dsageld` (`userName`, `GD`,`ST`, `BH`, `EK`, `LP`) VALUES (' + '"' + message.author.tag + '"' + ', 0, 0, 0, 0, 0)');
|
||||
@ -9,4 +34,4 @@ module.exports = async (message, args, db) => {
|
||||
message.reply('Dein Eintrag existiert bereits.');
|
||||
}
|
||||
});
|
||||
};
|
||||
};*/
|
@ -3,7 +3,7 @@ const create = require('./create');
|
||||
const add = require('./add');
|
||||
const remove = require('./remove');
|
||||
const show = require('./show');
|
||||
const mysql = require('mysql');
|
||||
const talent = require('./talent')
|
||||
require('dotenv').config();
|
||||
const prefix = '!';
|
||||
|
||||
@ -12,32 +12,22 @@ const commands = {
|
||||
create,
|
||||
add,
|
||||
remove,
|
||||
show
|
||||
show,
|
||||
talent
|
||||
};
|
||||
var Datastore = require('nedb'),
|
||||
db = new Datastore({
|
||||
filename: 'dsabot.db',
|
||||
autoload: true
|
||||
});
|
||||
|
||||
var db = mysql.createConnection({
|
||||
host : 'localhost',
|
||||
port : '3306',
|
||||
user : 'root',
|
||||
password : process.env.DB_PASSWORD,
|
||||
database : 'DSA'
|
||||
});
|
||||
|
||||
db.connect((err) => {
|
||||
if(err){
|
||||
throw err;
|
||||
}
|
||||
console.log('MySql connected...');
|
||||
});
|
||||
|
||||
module.exports = async (message) =>{
|
||||
//command manager
|
||||
module.exports = async (message) => {
|
||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||
|
||||
const args = message.content.slice(prefix.length).split(' ');
|
||||
const command = args.shift().toLowerCase();
|
||||
|
||||
if(Object.keys(commands).includes(command)) {
|
||||
if (Object.keys(commands).includes(command)) {
|
||||
commands[command](message, args, db);
|
||||
}
|
||||
|
||||
|
0
src/commands/read.js
Normal file
0
src/commands/read.js
Normal file
@ -1,7 +1,27 @@
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
module.exports = async (message, args, db) => {
|
||||
// eslint-disable-next-line no-undef
|
||||
db.query('SELECT * FROM dsageld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data
|
||||
try {
|
||||
console.log(message)
|
||||
db.find({
|
||||
user: message.author.tag
|
||||
}, function (err, docs) {
|
||||
// docs is an array containing documents Mars, Earth, Jupiter If no document is
|
||||
// found, docs is equal to []
|
||||
if (!docs.length > 0)
|
||||
message.reply('Sorry, Für dich habe ich keinen Eintrag 😥')
|
||||
else
|
||||
message.reply(
|
||||
`Du besitzt folgendes:
|
||||
${docs[0].silver} Silberstücke.`
|
||||
)
|
||||
});
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
|
||||
|
||||
/* db.query('SELECT * FROM dsageld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data
|
||||
if(row && err) {
|
||||
message.reply('Es gab einen Fehler.');
|
||||
}
|
||||
@ -11,5 +31,5 @@ module.exports = async (message, args, db) => {
|
||||
message.reply('du hast: ' + row[0].GD + ' GD, ' + row[0].ST + ' ST, ' + row[0].BH + ' BH, ' + row[0].EK + ' EK.' + row[0].LP + ' LeP.');
|
||||
}
|
||||
}
|
||||
);
|
||||
);*/
|
||||
};
|
56
src/commands/talent.js
Normal file
56
src/commands/talent.js
Normal file
@ -0,0 +1,56 @@
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
module.exports = async (message, args, db) => {
|
||||
if (args.length < 3) {
|
||||
message.reply("Der Talentwurf funktioniert so:");
|
||||
message.reply(
|
||||
"!talent Eigenschaftswert1 Eigenschaftswert2 Eigenschaftswert3 [Bonus] [Erschwernis]"
|
||||
);
|
||||
} else {
|
||||
var roll = [];
|
||||
if (args[3]) {
|
||||
var bonus = parseInt(args[3]);
|
||||
} else {
|
||||
bonus = 0;
|
||||
}
|
||||
if (args[4]) {
|
||||
var erschwernis = parseInt(args[4]);
|
||||
} else {
|
||||
erschwernis = 0;
|
||||
}
|
||||
for (i = 1; i <= 3; i++) {
|
||||
var a = Math.floor(Math.random() * 20 + 1);
|
||||
roll.push(a);
|
||||
}
|
||||
var ok = 0;
|
||||
var patzer = 0;
|
||||
var crit = 0;
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (Math.floor(parseInt(args[i]) + parseInt(erschwernis)) >= roll[i])
|
||||
ok++;
|
||||
else if (
|
||||
Math.floor(parseInt(args[i]) + parseInt(bonus) + parseInt(erschwernis)) >= roll[i]) {
|
||||
ok++;
|
||||
bonus = bonus - (roll[i] - parseInt(erschwernis) - parseInt(args[i]));
|
||||
}
|
||||
if (roll[i] == 1) crit++;
|
||||
if (roll[i] == 20) patzer++;
|
||||
}
|
||||
if (patzer >= 2) {
|
||||
message.reply(
|
||||
"Deine 🎲: " + roll.join(", ") + ". Patzer! Du hast aber auch Pech 😥"
|
||||
);
|
||||
} else if (crit >= 2) {
|
||||
message.reply(
|
||||
"Deine 🎲: " + roll.join(", ") + ". Damit hast du einen kritischen Erfolg erzielt 🎈✨🥳"
|
||||
);
|
||||
} else if (ok < 3) {
|
||||
message.reply(
|
||||
"Deine 🎲: " + roll.join(", ") + ". Damit hast du nur " + ok + "/3 Proben bestanden. 😪"
|
||||
);
|
||||
} else {
|
||||
message.reply(
|
||||
"Das waren deine 🎲: " + roll.join(", ") + ". Damit hast du " + ok + "/3 Proben bestanden. Dein Bonus: " + bonus + "/" + args[3] + "."
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
6
src/globals.js
Normal file
6
src/globals.js
Normal file
@ -0,0 +1,6 @@
|
||||
const money = [{
|
||||
"GD": "Golddukaten",
|
||||
"ST": "Silbertaler",
|
||||
|
||||
|
||||
}]
|
11
src/index.js
11
src/index.js
@ -1,9 +1,12 @@
|
||||
require('dotenv').config();
|
||||
const Discord = require('discord.js');
|
||||
const bot = new Discord.Client();
|
||||
const client = new Discord.Client();
|
||||
const SERVERID = process.env.SERVERID
|
||||
const commandHandler = require('./commands');
|
||||
|
||||
bot.on('message', commandHandler);
|
||||
|
||||
bot.login(process.env.BOT_TOKEN);
|
||||
client.on('message', commandHandler);
|
||||
|
||||
client.login(process.env.BOT_TOKEN);
|
||||
client.once('ready', () => {
|
||||
console.log('Ready!');
|
||||
});
|
Reference in New Issue
Block a user