final version

This commit is contained in:
root
2020-03-25 17:03:18 +01:00
parent 6e0a5c704a
commit 8765b38c2f
6 changed files with 40 additions and 22 deletions

View File

@ -1 +0,0 @@
BOT_TOKEN = #YOUR_BOT_TOKEN_HERE

View File

@ -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.');
});
}
});

View File

@ -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.');
}
});

View File

@ -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) => {

View File

@ -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.');
});
}
}
});
}

View File

@ -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.');
}
}
);
};