From 8765b38c2fb4793ea3bab3c07c0f006520ae41cf Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2020 17:03:18 +0100 Subject: [PATCH] final version --- .sample.env | 1 - src/commands/add.js | 12 +++++++----- src/commands/create.js | 6 +++--- src/commands/index.js | 9 +++++---- src/commands/remove.js | 23 ++++++++++++++++------- src/commands/show.js | 11 +++++++++-- 6 files changed, 40 insertions(+), 22 deletions(-) delete mode 100644 .sample.env diff --git a/.sample.env b/.sample.env deleted file mode 100644 index 365335d..0000000 --- a/.sample.env +++ /dev/null @@ -1 +0,0 @@ -BOT_TOKEN = #YOUR_BOT_TOKEN_HERE \ No newline at end of file diff --git a/src/commands/add.js b/src/commands/add.js index 3c8c0d4..c5e49b9 100644 --- a/src/commands/add.js +++ b/src/commands/add.js @@ -3,11 +3,11 @@ module.exports = async (message, args, db) => { if(!isNaN(args[0]) && (args[1] === 'GD' || args[1] === 'ST' || args[1] === 'BH' || args[1] === 'EK')) { // 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 && err) { message.reply('Es gab einen Fehler.'); } - if(row.length < 1) { //if the user is not in the database + if(typeof(row) == 'undefined') { //if the user is not in the database message.reply('Es existiert kein Eintrag für dich füge ihn mit !create hinzu.'); } else { //if the user is in the database if(args[1] === 'GD') { @@ -18,12 +18,14 @@ module.exports = async (message, args, db) => { n = parseInt(row[0].BH, 10) + parseInt(args[0], 10); } else if(args[1] === 'EK') { n = parseInt(row[0].EK, 10) + parseInt(args[0], 10); + } else if(args[1] === 'LP') { + n = parseInt(row[0].EK, 10) + parseInt(args[0], 10); } // eslint-disable-next-line no-undef - db.query('UPDATE DSAGeld SET' + '`' + args[1] + '`' + ' = (' + n + ') WHERE userName = ' + '"' + message.author.tag + '"'); + db.query('UPDATE dsageld SET' + '`' + args[1] + '`' + ' = (' + n + ') WHERE userName = ' + '"' + message.author.tag + '"'); // 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 - message.reply(args[0] + args[1] + ' hinzugefügt, du hast: ' + row[0].GD + 'GD, ' + row[0].ST + 'ST, ' + row[0].BH + 'BH, ' + row[0].EK + 'EK.'); + db.query('SELECT * FROM dsageld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data + message.reply(args[0] + args[1] + ' hinzugefügt, du hast: ' + row[0].GD + 'GD, ' + row[0].ST + 'ST, ' + row[0].BH + 'BH, ' + row[0].EK + 'EK, ' + row[0].LP + 'LeP.'); }); } }); diff --git a/src/commands/create.js b/src/commands/create.js index 078faa3..7c5b70d 100644 --- a/src/commands/create.js +++ b/src/commands/create.js @@ -1,11 +1,11 @@ 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 + 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`) VALUES (' + '"' + message.author.tag + '"' + ', 0, 0, 0, 0)'); + db.query('INSERT INTO `dsageld` (`userName`, `GD`,`ST`, `BH`, `EK`, `LP`) VALUES (' + '"' + message.author.tag + '"' + ', 0, 0, 0, 0, 0)'); message.reply('Dein Eintrag wurde registriert.'); - } else if(row) { + } else if(row.length >= 1) { message.reply('Dein Eintrag existiert bereits.'); } }); diff --git a/src/commands/index.js b/src/commands/index.js index 4a4b907..5186e62 100644 --- a/src/commands/index.js +++ b/src/commands/index.js @@ -4,6 +4,7 @@ const add = require('./add'); const remove = require('./remove'); const show = require('./show'); const mysql = require('mysql'); +require('dotenv').config(); const prefix = '!'; const commands = { @@ -15,11 +16,11 @@ const commands = { }; var db = mysql.createConnection({ - host : 'remotemysql.com', + host : 'localhost', port : '3306', - user : 'tftipudgeE', - password : 'GYKju7YA1p', - database : 'tftipudgeE' + user : 'root', + password : 'dsa_bot_db', + database : 'DSA' }); db.connect((err) => { diff --git a/src/commands/remove.js b/src/commands/remove.js index 1cd332c..21ff9ab 100644 --- a/src/commands/remove.js +++ b/src/commands/remove.js @@ -3,11 +3,11 @@ module.exports = async (message, args, db) => { if(!isNaN(args[0]) && (args[1] === 'GD' || args[1] === 'ST' || args[1] === 'BH' || args[1] === 'EK')) { // 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 dsaeld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data if(row && err) { message.reply('Es gab einen Fehler.'); } - if(!row) { //if the user is not in the database + if(typeof(row) == 'undefined') { //if the user is not in the database message.reply('Es existiert kein Eintrag für dich füge ihn mit !create hinzu.'); } else { //if the user is in the database @@ -19,18 +19,27 @@ module.exports = async (message, args, db) => { n = parseInt(row[0].BH, 10) - parseInt(args[0], 10); } else if(args[1] === 'EK') { n = parseInt(row[0].EK, 10) - parseInt(args[0], 10); + } else if(args[1] === 'LP') { + n = parseInt(row[0].EK, 10) - parseInt(args[0], 10); } if(n >= 0) { // eslint-disable-next-line no-undef - db.query('UPDATE DSAGeld SET' + '`' + args[1] + '`' + ' = (' + n + ') WHERE userName = ' + '"' + message.author.tag + '"'); + db.query('UPDATE dsageld SET' + '`' + args[1] + '`' + ' = (' + n + ') WHERE userName = ' + '"' + message.author.tag + '"'); // 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 - message.reply(args[0] + args[1] + ' abgezogen, du hast: ' + row[0].GD + 'GD, ' + row[0].ST + 'ST, ' + row[0].BH + 'BH, ' + row[0].EK + 'EK.'); + db.query('SELECT * FROM dsageld WHERE userName = ' + '"' + message.author.tag + '"', function(err, row) { //the row is the user's data + message.reply(args[0] + args[1] + ' abgezogen, du hast: ' + row[0].GD + 'GD, ' + row[0].ST + 'ST, ' + row[0].BH + 'BH, ' + row[0].EK + 'EK,' + row[0].LP + 'LeP.'); }); - } else if(n < 0) { + } else if(n < 0 && !(args[1] === 'LP')) { message.reply('du hast nicht genügend ' + args[1] ); - } + } else if(n < 0 && args[1] === 'LP') { + // eslint-disable-next-line no-undef + db.query('UPDATE dsageld SET' + '`' + args[1] + '`' + ' = (' + n + ') WHERE userName = ' + '"' + message.author.tag + '"'); + // 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 + message.reply('Deine LeP sind unter Null: ' + n + ' LeP.'); + }); + } } }); } diff --git a/src/commands/show.js b/src/commands/show.js index bd2cacf..9fcd605 100644 --- a/src/commands/show.js +++ b/src/commands/show.js @@ -1,8 +1,15 @@ // 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 - message.reply('du hast: ' + row[0].GD + ' GD, ' + row[0].ST + ' ST, ' + row[0].BH + ' BH, ' + row[0].EK + ' EK.' ); + 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.'); + } + if(row.length < 1) { //if the user is not in the database + message.reply('Es existiert kein Eintrag für dich füge ihn mit !create hinzu.'); + } else if(row.length >= 1){ + message.reply('du hast: ' + row[0].GD + ' GD, ' + row[0].ST + ' ST, ' + row[0].BH + ' BH, ' + row[0].EK + ' EK.' + row[0].LP + ' LeP.'); + } } ); }; \ No newline at end of file