generated from Baipyrus/DiscordJS-Template
refactor: project wide renaming for accuracy
This commit is contained in:
parent
d9952d79e9
commit
db898a2a36
@ -4,7 +4,7 @@ import {
|
|||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
ChatInputCommandInteraction
|
ChatInputCommandInteraction
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { Guild, VoiceChannel } from '../../../database.js';
|
import { Guilds, VoiceChannels } from '../../../database.js';
|
||||||
|
|
||||||
export const data = new SlashCommandBuilder()
|
export const data = new SlashCommandBuilder()
|
||||||
.setName('custom_vc')
|
.setName('custom_vc')
|
||||||
@ -68,12 +68,12 @@ export async function execute(interaction) {
|
|||||||
|
|
||||||
step = 'save';
|
step = 'save';
|
||||||
// Create guild if not exists
|
// Create guild if not exists
|
||||||
await Guild.findOrCreate({
|
await Guilds.findOrCreate({
|
||||||
where: guildData,
|
where: guildData,
|
||||||
defaults: guildData
|
defaults: guildData
|
||||||
});
|
});
|
||||||
// Save channel data
|
// Save channel data
|
||||||
await VoiceChannel.create({
|
await VoiceChannels.create({
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
guild: guild.id,
|
guild: guild.id,
|
||||||
create: true
|
create: true
|
||||||
@ -94,12 +94,12 @@ export async function execute(interaction) {
|
|||||||
|
|
||||||
step = 'save';
|
step = 'save';
|
||||||
// Create guild if not exists
|
// Create guild if not exists
|
||||||
await Guild.findOrCreate({
|
await Guilds.findOrCreate({
|
||||||
where: guildData,
|
where: guildData,
|
||||||
defaults: guildData
|
defaults: guildData
|
||||||
});
|
});
|
||||||
// Save channel data
|
// Save channel data
|
||||||
await VoiceChannel.create({
|
await VoiceChannels.create({
|
||||||
id,
|
id,
|
||||||
guild: guild.id,
|
guild: guild.id,
|
||||||
create: true
|
create: true
|
||||||
@ -120,7 +120,7 @@ export async function execute(interaction) {
|
|||||||
|
|
||||||
// Remove channel from guild
|
// Remove channel from guild
|
||||||
step = 'remove';
|
step = 'remove';
|
||||||
const count = await VoiceChannel.destroy({
|
const count = await VoiceChannels.destroy({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
create: true
|
create: true
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
import { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction } from 'discord.js';
|
import { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { Role, Guild } from '../../../database.js';
|
import { Roles, Guilds } from '../../../database.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Guild} guild
|
* @param {Guilds} guild
|
||||||
* @param {Role} role
|
* @param {Roles} role
|
||||||
*/
|
*/
|
||||||
const registerRole = async (guild, role) => {
|
const registerRole = async (guild, role) => {
|
||||||
// Check if guild exists in database, otherwise create it
|
// Check if guild exists in database, otherwise create it
|
||||||
const guildData = { id: guild.id };
|
const guildData = { id: guild.id };
|
||||||
await Guild.findOrCreate({
|
await Guilds.findOrCreate({
|
||||||
where: guildData,
|
where: guildData,
|
||||||
defaults: guildData
|
defaults: guildData
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register role in database
|
// Register role in database
|
||||||
await Role.create({
|
await Roles.create({
|
||||||
guild: guild.id,
|
guild: guild.id,
|
||||||
id: role.id,
|
id: role.id,
|
||||||
assign: true
|
assign: true
|
||||||
@ -57,7 +57,7 @@ export async function execute(interaction) {
|
|||||||
switch (options.getSubcommand()) {
|
switch (options.getSubcommand()) {
|
||||||
case 'add': {
|
case 'add': {
|
||||||
// Search for role in database
|
// Search for role in database
|
||||||
const found = await Role.findOne({
|
const found = await Roles.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: role.id
|
id: role.id
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ export async function execute(interaction) {
|
|||||||
}
|
}
|
||||||
case 'remove': {
|
case 'remove': {
|
||||||
// Remove role from database
|
// Remove role from database
|
||||||
const count = await Role.destroy({
|
const count = await Roles.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: role.id,
|
id: role.id,
|
||||||
assign: true
|
assign: true
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
PermissionFlagsBits,
|
PermissionFlagsBits,
|
||||||
ContextMenuCommandInteraction
|
ContextMenuCommandInteraction
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { Message } from '../../../../database.js';
|
import { Messages } from '../../../../database.js';
|
||||||
|
|
||||||
export const data = new ContextMenuCommandBuilder()
|
export const data = new ContextMenuCommandBuilder()
|
||||||
.setDMPermission(false)
|
.setDMPermission(false)
|
||||||
@ -17,7 +17,7 @@ export async function execute(interaction) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Create database entry
|
// Create database entry
|
||||||
await Message.create({ id });
|
await Messages.create({ id });
|
||||||
|
|
||||||
// Reply successfully to acknowledge command
|
// Reply successfully to acknowledge command
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { PermissionFlagsBits, SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
|
import { PermissionFlagsBits, SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
|
||||||
import { addSelfRoles, removeSelfRoles } from '../../../shared.js';
|
import { addSelfRoles, removeSelfRoles } from '../../../shared.js';
|
||||||
import { Guild, Message } from '../../../database.js';
|
import { Guilds, Messages } from '../../../database.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a `Message` in the current channel and registers for self roles.
|
* Sends a `Message` in the current channel and registers for self roles.
|
||||||
@ -48,11 +48,11 @@ const registerSelfRoles = async (interaction) => {
|
|||||||
await channel.messages.fetch(id);
|
await channel.messages.fetch(id);
|
||||||
|
|
||||||
// Check if message is already registered
|
// Check if message is already registered
|
||||||
const found = await Message.findOne({
|
const found = await Messages.findOne({
|
||||||
where: { id }
|
where: { id }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (found) throw new Error('Message already registered!');
|
if (found) throw new Error('Messages already registered!');
|
||||||
|
|
||||||
// Reply successfully to acknowledge command
|
// Reply successfully to acknowledge command
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
@ -196,13 +196,13 @@ export async function execute(interaction) {
|
|||||||
try {
|
try {
|
||||||
// Create guild if not exists
|
// Create guild if not exists
|
||||||
const guildData = { id: interaction.guild.id };
|
const guildData = { id: interaction.guild.id };
|
||||||
await Guild.findOrCreate({
|
await Guilds.findOrCreate({
|
||||||
where: guildData,
|
where: guildData,
|
||||||
defaults: guildData
|
defaults: guildData
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create database entry
|
// Create database entry
|
||||||
await Message.create({
|
await Messages.create({
|
||||||
id,
|
id,
|
||||||
guild: interaction.guild.id
|
guild: interaction.guild.id
|
||||||
});
|
});
|
||||||
|
30
database.js
30
database.js
@ -18,26 +18,26 @@ const sequelize = new Sequelize({
|
|||||||
logging: false
|
logging: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const Response = defineResponse(sequelize);
|
const Responses = defineResponse(sequelize);
|
||||||
|
|
||||||
const Keyword = defineKeyword(sequelize);
|
const Keywords = defineKeyword(sequelize);
|
||||||
Keyword.hasMany(Response, { foreignKey: 'keyword', onDelete: 'CASCADE' });
|
Keywords.hasMany(Responses, { foreignKey: 'keyword', onDelete: 'CASCADE' });
|
||||||
|
|
||||||
const RoleEmojiPair = defineRoleEmojiPair(sequelize);
|
const RoleEmojiPairs = defineRoleEmojiPair(sequelize);
|
||||||
|
|
||||||
const VoiceChannel = defineVoiceChannel(sequelize);
|
const VoiceChannels = defineVoiceChannel(sequelize);
|
||||||
|
|
||||||
const Message = defineMessage(sequelize);
|
const Messages = defineMessage(sequelize);
|
||||||
Message.hasMany(RoleEmojiPair, { foreignKey: 'message', onDelete: 'CASCADE' });
|
Messages.hasMany(RoleEmojiPairs, { foreignKey: 'message', onDelete: 'CASCADE' });
|
||||||
|
|
||||||
const Role = defineRole(sequelize);
|
const Roles = defineRole(sequelize);
|
||||||
Role.hasMany(RoleEmojiPair, { foreignKey: 'role', onDelete: 'CASCADE' });
|
Roles.hasMany(RoleEmojiPairs, { foreignKey: 'role', onDelete: 'CASCADE' });
|
||||||
|
|
||||||
const Guild = defineGuild(sequelize);
|
const Guilds = defineGuild(sequelize);
|
||||||
Guild.hasMany(Keyword, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
Guilds.hasMany(Keywords, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
||||||
Guild.hasMany(VoiceChannel, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
Guilds.hasMany(VoiceChannels, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
||||||
Guild.hasMany(Message, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
Guilds.hasMany(Messages, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
||||||
Guild.hasMany(Role, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
Guilds.hasMany(Roles, { foreignKey: 'guild', onDelete: 'CASCADE' });
|
||||||
|
|
||||||
sequelize.sync();
|
sequelize.sync();
|
||||||
export { sequelize, Guild, Role, RoleEmojiPair, VoiceChannel, Message };
|
export { sequelize, Guilds, Roles, Messages, VoiceChannels, RoleEmojiPairs, Keywords, Responses };
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ChannelType, Events, GuildChannel } from 'discord.js';
|
import { ChannelType, Events, GuildChannel } from 'discord.js';
|
||||||
import { VoiceChannel } from '../../database.js';
|
import { VoiceChannels } from '../../database.js';
|
||||||
|
|
||||||
export const name = Events.ChannelDelete;
|
export const name = Events.ChannelDelete;
|
||||||
/** @param {GuildChannel} channel */
|
/** @param {GuildChannel} channel */
|
||||||
@ -7,7 +7,7 @@ export async function execute(channel) {
|
|||||||
if (channel.type !== ChannelType.GuildVoice) return;
|
if (channel.type !== ChannelType.GuildVoice) return;
|
||||||
|
|
||||||
// Delete channel entry once channel is deleted itself
|
// Delete channel entry once channel is deleted itself
|
||||||
const count = await VoiceChannel.destroy({
|
const count = await VoiceChannels.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: channel.id
|
id: channel.id
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
VoiceState,
|
VoiceState,
|
||||||
PermissionsBitField
|
PermissionsBitField
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { VoiceChannel } from '../../database.js';
|
import { VoiceChannels } from '../../database.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that either creates a new custom channel or gets an existing one registered in the database.
|
* Function that either creates a new custom channel or gets an existing one registered in the database.
|
||||||
@ -18,7 +18,7 @@ import { VoiceChannel } from '../../database.js';
|
|||||||
*/
|
*/
|
||||||
const getChannel = async (member, guildChs, channel) => {
|
const getChannel = async (member, guildChs, channel) => {
|
||||||
// Check database for existing channel
|
// Check database for existing channel
|
||||||
const ownCh = await VoiceChannel.findOne({
|
const ownCh = await VoiceChannels.findOne({
|
||||||
where: {
|
where: {
|
||||||
owner: member.id
|
owner: member.id
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ const getChannel = async (member, guildChs, channel) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Save newly created channel
|
// Save newly created channel
|
||||||
await VoiceChannel.create({
|
await VoiceChannels.create({
|
||||||
id: privCh.id,
|
id: privCh.id,
|
||||||
owner: member.id
|
owner: member.id
|
||||||
});
|
});
|
||||||
@ -58,7 +58,7 @@ const leftVoiceChat = async (state) => {
|
|||||||
if (members.length > 0) return;
|
if (members.length > 0) return;
|
||||||
|
|
||||||
// Find channel by id, return if not registered as custom
|
// Find channel by id, return if not registered as custom
|
||||||
const custom = await VoiceChannel.findOne({
|
const custom = await VoiceChannels.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
create: false
|
create: false
|
||||||
@ -84,7 +84,7 @@ export async function execute(oldState, newState) {
|
|||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
// Find channel by id, return if not registered for customs
|
// Find channel by id, return if not registered for customs
|
||||||
const createCh = await VoiceChannel.findOne({
|
const createCh = await VoiceChannels.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: channel.id,
|
id: channel.id,
|
||||||
create: true
|
create: true
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Events, GuildMember } from 'discord.js';
|
import { Events, GuildMember } from 'discord.js';
|
||||||
import { Role } from '../../database.js';
|
import { Roles } from '../../database.js';
|
||||||
|
|
||||||
export const name = Events.GuildMemberAdd;
|
export const name = Events.GuildMemberAdd;
|
||||||
/** @param {GuildMember} member */
|
/** @param {GuildMember} member */
|
||||||
export async function execute(member) {
|
export async function execute(member) {
|
||||||
// Find roles to be assigned in guild from database
|
// Find roles to be assigned in guild from database
|
||||||
const roles = await Role.findAll({
|
const roles = await Roles.findAll({
|
||||||
where: {
|
where: {
|
||||||
guild: member.guild.id,
|
guild: member.guild.id,
|
||||||
assign: true
|
assign: true
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Message } from '../../database.js';
|
import { Messages } from '../../database.js';
|
||||||
import { Events } from 'discord.js';
|
import { Events } from 'discord.js';
|
||||||
|
|
||||||
export const name = Events.MessageDelete;
|
export const name = Events.MessageDelete;
|
||||||
/** @param {import('discord.js').Message} message */
|
/** @param {import('discord.js').Message} message */
|
||||||
export async function execute(message) {
|
export async function execute(message) {
|
||||||
// Delete message entry once message is deleted itself
|
// Delete message entry once message is deleted itself
|
||||||
const count = await Message.destroy({
|
const count = await Messages.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: message.id
|
id: message.id
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Events, MessageReaction, User } from 'discord.js';
|
import { Events, MessageReaction, User } from 'discord.js';
|
||||||
import { Message, RoleEmojiPair } from '../../database.js';
|
import { Messages, RoleEmojiPairs } from '../../database.js';
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
|
|
||||||
config();
|
config();
|
||||||
@ -14,7 +14,7 @@ export async function execute(reaction, user) {
|
|||||||
|
|
||||||
// Get message
|
// Get message
|
||||||
const msgID = reaction.message.id;
|
const msgID = reaction.message.id;
|
||||||
const message = await Message.findOne({
|
const message = await Messages.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: msgID
|
id: msgID
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ export async function execute(reaction, user) {
|
|||||||
|
|
||||||
// Get emoji
|
// Get emoji
|
||||||
const emoji = reaction.emoji.toString();
|
const emoji = reaction.emoji.toString();
|
||||||
const rep = await RoleEmojiPair.findOne({
|
const rep = await RoleEmojiPairs.findOne({
|
||||||
where: {
|
where: {
|
||||||
message: msgID,
|
message: msgID,
|
||||||
emoji
|
emoji
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Events, MessageReaction, User } from 'discord.js';
|
import { Events, MessageReaction, User } from 'discord.js';
|
||||||
import { Message, RoleEmojiPair } from '../../database.js';
|
import { Messages, RoleEmojiPairs } from '../../database.js';
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
|
|
||||||
config();
|
config();
|
||||||
@ -14,7 +14,7 @@ export async function execute(reaction, user) {
|
|||||||
|
|
||||||
// Get message
|
// Get message
|
||||||
const msgID = reaction.message.id;
|
const msgID = reaction.message.id;
|
||||||
const message = await Message.findOne({
|
const message = await Messages.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: msgID
|
id: msgID
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ export async function execute(reaction, user) {
|
|||||||
|
|
||||||
// Get emoji
|
// Get emoji
|
||||||
const emoji = reaction.emoji.toString();
|
const emoji = reaction.emoji.toString();
|
||||||
const rep = await RoleEmojiPair.findOne({
|
const rep = await RoleEmojiPairs.findOne({
|
||||||
where: {
|
where: {
|
||||||
message: msgID,
|
message: msgID,
|
||||||
emoji
|
emoji
|
||||||
|
@ -6,7 +6,7 @@ import { DataTypes, Sequelize } from 'sequelize';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The definition of the `Guild` table in the database.
|
* The definition of the `Guilds` table in the database.
|
||||||
* @param {Sequelize} sequelize
|
* @param {Sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
export default function (sequelize) {
|
export default function (sequelize) {
|
||||||
|
@ -7,7 +7,7 @@ import { DataTypes, Deferrable, Sequelize } from 'sequelize';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The definition of the `Message` table in the database.
|
* The definition of the `Messages` table in the database.
|
||||||
* @param {Sequelize} sequelize
|
* @param {Sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
export default function (sequelize) {
|
export default function (sequelize) {
|
||||||
|
@ -9,7 +9,7 @@ import { DataTypes, Deferrable, Sequelize } from 'sequelize';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The definition of the `RoleEmojiPair` table in the database.
|
* The definition of the `RoleEmojiPairs` table in the database.
|
||||||
* @param {Sequelize} sequelize
|
* @param {Sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
export default function (sequelize) {
|
export default function (sequelize) {
|
||||||
|
@ -8,7 +8,7 @@ import { DataTypes, Deferrable, Sequelize } from 'sequelize';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The definition of the `Role` table in the database.
|
* The definition of the `Roles` table in the database.
|
||||||
* @param {Sequelize} sequelize
|
* @param {Sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
export default function (sequelize) {
|
export default function (sequelize) {
|
||||||
|
@ -9,7 +9,7 @@ import { DataTypes, Deferrable, Sequelize } from 'sequelize';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The definition of the `VoiceChannel` table in the database.
|
* The definition of the `VoiceChannels` table in the database.
|
||||||
* @param {Sequelize} sequelize
|
* @param {Sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
export default function (sequelize) {
|
export default function (sequelize) {
|
||||||
|
16
shared.js
16
shared.js
@ -1,5 +1,5 @@
|
|||||||
import { ChatInputCommandInteraction, ContextMenuCommandInteraction, Role } from 'discord.js';
|
import { ChatInputCommandInteraction, ContextMenuCommandInteraction, Role } from 'discord.js';
|
||||||
import { Message, RoleEmojiPair, Guild } from './database.js';
|
import { Messages, RoleEmojiPairs, Guilds } from './database.js';
|
||||||
import { readdir } from 'fs/promises';
|
import { readdir } from 'fs/promises';
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
@ -15,7 +15,7 @@ config();
|
|||||||
*/
|
*/
|
||||||
export const removeSelfRoles = async (interaction, id) => {
|
export const removeSelfRoles = async (interaction, id) => {
|
||||||
// Try deleting message from database
|
// Try deleting message from database
|
||||||
const count = await Message.destroy({
|
const count = await Messages.destroy({
|
||||||
where: {
|
where: {
|
||||||
id: id
|
id: id
|
||||||
}
|
}
|
||||||
@ -35,18 +35,18 @@ export const removeSelfRoles = async (interaction, id) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to handle saving all the corresponding data for `Message` and `RoleEmojiPair` tables.
|
* Function to handle saving all the corresponding data for `Messages` and `RoleEmojiPairs` tables.
|
||||||
* @param {string} id A Discord message ID.
|
* @param {string} id A Discord message ID.
|
||||||
* @param {Role} role
|
* @param {Role} role
|
||||||
* @param {string} emoji Either a unicode emoji or a string representation in Discord custom emoji format.
|
* @param {string} emoji Either a unicode emoji or a string representation in Discord custom emoji format.
|
||||||
*/
|
*/
|
||||||
const saveMessageData = async (id, role, emoji) => {
|
const saveMessageData = async (id, role, emoji) => {
|
||||||
// Try finding message
|
// Try finding message
|
||||||
const msg = await Message.findOne({ where: { id } });
|
const msg = await Messages.findOne({ where: { id } });
|
||||||
if (msg === null) throw new Error(`No message with ID '${id}' could be found!`);
|
if (msg === null) throw new Error(`No message with ID '${id}' could be found!`);
|
||||||
|
|
||||||
// Try finding existing entry
|
// Try finding existing entry
|
||||||
const rep = await RoleEmojiPair.findOne({
|
const rep = await RoleEmojiPairs.findOne({
|
||||||
where: {
|
where: {
|
||||||
[Op.or]: [
|
[Op.or]: [
|
||||||
{
|
{
|
||||||
@ -67,13 +67,13 @@ const saveMessageData = async (id, role, emoji) => {
|
|||||||
|
|
||||||
// Create guild if not exists
|
// Create guild if not exists
|
||||||
const guildData = { id: role.guild.id };
|
const guildData = { id: role.guild.id };
|
||||||
await Guild.findOrCreate({
|
await Guilds.findOrCreate({
|
||||||
where: guildData,
|
where: guildData,
|
||||||
defaults: guildData
|
defaults: guildData
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create database entry for pair
|
// Create database entry for pair
|
||||||
await RoleEmojiPair.create({
|
await RoleEmojiPairs.create({
|
||||||
message: id,
|
message: id,
|
||||||
role: role.id,
|
role: role.id,
|
||||||
guild: guildData.id,
|
guild: guildData.id,
|
||||||
@ -92,7 +92,7 @@ const editMessage = async (message, role, emoji) => {
|
|||||||
|
|
||||||
// Find out whether to pad message or already present
|
// Find out whether to pad message or already present
|
||||||
let padding = '\n';
|
let padding = '\n';
|
||||||
const reps = await RoleEmojiPair.findAll({ where: { message: message.id } });
|
const reps = await RoleEmojiPairs.findAll({ where: { message: message.id } });
|
||||||
if (reps.length === 0) padding += '\n';
|
if (reps.length === 0) padding += '\n';
|
||||||
|
|
||||||
// Get old and build new content of message
|
// Get old and build new content of message
|
||||||
|
Loading…
Reference in New Issue
Block a user