can now store users in database + database file
This commit is contained in:
@ -5,11 +5,10 @@ const Database = async (db) => {
|
||||
const server = sql.createConnection({
|
||||
host : db.DB_HOST,
|
||||
user : db.DB_USERNAME,
|
||||
password : db.DB_PASSWORD
|
||||
,
|
||||
password : db.DB_PASSWORD,
|
||||
database : db.DB_NAME
|
||||
});
|
||||
|
||||
|
||||
server.connect(function(err) {
|
||||
if (err) {
|
||||
console.error('error connecting Database in Data.Database: ' + err.stack);
|
||||
|
50
Commons/Data/Reactions.js
Normal file
50
Commons/Data/Reactions.js
Normal file
@ -0,0 +1,50 @@
|
||||
const mysql = require("mysql");
|
||||
/**
|
||||
* creates a Reaction and stores it in the databse
|
||||
* @param sql {Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a Reaction on
|
||||
* @param Reaction {string} the id of which Reaction you want to store
|
||||
* @param Reactionname {string} the Reactionname of the Reaction you want to store
|
||||
* @param nickname {string} if the nickname of the Reaction if he got any
|
||||
* @param owner {boolean} whether or not the Reaction is the server owner
|
||||
*/
|
||||
let CreateReaction = async (sql, server, Reaction, Reactionname, owner) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a Reaction from databse
|
||||
* @param sql {mysql.Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a Reaction on
|
||||
* @param Reaction {string} the id of which Reaction you want to store
|
||||
*/
|
||||
let GetReaction = async (sql, server, Reaction) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
/**
|
||||
* updates a Reaction and stores it in the databse
|
||||
* @param sql {mysql.Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a Reaction on
|
||||
* @param Reaction {string} the id of which Reaction you want to store
|
||||
* @param Reactionname {string} the Reactionname of the Reaction you want to store
|
||||
* @param nickname {string} if the nickname of the Reaction if he got any
|
||||
* @param owner {boolean} whether or not the Reaction is the server owner
|
||||
* @param xp {number} the xp the specified Reaction has
|
||||
* @param level {number} the level the Reaction has
|
||||
*/
|
||||
let UpdateReaction = async (sql, server, Reaction, Reactionname, nickname, owner, xp, level) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a Reaction from databse
|
||||
* @param sql {mysql.Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a Reaction on
|
||||
* @param Reaction {string} the id of which Reaction you want to store
|
||||
*/
|
||||
let RemoveReaction = async (sql, server, Reaction) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
module.exports = {CreateReaction, GetReaction, UpdateReaction, RemoveReaction}
|
61
Commons/Data/User.js
Normal file
61
Commons/Data/User.js
Normal file
@ -0,0 +1,61 @@
|
||||
const mysql = require("mysql");
|
||||
/**
|
||||
* creates a user and stores it in the databse
|
||||
* @param sql {Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a user on
|
||||
* @param user {string} the id of which user you want to store
|
||||
* @param username {string} the username of the user you want to store
|
||||
* @param nickname {string} if the nickname of the user if he got any
|
||||
* @param owner {boolean} whether or not the user is the server owner
|
||||
*/
|
||||
let CreateUser = async (sql, server, user, username, owner) => {
|
||||
sql.query({
|
||||
sql: 'INSERT INTO serverusers SET ?',
|
||||
timeout: 40000, // 40s
|
||||
values: {serverid: server, userid: user, username: username, owner: owner}
|
||||
}, function (error, results, fields) {
|
||||
// error will be an Error if one occurred during the query
|
||||
if (error != undefined | null) {
|
||||
throw `could not create user on server ${server} with userid ${user} due to error: ` + error
|
||||
}
|
||||
// results will contain the results of the query
|
||||
// fields will contain information about the returned results fields (if any)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a user from databse
|
||||
* @param sql {mysql.Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a user on
|
||||
* @param user {string} the id of which user you want to store
|
||||
*/
|
||||
let GetUser = async (sql, server, user) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
/**
|
||||
* updates a user and stores it in the databse
|
||||
* @param sql {mysql.Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a user on
|
||||
* @param user {string} the id of which user you want to store
|
||||
* @param username {string} the username of the user you want to store
|
||||
* @param nickname {string} if the nickname of the user if he got any
|
||||
* @param owner {boolean} whether or not the user is the server owner
|
||||
* @param xp {number} the xp the specified user has
|
||||
* @param level {number} the level the user has
|
||||
*/
|
||||
let UpdateUser = async (sql, server, user, username, nickname, owner, xp, level) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
/**
|
||||
* gets a user from databse
|
||||
* @param sql {mysql.Connection} the mysql connection object
|
||||
* @param server {string} the id of which server you want ot create a user on
|
||||
* @param user {string} the id of which user you want to store
|
||||
*/
|
||||
let RemoveUser = async (sql, server, user) => {
|
||||
throw "not implemented";
|
||||
}
|
||||
|
||||
module.exports = {CreateUser, GetUser, UpdateUser, RemoveUser}
|
@ -52,6 +52,20 @@ const DevData = {
|
||||
MessageType: "public",
|
||||
}
|
||||
}
|
||||
},
|
||||
"1099317452170596523": {
|
||||
type: "reactionRole",
|
||||
reactions: {
|
||||
"🪙":{
|
||||
Action: "role",
|
||||
Role: {
|
||||
Name: "Gold Role",
|
||||
ID: "1051891644007469096"
|
||||
},
|
||||
Restriction: "AddOnly",
|
||||
MessageType: "public",
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,17 +94,6 @@ revokes a given roles to a given user
|
||||
*/
|
||||
const RemoveRoles = async (userVal, roles, bot) => {
|
||||
|
||||
[
|
||||
{
|
||||
name: "role",
|
||||
reason: "given as a test"
|
||||
},
|
||||
{
|
||||
name: "role",
|
||||
reason: undefined
|
||||
},
|
||||
]
|
||||
|
||||
// error handling
|
||||
if (userVal == undefined) { throw "error user was undefined" }
|
||||
if (roleName == undefined) { throw "error roleNames was undefined" }
|
||||
|
Reference in New Issue
Block a user