migrated to mariadb
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
"dotenv": "^8.2.0",
|
||||
"eris": "^0.13.3",
|
||||
"express-authentication": "^0.3.2",
|
||||
"mariadb": "^2.4.2",
|
||||
"moment": "^2.27.0",
|
||||
"sequelize": "^6.3.3",
|
||||
"sqlite3": "^5.0.0"
|
||||
|
||||
@@ -27,7 +27,7 @@ module.exports.ScoreMember = async function(erismember)
|
||||
if (erismember.bot)
|
||||
{
|
||||
ret.score = 999;
|
||||
ret.warnins.push({warning:'member is bot', severity: 0});
|
||||
ret.warnings.push({warning:'member is bot', severity: 0});
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ const Logger = require('./logger.js');
|
||||
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
let Database;
|
||||
|
||||
let Guild;
|
||||
|
||||
module.exports.setup = async function()
|
||||
@@ -11,17 +13,22 @@ module.exports.setup = async function()
|
||||
if (process.env.NODE_ENV == "production")
|
||||
{
|
||||
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 {
|
||||
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: {
|
||||
type: Sequelize.STRING,
|
||||
primaryKey: true,
|
||||
@@ -30,6 +37,7 @@ module.exports.setup = async function()
|
||||
name: Sequelize.STRING,
|
||||
prefix: Sequelize.STRING,
|
||||
logchannel: Sequelize.STRING,
|
||||
guildsettings: Sequelize.JSON,
|
||||
logsettings: Sequelize.JSON, // JSON / Array
|
||||
modcases: Sequelize.INTEGER
|
||||
}, {
|
||||
@@ -38,8 +46,8 @@ module.exports.setup = async function()
|
||||
|
||||
try
|
||||
{
|
||||
await database.authenticate();
|
||||
await database.sync();
|
||||
await Database.authenticate();
|
||||
await Database.sync();
|
||||
Logger.info('Database connection has been established successfully.');
|
||||
} catch (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 {
|
||||
let user = await Guild.create({
|
||||
@@ -55,6 +63,7 @@ module.exports.NewGuild = async function(id, name, prefix, logchannel, logsettin
|
||||
name: name,
|
||||
prefix: prefix,
|
||||
logchannel: logchannel, // -1 if not set
|
||||
guildsettings: guildsettings,
|
||||
logsettings: logsettings,
|
||||
modcases: modcases
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ module.exports.newMessage = async function(message)
|
||||
} catch (e) {
|
||||
GuildName = 'not defined';
|
||||
}
|
||||
Database.NewGuild(message.guildID, GuildName, '*', -1, {}, 0);
|
||||
Database.NewGuild(message.guildID, GuildName, '*', -1, {}, {}, 0);
|
||||
GuildsAndPrefixs[message.guildID] = '*'
|
||||
} else
|
||||
{
|
||||
@@ -117,7 +117,7 @@ async function InitializeGuild(message, args)
|
||||
const guild = await Discord.bot.getRESTGuild(message.guildID);
|
||||
if (AlreadyGuild == -1)
|
||||
{
|
||||
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, 0);
|
||||
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, {}, 0);
|
||||
} else {
|
||||
if (AlreadyGuild.name != guild.name)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ async function SetLogChannel(message, args)
|
||||
const guild = await Discord.bot.getRESTGuild(message.guildID);
|
||||
if (AlreadyGuild == -1)
|
||||
{
|
||||
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, 0);
|
||||
Database.NewGuild(guild.id, guild.name, '*', message.channel.id, {}, {}, 0);
|
||||
} else {
|
||||
if (AlreadyGuild.name != guild.name)
|
||||
{
|
||||
|
||||
@@ -171,7 +171,7 @@ async function GuildCreate(guild)
|
||||
const AlreadyGuild = await Database.FetchGuild(guild.id);
|
||||
if (AlreadyGuild == -1)
|
||||
{
|
||||
Database.NewGuild(guild.id, guild.name, '*', -1, {}, 0);
|
||||
Database.NewGuild(guild.id, guild.name, '*', -1, {}, {}, 0);
|
||||
} else {
|
||||
if (AlreadyGuild.name == guild.name) return;
|
||||
Database.UpdateGuildName(guild.id, guild.name);
|
||||
@@ -609,6 +609,9 @@ async function GuildMemberRemove(guild, member)
|
||||
}
|
||||
|
||||
async function GuildMemberUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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!')
|
||||
|
||||
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 () => {
|
||||
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');
|
||||
|
||||
let LogLevel = 1;
|
||||
let Dialect = 'SQLITE';
|
||||
let Dialect;
|
||||
let logPath = 'logs.log';
|
||||
let dateFormat = 'DD-MM-YY HH:mm:ss'
|
||||
|
||||
module.exports.init = function(path) {
|
||||
if (path) logPath = path;
|
||||
|
||||
Dialect = process.env.NODE_ENV == 'production' ? 'MARIADB' : 'SQLITE';
|
||||
|
||||
if (!fs.existsSync(logPath)) {
|
||||
fs.writeFileSync(logPath, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user