migrated to mariadb
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"eris": "^0.13.3",
|
"eris": "^0.13.3",
|
||||||
"express-authentication": "^0.3.2",
|
"express-authentication": "^0.3.2",
|
||||||
|
"mariadb": "^2.4.2",
|
||||||
"moment": "^2.27.0",
|
"moment": "^2.27.0",
|
||||||
"sequelize": "^6.3.3",
|
"sequelize": "^6.3.3",
|
||||||
"sqlite3": "^5.0.0"
|
"sqlite3": "^5.0.0"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module.exports.ScoreMember = async function(erismember)
|
|||||||
if (erismember.bot)
|
if (erismember.bot)
|
||||||
{
|
{
|
||||||
ret.score = 999;
|
ret.score = 999;
|
||||||
ret.warnins.push({warning:'member is bot', severity: 0});
|
ret.warnings.push({warning:'member is bot', severity: 0});
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ const Logger = require('./logger.js');
|
|||||||
|
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
|
|
||||||
|
let Database;
|
||||||
|
|
||||||
let Guild;
|
let Guild;
|
||||||
|
|
||||||
module.exports.setup = async function()
|
module.exports.setup = async function()
|
||||||
@@ -11,17 +13,22 @@ module.exports.setup = async function()
|
|||||||
if (process.env.NODE_ENV == "production")
|
if (process.env.NODE_ENV == "production")
|
||||||
{
|
{
|
||||||
Logger.database('Setting up production databse');
|
Logger.database('Setting up production databse');
|
||||||
|
Database = new Sequelize(process.env.DB_DATABASE, process.env.DB_USER, process.env.DB_PASS, {
|
||||||
|
dialect: 'mariadb',
|
||||||
|
logging: Logger.database
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
Logger.database('Setting up development databse');
|
Logger.database('Setting up development databse');
|
||||||
|
Database = new Sequelize({
|
||||||
|
dialect: 'sqlite',
|
||||||
|
storage: process.env.DB_DEV_LOCATION,
|
||||||
|
logging: Logger.database
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const database = new Sequelize({
|
|
||||||
dialect: 'sqlite',
|
|
||||||
storage: process.env.NODE_ENV == "production" ? process.env.DB_LOCATION : process.env.DB_DEV_LOCATION,
|
|
||||||
logging: Logger.database
|
|
||||||
});
|
|
||||||
|
|
||||||
Guild = database.define('guild', {
|
|
||||||
|
Guild = Database.define('guild', {
|
||||||
id: {
|
id: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
@@ -30,6 +37,7 @@ module.exports.setup = async function()
|
|||||||
name: Sequelize.STRING,
|
name: Sequelize.STRING,
|
||||||
prefix: Sequelize.STRING,
|
prefix: Sequelize.STRING,
|
||||||
logchannel: Sequelize.STRING,
|
logchannel: Sequelize.STRING,
|
||||||
|
guildsettings: Sequelize.JSON,
|
||||||
logsettings: Sequelize.JSON, // JSON / Array
|
logsettings: Sequelize.JSON, // JSON / Array
|
||||||
modcases: Sequelize.INTEGER
|
modcases: Sequelize.INTEGER
|
||||||
}, {
|
}, {
|
||||||
@@ -38,8 +46,8 @@ module.exports.setup = async function()
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await database.authenticate();
|
await Database.authenticate();
|
||||||
await database.sync();
|
await Database.sync();
|
||||||
Logger.info('Database connection has been established successfully.');
|
Logger.info('Database connection has been established successfully.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.panic('Unable to connect to the database:', error);
|
Logger.panic('Unable to connect to the database:', error);
|
||||||
@@ -47,7 +55,7 @@ module.exports.setup = async function()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.NewGuild = async function(id, name, prefix, logchannel, logsettings, modcases)
|
module.exports.NewGuild = async function(id, name, prefix, logchannel, guildsettings, logsettings, modcases)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
let user = await Guild.create({
|
let user = await Guild.create({
|
||||||
@@ -55,6 +63,7 @@ module.exports.NewGuild = async function(id, name, prefix, logchannel, logsettin
|
|||||||
name: name,
|
name: name,
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
logchannel: logchannel, // -1 if not set
|
logchannel: logchannel, // -1 if not set
|
||||||
|
guildsettings: guildsettings,
|
||||||
logsettings: logsettings,
|
logsettings: logsettings,
|
||||||
modcases: modcases
|
modcases: modcases
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ module.exports.newMessage = async function(message)
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
GuildName = 'not defined';
|
GuildName = 'not defined';
|
||||||
}
|
}
|
||||||
Database.NewGuild(message.guildID, GuildName, '*', -1, {}, 0);
|
Database.NewGuild(message.guildID, GuildName, '*', -1, {}, {}, 0);
|
||||||
GuildsAndPrefixs[message.guildID] = '*'
|
GuildsAndPrefixs[message.guildID] = '*'
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@@ -117,7 +117,7 @@ async function InitializeGuild(message, args)
|
|||||||
const guild = await Discord.bot.getRESTGuild(message.guildID);
|
const guild = await Discord.bot.getRESTGuild(message.guildID);
|
||||||
if (AlreadyGuild == -1)
|
if (AlreadyGuild == -1)
|
||||||
{
|
{
|
||||||
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, 0);
|
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, {}, 0);
|
||||||
} else {
|
} else {
|
||||||
if (AlreadyGuild.name != guild.name)
|
if (AlreadyGuild.name != guild.name)
|
||||||
{
|
{
|
||||||
@@ -155,7 +155,7 @@ async function SetLogChannel(message, args)
|
|||||||
const guild = await Discord.bot.getRESTGuild(message.guildID);
|
const guild = await Discord.bot.getRESTGuild(message.guildID);
|
||||||
if (AlreadyGuild == -1)
|
if (AlreadyGuild == -1)
|
||||||
{
|
{
|
||||||
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, 0);
|
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, {}, 0);
|
||||||
} else {
|
} else {
|
||||||
if (AlreadyGuild.name != guild.name)
|
if (AlreadyGuild.name != guild.name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ async function GuildCreate(guild)
|
|||||||
const AlreadyGuild = await Database.FetchGuild(guild.id);
|
const AlreadyGuild = await Database.FetchGuild(guild.id);
|
||||||
if (AlreadyGuild == -1)
|
if (AlreadyGuild == -1)
|
||||||
{
|
{
|
||||||
Database.NewGuild(guild.id, guild.name, '*', -1, {}, 0);
|
Database.NewGuild(guild.id, guild.name, '*', -1, {}, {}, 0);
|
||||||
} else {
|
} else {
|
||||||
if (AlreadyGuild.name == guild.name) return;
|
if (AlreadyGuild.name == guild.name) return;
|
||||||
Database.UpdateGuildName(guild.id, guild.name);
|
Database.UpdateGuildName(guild.id, guild.name);
|
||||||
@@ -609,6 +609,9 @@ async function GuildMemberRemove(guild, member)
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function GuildMemberUpdate()
|
async function GuildMemberUpdate()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
async function MessageDelete(message)
|
async function MessageDelete(message)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ module.exports.setup = async function()
|
|||||||
|
|
||||||
if (!process.env.BOT_TOKEN) Logger.panic('No BOT_TOKEN in .env file!')
|
if (!process.env.BOT_TOKEN) Logger.panic('No BOT_TOKEN in .env file!')
|
||||||
|
|
||||||
this.bot = new Eris(process.env.BOT_TOKEN, {allowedMentions: false, restMode: true});
|
this.bot = new Eris(process.env.NODE_ENV == 'production' ? process.env.BOT_TOKEN : process.env.BOT_DEV_TOKEN,
|
||||||
|
{allowedMentions: false, restMode: true});
|
||||||
|
|
||||||
this.bot.on('ready', async () => {
|
this.bot.on('ready', async () => {
|
||||||
Logger.info(`Discord logged in as ${this.bot.user.username}#${this.bot.user.discriminator}`);
|
Logger.info(`Discord logged in as ${this.bot.user.username}#${this.bot.user.discriminator}`);
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ const moment = require('moment');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
let LogLevel = 1;
|
let LogLevel = 1;
|
||||||
let Dialect = 'SQLITE';
|
let Dialect;
|
||||||
let logPath = 'logs.log';
|
let logPath = 'logs.log';
|
||||||
let dateFormat = 'DD-MM-YY HH:mm:ss'
|
let dateFormat = 'DD-MM-YY HH:mm:ss'
|
||||||
|
|
||||||
module.exports.init = function(path) {
|
module.exports.init = function(path) {
|
||||||
if (path) logPath = path;
|
if (path) logPath = path;
|
||||||
|
|
||||||
|
Dialect = process.env.NODE_ENV == 'production' ? 'MARIADB' : 'SQLITE';
|
||||||
|
|
||||||
if (!fs.existsSync(logPath)) {
|
if (!fs.existsSync(logPath)) {
|
||||||
fs.writeFileSync(logPath, '');
|
fs.writeFileSync(logPath, '');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user