173 lines
2.3 KiB
JavaScript
173 lines
2.3 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const bot_instances = sequelize.define(
|
|
'bot_instances',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
instance_name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
bot_client_key: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"online",
|
|
|
|
|
|
"offline",
|
|
|
|
|
|
"starting",
|
|
|
|
|
|
"error",
|
|
|
|
|
|
"reconnecting"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
auto_reconnect_enabled: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
reconnect_backoff_seconds: {
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
|
|
},
|
|
|
|
last_connected_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
last_disconnect_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
last_error_message: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
bot_instances.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.bot_instances.hasMany(db.voice_sessions, {
|
|
as: 'voice_sessions_bot_instance',
|
|
foreignKey: {
|
|
name: 'bot_instanceId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.bot_instances.belongsTo(db.discord_servers, {
|
|
as: 'discord_server',
|
|
foreignKey: {
|
|
name: 'discord_serverId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.bot_instances.belongsTo(db.voice_channels, {
|
|
as: 'current_voice_channel',
|
|
foreignKey: {
|
|
name: 'current_voice_channelId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.bot_instances.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.bot_instances.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return bot_instances;
|
|
};
|
|
|
|
|