relative imports to properly type model instances

This commit is contained in:
Baipyrus 2024-04-04 09:55:14 +02:00
parent 663f1313e9
commit 08567747c7
7 changed files with 13 additions and 0 deletions

View File

@ -57,6 +57,7 @@ export async function execute(interaction) {
switch (options.getSubcommand()) {
case 'add': {
// Search for role in database
/** @type {import('../../../models/roles.js').Role|null} */
const found = await Roles.findOne({
where: {
id: role.id

View File

@ -48,6 +48,7 @@ const registerSelfRoles = async (interaction) => {
await channel.messages.fetch(id);
// Check if message is already registered
/** @type {import('../../../models/messages.js').Message|null} */
const found = await Messages.findOne({
where: { id }
});

View File

@ -18,6 +18,7 @@ import { VoiceChannels } from '../../database.js';
*/
const getChannel = async (member, guildChs, channel) => {
// Check database for existing channel
/** @type {import('../../models/voiceChannels.js').VoiceChannel|null} */
const ownCh = await VoiceChannels.findOne({
where: {
owner: member.id
@ -58,6 +59,7 @@ const leftVoiceChat = async (state) => {
if (members.length > 0) return;
// Find channel by id, return if not registered as custom
/** @type {import('../../models/voiceChannels.js').VoiceChannel|null} */
const custom = await VoiceChannels.findOne({
where: {
id: channel.id,
@ -84,6 +86,7 @@ export async function execute(oldState, newState) {
if (!channel) return;
// Find channel by id, return if not registered for customs
/** @type {import('../../models/voiceChannels.js').VoiceChannel|null} */
const createCh = await VoiceChannels.findOne({
where: {
id: channel.id,

View File

@ -5,6 +5,7 @@ export const name = Events.GuildMemberAdd;
/** @param {GuildMember} member */
export async function execute(member) {
// Find roles to be assigned in guild from database
/** @type {import('../../models/roles.js').Role[]} */
const roles = await Roles.findAll({
where: {
guild: member.guild.id,

View File

@ -14,6 +14,7 @@ export async function execute(reaction, user) {
// Get message
const msgID = reaction.message.id;
/** @type {import('../../models/messages.js').Message|null} */
const message = await Messages.findOne({
where: {
id: msgID
@ -24,6 +25,7 @@ export async function execute(reaction, user) {
// Get emoji
const emoji = reaction.emoji.toString();
/** @type {import('../../models/roleEmojiPairs.js').RoleEmojiPair|null} */
const rep = await RoleEmojiPairs.findOne({
where: {
message: msgID,

View File

@ -14,6 +14,7 @@ export async function execute(reaction, user) {
// Get message
const msgID = reaction.message.id;
/** @type {import('../../models/messages.js').Message|null} */
const message = await Messages.findOne({
where: {
id: msgID
@ -24,6 +25,7 @@ export async function execute(reaction, user) {
// Get emoji
const emoji = reaction.emoji.toString();
/** @type {import('../../models/roleEmojiPairs.js').RoleEmojiPair|null} */
const rep = await RoleEmojiPairs.findOne({
where: {
message: msgID,

View File

@ -42,10 +42,12 @@ export const removeSelfRoles = async (interaction, id) => {
*/
const saveMessageData = async (id, role, emoji) => {
// Try finding message
/** @type {import('./models/messages.js').Message|null} */
const msg = await Messages.findOne({ where: { id } });
if (msg === null) throw new Error(`No message with ID '${id}' could be found!`);
// Try finding existing entry
/** @type {import('./models/roleEmojiPairs.js').RoleEmojiPair|null} */
const rep = await RoleEmojiPairs.findOne({
where: {
[Op.or]: [
@ -92,6 +94,7 @@ const editMessage = async (message, role, emoji) => {
// Find out whether to pad message or already present
let padding = '\n';
/** @type {import('./models/roleEmojiPairs.js').RoleEmojiPair[]} */
const reps = await RoleEmojiPairs.findAll({ where: { message: message.id } });
if (reps.length === 0) padding += '\n';