TypeScript :D

This commit is contained in:
Axel Olausson Holtenäs 2022-04-10 00:06:30 +02:00
parent 0503b8d1ec
commit 05699e6813
No known key found for this signature in database
GPG key ID: 9347A5E873995701
53 changed files with 512 additions and 438 deletions

View file

@ -15,6 +15,7 @@
"hoster",
"pino",
"runned",
"Sifell",
"Timout",
"upsert",
"uuidv",

View file

@ -43,6 +43,7 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",

View file

@ -1,27 +1,27 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { counters } from '../../../../helpers/database/models';
import counters from '../../../../helpers/database/models/counterSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: 'Admin',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
@ -29,13 +29,13 @@ export default async (interaction) => {
const word = await interaction.options.getString('word');
const start = await interaction.options.getNumber('start');
if (channel.type !== 'GUILD_TEXT') {
if (channel?.type !== 'GUILD_TEXT') {
// Create embed object
const embed = {
title: 'Admin - Counter',
description: `That channel is not supported, it needs to be a text channel.`,
timestamp: new Date(),
color: config.colors.error,
color: config.colors.error as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -44,15 +44,15 @@ export default async (interaction) => {
}
const counterExist = await counters.findOne({
guildId: member.guild.id,
channelId: channel.id,
guildId: interaction?.guild?.id,
channelId: channel?.id,
word,
});
if (!counterExist) {
await counters.create({
guildId: member.guild.id,
channelId: channel.id,
guildId: interaction?.guild?.id,
channelId: channel?.id,
word,
counter: start || 0,
});
@ -63,13 +63,13 @@ export default async (interaction) => {
start || 0
}.`,
timestamp: new Date(),
color: config.colors.success,
color: config.colors.success as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} added ${channel.id} as a counter using word "${word}" for counting.`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} added ${channel.id} as a counter using word "${word}" for counting.`
);
// Send interaction reply
@ -80,7 +80,7 @@ export default async (interaction) => {
title: 'Admin - Counter',
description: `${channel} is already a counting channel.`,
timestamp: new Date(),
color: config.colors.error,
color: config.colors.error as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};

View file

@ -1,40 +1,40 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { counters } from '../../../../helpers/database/models';
import counters from '../../../../helpers/database/models/counterSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: 'Admin',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
const channel = await interaction.options.getChannel('channel');
await counters
.deleteOne({ guildId: member.guild.id, channelId: channel.id })
.deleteOne({ guildId: interaction?.guild?.id, channelId: channel?.id })
.then(async () => {
interaction.editReply({ content: 'Removed' });
});
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed remove counter.`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} executed remove counter.`
);
};

View file

@ -1,25 +1,26 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { add, remove } from './addons';
import add from './addons/add';
import remove from './addons/remove';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Counter',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
}
// If subcommand is give
@ -36,7 +37,9 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);

View file

@ -1,38 +1,39 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { users } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
const { guild, user } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
const user = await interaction.options.getUser('user');
const userOption = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount');
// If amount is zero or below
if (amount === null) return;
if (amount <= 0) {
// If amount is zero or below
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
@ -43,13 +44,13 @@ export default async (interaction) => {
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get toUserDB object
const toUserDB = await users.findOne({
userId: user.id,
guildId: interaction.member.guild.id,
userId: userOption?.id,
guildId: interaction?.guild?.id,
});
// If toUserDB has no credits
@ -58,14 +59,14 @@ export default async (interaction) => {
const embed = {
title: ':toolbox: Admin - Credits [Give]',
description:
'That user has no credits, I can not give credits to the user',
color: config.colors.error,
'That userOption has no credits, I can not give credits to the userOption',
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Deposit amount to toUserDB
@ -80,7 +81,7 @@ export default async (interaction) => {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Give]',
description: `Gave ${creditNoun(amount)} to ${user}.`,
description: `Gave ${creditNoun(amount)} to ${userOption}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -90,17 +91,17 @@ export default async (interaction) => {
await logger.debug(
`Administrator: ${interaction.user.username} gave ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} to ${user.username}`
} to ${userOption?.username}`
);
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${member.id} gave ${user.id} ${creditNoun(
amount
)}.`
`Guild: ${guild?.id} User: ${user?.id} gave ${
userOption?.id
} ${creditNoun(amount)}.`
);
});
};

View file

@ -1,36 +1,38 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { users } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Set]',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
const user = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount');
if (amount === null) return;
// If amount is zero or below
if (amount <= 0) {
// Create embed object
@ -43,13 +45,13 @@ export default async (interaction) => {
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get toUserDB object
const toUserDB = await users.findOne({
userId: user.id,
guildId: interaction.member.guild.id,
userId: user?.id,
guildId: interaction?.guild?.id,
});
// If toUserDB has no credits
@ -59,13 +61,13 @@ export default async (interaction) => {
title: ':toolbox: Admin - Credits [Set]',
description:
'That user has no credits, I can not set credits to the user',
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Set toUserDB with amount
@ -90,16 +92,16 @@ export default async (interaction) => {
await logger.debug(
`Administrator: ${interaction.user.username} set ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} on ${user.username}`
} on ${user?.username}`
);
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} set ${
user.id
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} set ${
user?.id
} to ${creditNoun(amount)}.`
);
});

View file

@ -1,55 +1,57 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { users } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild, user } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
const user = await interaction.options.getUser('user');
const userOption = await interaction.options.getUser('userOption');
const amount = await interaction.options.getInteger('amount');
if (amount === null) return;
// If amount is zero or below
if (amount <= 0) {
// Give embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]',
description: "You can't take zero or below.",
color: 0xbb2124,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get toUser object
const toUser = await users.findOne({
userId: user.id,
guildId: interaction.member.guild.id,
userId: userOption?.id,
guildId: interaction?.guild?.id,
});
// If toUser has no credits
@ -58,14 +60,14 @@ export default async (interaction) => {
const embed = {
title: ':toolbox: Admin - Credits [Take]',
description:
'That user has no credits, I can not take credits from the user',
color: config.colors.error,
'That userOption has no credits, I can not take credits from the userOption',
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Withdraw amount from toUser
@ -80,7 +82,7 @@ export default async (interaction) => {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Take]',
description: `You took ${creditNoun(amount)} to ${user}.`,
description: `You took ${creditNoun(amount)} to ${userOption}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -90,15 +92,15 @@ export default async (interaction) => {
await logger.debug(
`Administrator: ${interaction.user.username} took ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} from ${user.username}`
} from ${userOption?.username}`
);
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
`Guild: ${guild?.id} User: ${user?.id} took ${creditNoun(
amount
)} from ${user.id}.`
);

View file

@ -1,31 +1,31 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { users } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
import creditNoun from '../../../../helpers/creditNoun';
import saveUser from '../../../../helpers/saveUser';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
@ -35,14 +35,14 @@ export default async (interaction) => {
// Get fromUser object
const fromUser = await users.findOne({
userId: from.id,
guildId: interaction.member.guild.id,
userId: from?.id,
guildId: interaction?.guild?.id,
});
// Get toUser object
const toUser = await users.findOne({
userId: to.id,
guildId: interaction.member.guild.id,
userId: to?.id,
guildId: interaction?.guild?.id,
});
// If fromUser has no credits
@ -52,13 +52,13 @@ export default async (interaction) => {
title: ':toolbox: Admin - Credits [Transfer]',
description:
'That user has no credits, I can not transfer credits from the user',
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// If toUser has no credits
@ -68,28 +68,30 @@ export default async (interaction) => {
title: ':toolbox: Admin - Credits [Transfer]',
description:
'That user has no credits, I can not transfer credits to the user',
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
if (amount === null) return;
// If amount is zero or below
if (amount <= 0) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
description: "You can't transfer zero or below.",
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Withdraw amount from fromUser
@ -106,15 +108,15 @@ export default async (interaction) => {
const embed = {
title: ':toolbox: Admin - Credits [Transfer]',
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
color: config.colors.success,
color: config.colors.success as any,
fields: [
{
name: `${from.username} Balance`,
name: `${from?.username} Balance`,
value: `${fromUser.credits}`,
inline: true,
},
{
name: `${to.username} Balance`,
name: `${to?.username} Balance`,
value: `${toUser.credits}`,
inline: true,
},
@ -124,13 +126,13 @@ export default async (interaction) => {
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
amount
)} from ${from.id} to ${to.id}.`
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} transferred ${creditNoun(amount)} from ${from?.id} to ${to?.id}.`
);
});
};

View file

@ -1,25 +1,31 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { give, take, set, transfer } from './addons';
import give from './addons/give';
import take from './addons/take';
import set from './addons/set';
import transfer from './addons/transfer';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { user, guild } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':toolbox: Admin - Credits',
color: config.colors.error,
description: 'You do not have permission to manage this!',
title: ':toolbox: Admin - Credits' as string,
color: config.colors.error as any,
description: 'You do not have permission to manage this!' as string,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
footer: {
iconURL: config.footer.icon as string,
text: config.footer.text as string,
},
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
}
// If subcommand is give
@ -48,7 +54,7 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
`Guild: ${guild?.id} User: ${user?.id} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);

View file

@ -2,6 +2,8 @@ import { SlashCommandBuilder } from '@discordjs/builders';
import credits from './credits';
import counter from './counter';
import { CommandInteraction } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('admin')
@ -121,7 +123,7 @@ export default {
)
)
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand group is credits
if (interaction.options.getSubcommandGroup() === 'credits') {
// Execute credits group

View file

@ -1,8 +1,8 @@
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { counters } from '../../../helpers/database/models';
export default async (interaction) => {
import counters from '../../../helpers/database/models/counterSchema';
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
try {
// Destructure member
const { member } = await interaction;
@ -11,8 +11,8 @@ export default async (interaction) => {
const channel = await interaction.options.getChannel('channel');
const counter = await counters.findOne({
guildId: member.guild.id,
channelId: channel.id,
guildId: interaction?.guild?.id,
channelId: channel?.id,
});
if (!counter) {
@ -21,7 +21,7 @@ export default async (interaction) => {
title: 'Counter - View',
description: `${channel} is not a counting channel.`,
timestamp: new Date(),
color: config.colors.error,
color: config.colors.error as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -32,14 +32,14 @@ export default async (interaction) => {
// Create embed object
const embed = {
title: 'Counter - View',
color: config.colors.success,
color: config.colors.success as any,
description: `${channel} is currently at number ${counter.counter}.`,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return await interaction.editReply({ embeds: [embed], ephemeral: true });
return await interaction.editReply({ embeds: [embed] });
} catch (e) {
// Send debug message
await logger.error(e);

View file

@ -1,6 +1,8 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import view from './addons/view';
import { CommandInteraction } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('counter')
@ -16,7 +18,7 @@ export default {
.setRequired(true)
)
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand is view
if (interaction.options.getSubcommand() === 'view') {
// Execute view addon

View file

@ -1,16 +1,17 @@
import { CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { users } from '../../../helpers/database/models';
import users from '../../../helpers/database/models/userSchema';
import creditNoun from '../../../helpers/creditNoun';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Get options
const user = await interaction.options.getUser('user');
// Get credit object
const userDB = await users.findOne({
userId: user ? user.id : interaction.user.id,
guildId: interaction.member.guild.id,
userId: user ? user.id : interaction?.user?.id,
guildId: interaction?.guild?.id,
});
// Destructure balance
@ -24,13 +25,13 @@ export default async (interaction) => {
description: `${
user ? `${user} is` : 'You are'
} not found in the database.`,
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// If !credits
@ -39,13 +40,13 @@ export default async (interaction) => {
const embed = {
title: ':dollar: Credits - Balance',
description: `${user ? `${user} has` : 'You have'} no credits.`,
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// If credits
@ -56,12 +57,12 @@ export default async (interaction) => {
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
credits
)}.`,
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
};

View file

@ -1,58 +1,59 @@
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { users } from '../../../helpers/database/models';
import users from '../../../helpers/database/models/userSchema';
import saveUser from '../../../helpers/saveUser';
import creditNoun from '../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
// Get options
const user = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount');
const reason = await interaction.options.getString('reason');
const { member } = interaction;
const { guild } = member;
// Get fromUserDB object
const fromUserDB = await users.findOne({
userId: interaction.user.id,
guildId: interaction.member.guild.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
// Get toUserDB object
const toUserDB = await users.findOne({
userId: user.id,
guildId: interaction.member.guild.id,
userId: user?.id,
guildId: interaction?.guild?.id,
});
// If receiver is same as sender
if (user.id === interaction.user.id) {
if (user?.id === interaction?.user?.id) {
// Create embed object
const embed = {
title: ':dollar: Credits - Gift',
description: "You can't pay yourself.",
color: 0xbb2124,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
if (amount === null) return;
// If amount is zero or below
if (amount <= 0) {
// Create embed object
const embed = {
title: ':dollar: Credits - Gift',
description: "You can't pay zero or below.",
color: 0xbb2124,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// If user has below gifting amount
@ -61,13 +62,13 @@ export default async (interaction) => {
const embed = {
title: ':dollar: Credits - Gift',
description: `You have insufficient credits. Your credits is ${fromUserDB.credits}`,
color: 0xbb2124,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// If toUserDB has no credits
@ -77,13 +78,13 @@ export default async (interaction) => {
title: ':dollar: Credits - Gift',
description:
'That user has no credits, I can not gift credits to the user',
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Withdraw amount from fromUserDB
@ -119,20 +120,21 @@ export default async (interaction) => {
};
// Get DM user object
const dmUser = await interaction.client.users.cache.get(user.id);
const dmUser = await interaction.client.users.cache.get(
interaction?.user?.id
);
// Send DM to user
await dmUser.send({ embeds: [dmEmbed] });
await dmUser?.send({ embeds: [dmEmbed] });
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${member.id} gift sent from: ${interaction.user.id} to: ${user.id}`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} gift sent from: ${interaction?.user?.id} to: ${user?.id}`
);
// Send interaction reply
return interaction.editReply({
embeds: [interactionEmbed],
ephemeral: true,
});
});
};

View file

@ -1,11 +1,11 @@
import config from '../../../../config.json';
import { users } from '../../../helpers/database/models';
import users from '../../../helpers/database/models/userSchema';
import creditNoun from '../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
// Get all users in the guild
const usersDB = await users.find({ guildId: interaction.member.guild.id });
const usersDB = await users.find({ guildId: interaction?.guild?.id });
const topTen = usersDB
@ -16,7 +16,7 @@ export default async (interaction) => {
.slice(0, 10);
// Create entry object
const entry = (x, index) =>
const entry = (x: any, index: any) =>
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.credits)}`;
// Create embed object
@ -25,11 +25,11 @@ export default async (interaction) => {
description: `Below are the top ten.\n${topTen
.map((x, index) => entry(x, index))
.join('\n')}`,
color: 0x22bb33,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
};

View file

@ -1,22 +1,23 @@
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { guilds, users, timeouts } from '../../../helpers/database/models';
import guilds from '../../../helpers/database/models/guildSchema';
import users from '../../../helpers/database/models/userSchema';
import timeouts from '../../../helpers/database/models/timeoutSchema';
import creditNoun from '../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
// Check if user has a timeout
const isTimeout = await timeouts.findOne({
guildId: guild.id,
userId: member.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
timeoutId: '2022-03-15-19-16',
});
const guildDB = await guilds.findOne({
guildId: guild.id,
guildId: interaction?.guild?.id,
});
// If user is not on timeout
@ -25,48 +26,50 @@ export default async (interaction) => {
const creditsEarned = Math.floor(Math.random() * guildDB.credits.workRate);
const userDB = await users.findOne({
userId: member.id,
guildId: guild.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
userDB.credits += creditsEarned;
await userDB.save().then(async () => {
// Send debug message
await logger.debug(`Credits added to user: ${interaction.member.id}`);
await logger.debug(`Credits added to user: ${interaction?.user?.id}`);
// Create embed object
const embed = {
title: ':dollar: Credits - Work',
description: `You have earned ${creditNoun(creditsEarned)}`,
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
});
// Create a timeout for the user
await timeouts.create({
guildId: guild.id,
userId: member.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
timeoutId: '2022-03-15-19-16',
});
setTimeout(async () => {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${member.id} has not worked within the last ${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} has not worked within the last ${
guildDB.work.timeout / 1000
} seconds, work can be done`
);
// When timeout is out, remove it from the database
await timeouts.deleteOne({
guildId: guild.id,
userId: member.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
timeoutId: '2022-03-15-19-16',
});
}, guildDB.credits.workTimeout);
@ -78,7 +81,7 @@ export default async (interaction) => {
guildDB.credits.workTimeout / 1000
} seconds, you can not work now!`,
timestamp: new Date(),
color: config.colors.error,
color: config.colors.error as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -87,7 +90,7 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${member.id} has worked within last day, no work can be done`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has worked within last day, no work can be done`
);
}
};

View file

@ -1,6 +1,9 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { balance, gift, top, work } from './addons';
import balance from './addons/balance';
import gift from './addons/gift';
import top from './addons/top';
import work from './addons/work';
import { CommandInteraction } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('credits')
@ -42,7 +45,7 @@ export default {
.addSubcommand((subcommand) =>
subcommand.setName('work').setDescription('Work for credits.')
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand is balance
if (interaction.options.getSubcommand() === 'balance') {
// Execute balance addon

View file

@ -1,26 +1,25 @@
import i18next from 'i18next';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { users, credits, experiences } from '../../../helpers/database/models';
export default async (interaction) => {
import users from '../../../helpers/database/models/userSchema';
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
try {
// Destructure member
const { member } = await interaction;
const { guild } = member;
// Get options
const target = await interaction.options.getUser('target');
// Get discord user object
const discordUser = await interaction.client.users.fetch(
`${target ? target.id : member.id}`
`${target ? target.id : interaction?.user?.id}`
);
// Get user object
const userDB = await users.findOne({
userId: await discordUser.id,
guildId: guild.id,
userId: await discordUser?.id,
guildId: interaction?.guild?.id,
});
// Create embed object
@ -29,7 +28,7 @@ export default async (interaction) => {
name: `${await discordUser.username}#${await discordUser.discriminator}`,
icon_url: await discordUser.displayAvatarURL(),
},
color: config.colors.success,
color: config.colors.success as any,
fields: [
{
name: `:dollar: Credits`,
@ -62,7 +61,7 @@ export default async (interaction) => {
};
// Send interaction reply
return await interaction.editReply({ embeds: [embed], ephemeral: true });
return await interaction.editReply({ embeds: [embed] });
} catch (e) {
// Send debug message
await logger.error(e);

View file

@ -1,6 +1,6 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import view from './addons/view';
import { CommandInteraction } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('profile')
@ -15,7 +15,7 @@ export default {
.setDescription('The profile you wish to view')
)
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand is view
if (interaction.options.getSubcommand() === 'view') {
// Execute view addon

View file

@ -1,12 +1,13 @@
import i18next from 'i18next';
import { CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { users, timeouts } from '../../../helpers/database/models';
import users from '../../../helpers/database/models/userSchema';
import timeouts from '../../../helpers/database/models/timeoutSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
// Get options
const target = await interaction.options.getUser('target');
@ -14,27 +15,27 @@ export default async (interaction) => {
// Get user object
const userDB = await users.findOne({
userId: member.id,
guildId: guild.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
// Check if user has a timeout
const isTimeout = await timeouts.findOne({
guildId: guild.id,
userId: member.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
timeoutId: 2,
});
// If user is not on timeout
if (!isTimeout) {
// Do not allow self reputation
if (target.id === interaction.member.id) {
if (target?.id === interaction?.user?.id) {
// Create embed object
const embed = {
title: ':loudspeaker: Reputation - Give',
description: 'You can not repute yourself.',
timestamp: new Date(),
color: config.colors.error,
color: config.colors.error as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -59,7 +60,7 @@ export default async (interaction) => {
title: ':loudspeaker: Reputation - Give',
description: `You have given ${target} a ${type} reputation!`,
timestamp: new Date(),
color: config.colors.success,
color: config.colors.success as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -68,13 +69,13 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has given ${target?.id} a ${type} reputation.`
);
// Create a timeout for the user
await timeouts.create({
guildId: member.guild.id,
userId: member.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
timeoutId: 2,
});
});
@ -82,8 +83,8 @@ export default async (interaction) => {
setTimeout(async () => {
// send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${
member.id
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} has not repute within last ${
config.reputation.timeout / 1000
} seconds, reputation can be given`
@ -91,8 +92,8 @@ export default async (interaction) => {
// When timeout is out, remove it from the database
await timeouts.deleteOne({
guildId: member.guild.id,
userId: member.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
timeoutId: 2,
});
}, config.reputation.timeout);
@ -104,7 +105,7 @@ export default async (interaction) => {
config.reputation.timeout / 1000
} seconds, you can not repute now!`,
timestamp: new Date(),
color: config.colors.error,
color: config.colors.error as any,
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -113,7 +114,9 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has repute within last ${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} has repute within last ${
config.reputation.timeout / 1000
} seconds, no reputation can be given`
);

View file

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import logger from '../../handlers/logger';
import give from './addons/give';
@ -26,7 +26,7 @@ export default {
.addChoice('Negative', 'negative')
)
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// Destructure member
const { member } = interaction;
@ -38,7 +38,9 @@ export default {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} executed /${
interaction.commandName
} ${interaction.options.getSubcommand()}`
);

View file

@ -1,28 +1,27 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { guilds } from '../../../../helpers/database/models';
import guilds from '../../../../helpers/database/models/guildSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
const { guild, user } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':hammer: Settings - Guild [Credits]',
color: config.colors.error,
color: config.colors.error as any,
description: `You don't have permission to manage this!`,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
@ -35,7 +34,7 @@ export default async (interaction) => {
// Get guild object
const guildDB = await guilds.findOne({
guildId: guild.id,
guildId: guild?.id,
});
// Modify values
@ -56,7 +55,7 @@ export default async (interaction) => {
const embed = {
title: ':hammer: Settings - Guild [Credits]',
description: 'Following settings is set!',
color: config.colors.success,
color: config.colors.success as any,
fields: [
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
@ -86,11 +85,11 @@ export default async (interaction) => {
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has changed credit details.`
`Guild: ${guild?.id} User: ${user.id} has changed credit details.`
);
});
};

View file

@ -1,28 +1,27 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { guilds } from '../../../../helpers/database/models';
import guilds from '../../../../helpers/database/models/guildSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':hammer: Settings - Guild [Points]',
color: config.colors.error,
color: config.colors.error as any,
description: `You don't have permission to manage this!`,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
@ -33,7 +32,7 @@ export default async (interaction) => {
// Get guild object
const guildDB = await guilds.findOne({
guildId: guild.id,
guildId: interaction?.guild?.id,
});
// Modify values
@ -50,7 +49,7 @@ export default async (interaction) => {
const embed = {
title: ':hammer: Settings - Guild [Points]',
description: 'Following settings is set!',
color: config.colors.success,
color: config.colors.success as any,
fields: [
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
@ -70,11 +69,11 @@ export default async (interaction) => {
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${member.id} has changed credit details.`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed credit details.`
);
});
};

View file

@ -1,29 +1,28 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
// Database models
import { apis } from '../../../../helpers/database/models';
import apis from '../../../../helpers/database/models/apiSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: ':hammer: Settings - Guild [Pterodactyl]',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Get options
@ -35,7 +34,7 @@ export default async (interaction) => {
await apis
.findOneAndUpdate(
{ guildId: guild.id },
{ guildId: interaction?.guild?.id },
{ url, token },
{ new: true, upsert: true }
)
@ -44,7 +43,7 @@ export default async (interaction) => {
const embed = {
title: ':hammer: Settings - Guild [Pterodactyl]',
color: config.colors.success,
color: config.colors.success as any,
description: 'Pterodactyl settings is saved!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
@ -52,12 +51,12 @@ export default async (interaction) => {
// Send reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${member.id} has changed api credentials.`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed api credentials.`
);
});
};

View file

@ -1,25 +1,27 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { pterodactyl, credits, points } from './addons';
import pterodactyl from './addons/pterodactyl';
import credits from './addons/credits';
import points from './addons/points';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
// Check permission
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
if (!interaction?.memberPermissions?.has(Permissions.FLAGS.MANAGE_GUILD)) {
// Create embed object
const embed = {
title: 'Settings - Guild',
color: config.colors.error,
color: config.colors.error as any,
description: 'You do not have permission to manage this!',
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
}
// If subcommand is pterodactyl
@ -42,7 +44,9 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);

View file

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import guild from './guild';
import user from './user';
@ -112,7 +112,7 @@ export default {
)
)
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand group is guild
if (interaction.options.getSubcommandGroup() === 'guild') {
// Execute guild group

View file

@ -1,19 +1,21 @@
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
import { CommandInteraction } from 'discord.js';
// Database models
import { users } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
const { guild } = member;
// Get options
const language = await interaction.options.getString('language');
// Get user object
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
const userDB = await users.findOne({
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
// Modify values
userDB.language = language !== null ? language : userDB.language;
@ -24,7 +26,7 @@ export default async (interaction) => {
const embed = {
title: ':hammer: Settings - User [Appearance]',
description: 'Following settings is set!',
color: config.colors.success,
color: config.colors.success as any,
fields: [
{
name: '🏳️‍🌈 Language',
@ -37,11 +39,11 @@ export default async (interaction) => {
};
// Send interaction reply
await interaction.editReply({ embeds: [embed], ephemeral: true });
await interaction.editReply({ embeds: [embed] });
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
`Guild: ${interaction?.guild?.id} User: ${interaction?.user?.id} has changed appearance settings.`
);
});
};

View file

@ -1,9 +1,9 @@
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { appearance } from './addons';
import appearance from './addons/appearance';
export default async (interaction) => {
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
@ -15,7 +15,9 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);

View file

@ -2,38 +2,40 @@ import { v4 as uuidv4 } from 'uuid';
import axios from 'axios';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { credits, apis } from '../../../helpers/database/models';
import apis from '../../../helpers/database/models/apiSchema';
import users from '../../../helpers/database/models/userSchema';
import creditNoun from '../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
const { member } = interaction;
const { guild } = member;
// Get options
const amount = await interaction.options.getInteger('amount');
if (amount === null) return;
// Get user object
const userDB = await users.findOne({
userId: member.id,
guildId: guild.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
// Get DM user object
const dmUser = interaction.client.users.cache.get(member.id);
const dmUser = interaction.client.users.cache.get(interaction?.user?.id);
// Stop if amount or user credits is below 100
if ((amount || userDB.credits) < 100) {
const embed = {
title: ':shopping_cart: Shop - Pterodactyl',
description: `You **can't** withdraw for __Pterodactyl__ below **100**.`,
color: config.colors.error,
color: config.colors.error as any,
fields: [
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
],
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Stop if amount or user credits is above 1.000.000
@ -41,14 +43,14 @@ export default async (interaction) => {
const embed = {
title: ':shopping_cart: Shop - Pterodactyl',
description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`,
color: config.colors.error,
color: config.colors.error as any,
fields: [
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
],
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Stop if user credits is below amount
@ -56,14 +58,14 @@ export default async (interaction) => {
const embed = {
title: ':shopping_cart: Shop - Pterodactyl',
description: `You have **insufficient** credits.`,
color: config.colors.error,
color: config.colors.error as any,
fields: [
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
],
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
}
// Generate a unique voucher for the user
@ -71,7 +73,7 @@ export default async (interaction) => {
// Get api object
const apiCredentials = await apis.findOne({
guildId: guild.id,
guildId: interaction?.guild?.id,
});
// Create a api instance
@ -91,7 +93,7 @@ export default async (interaction) => {
uses: 1,
code,
credits: amount || userDB.credits,
memo: `${interaction.createdTimestamp} - ${member.id}`,
memo: `${interaction.createdTimestamp} - ${interaction?.user?.id}`,
})
// If successful
@ -108,7 +110,7 @@ export default async (interaction) => {
inline: true,
},
],
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -117,7 +119,7 @@ export default async (interaction) => {
const interactionEmbed = {
title: ':shopping_cart: Shop - Pterodactyl',
description: 'I have sent you the code in DM!',
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -132,30 +134,31 @@ export default async (interaction) => {
.then(async () => {
// Send debug message
await logger.debug(
`User: ${member.username} redeemed: ${creditNoun(amount)}`
`User: ${interaction?.user?.username} redeemed: ${creditNoun(
amount
)}`
);
// Send DM message
await dmUser.send({ embeds: [dmEmbed] });
await dmUser?.send({ embeds: [dmEmbed] });
// Send interaction reply
await interaction.editReply({
embeds: [interactionEmbed],
ephemeral: true,
});
})
// If error occurs
.catch(async (e) => {
.catch(async (e: any) => {
await logger.error(e);
const embed = {
title: ':shopping_cart: Shop - Pterodactyl',
description: 'Something went wrong, please try again later.',
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
});
})
@ -165,10 +168,10 @@ export default async (interaction) => {
const embed = {
title: ':shopping_cart: Shop - Pterodactyl',
description: 'Something went wrong, please try again later.',
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
return interaction.editReply({ embeds: [embed] });
});
};

View file

@ -2,25 +2,28 @@ import { v4 as uuidv4 } from 'uuid';
import axios from 'axios';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import { guilds, users } from '../../../helpers/database/models';
import guilds from '../../../helpers/database/models/guildSchema';
import users from '../../../helpers/database/models/userSchema';
import creditNoun from '../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction, RoleManager } from 'discord.js';
export default async (interaction: CommandInteraction) => {
const name = interaction.options.getString('name');
const { member } = interaction;
const { guild } = member;
const guildDB = await guilds.findOne({ guildId: guild.id });
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
const guildDB = await guilds.findOne({ guildId: interaction?.guild?.id });
const userDB = await users.findOne({
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
guild.roles
if (name === null) return;
(interaction?.guild?.roles as RoleManager)
.create({
data: {
name,
color: 'BLUE',
},
reason: `${interaction.member.id} bought from shop`,
name,
color: 'BLUE',
reason: `${interaction?.user?.id} bought from shop`,
})
.then(async (role) => {
console.log(role);
@ -29,7 +32,7 @@ export default async (interaction) => {
const embed = {
title: ':shopping_cart: Shop - Roles',
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
color: config.colors.error,
color: config.colors.error as any,
fields: [
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
],
@ -38,7 +41,6 @@ export default async (interaction) => {
};
return interaction.editReply({
embeds: [embed],
ephemeral: true,
});
});
})

View file

@ -1,5 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { Permissions } from 'discord.js';
import { Permissions, CommandInteraction } from 'discord.js';
import guilds from '../../helpers/database/models/guildSchema';
import pterodactyl from './addons/pterodactyl';
import roles from './roles';
@ -43,7 +43,7 @@ export default {
)
)
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand is pterodactyl
if (interaction.options.getSubcommand() === 'pterodactyl') {
// Execute pterodactyl addon

View file

@ -2,30 +2,32 @@ import { v4 as uuidv4 } from 'uuid';
import axios from 'axios';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
import { users, shopRoles, guilds } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
import shopRoles from '../../../../helpers/database/models/shopRolesSchema';
import guilds from '../../../../helpers/database/models/guildSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction, GuildMemberRoleManager } from 'discord.js';
export default async (interaction: CommandInteraction) => {
const { member } = interaction;
const { guild } = member;
const name = await interaction.options.getString('name');
await interaction.guild.roles
if (name === null) return;
await interaction?.guild?.roles
.create({
name,
color: 'RED',
reason: `${interaction.member.id} bought from shop`,
reason: `${interaction?.user?.id} bought from shop`,
})
.then(async (role) => {
// Get guild object
const guildDB = await guilds.findOne({
guildId: interaction.member.guild.id,
guildId: interaction?.guild?.id,
});
const userDB = await users.findOne({
userId: member.id,
guildId: guild.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
const { pricePerHour } = guildDB.shop.roles;
@ -34,20 +36,22 @@ export default async (interaction) => {
await userDB.save();
await shopRoles.create({
roleId: role.id,
userId: member.id,
guildId: guild.id,
roleId: role?.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
pricePerHour,
lastPayed: new Date(),
});
member.roles.add(role.id);
await shopRoles.find().then((role) => console.log(role));
await (interaction?.member?.roles as GuildMemberRoleManager)?.add(
role?.id
);
await shopRoles.find().then((role: any) => console.log(role));
const embed = {
title: ':shopping_cart: Shop - Roles [Buy]',
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
color: config.colors.success,
color: config.colors.success as any,
fields: [
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
],
@ -56,7 +60,6 @@ export default async (interaction) => {
};
return interaction.editReply({
embeds: [embed],
ephemeral: true,
});
})
.catch(console.error);

View file

@ -2,47 +2,52 @@ import { v4 as uuidv4 } from 'uuid';
import axios from 'axios';
import config from '../../../../../config.json';
import logger from '../../../../handlers/logger';
import { users, shopRoles, guilds } from '../../../../helpers/database/models';
import users from '../../../../helpers/database/models/userSchema';
import shopRoles from '../../../../helpers/database/models/shopRolesSchema';
import guilds from '../../../../helpers/database/models/guildSchema';
import creditNoun from '../../../../helpers/creditNoun';
export default async (interaction) => {
import { CommandInteraction, GuildMemberRoleManager } from 'discord.js';
export default async (interaction: CommandInteraction) => {
const { member } = interaction;
const { guild } = member;
const role = await interaction.options.getRole('role');
if (role === null) return;
const roleExist = await shopRoles.find({
guildId: guild.id,
userId: member.id,
roleId: role.id,
guildId: interaction?.guild?.id,
userId: interaction?.user?.id,
roleId: role?.id,
});
if (roleExist) {
await member.roles.remove(role.id);
await (interaction?.member?.roles as GuildMemberRoleManager).remove(
role?.id
);
await interaction.guild.roles
.delete(role.id, `${interaction.member.id} canceled from shop`)
await interaction?.guild?.roles
.delete(role?.id, `${interaction?.user?.id} canceled from shop`)
.then(async () => {
// Get guild object
const guildDB = await guilds.findOne({
guildId: interaction.member.guild.id,
guildId: interaction?.guild?.id,
});
const userDB = await users.findOne({
userId: member.id,
guildId: guild.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
await shopRoles.deleteOne({
roleId: role.id,
userId: member.id,
guildId: guild.id,
roleId: role?.id,
userId: interaction?.user?.id,
guildId: interaction?.guild?.id,
});
const embed = {
title: ':shopping_cart: Shop - Roles [Buy]',
description: `You have canceled ${role.name}.`,
color: config.colors.success,
color: config.colors.success as any,
fields: [
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
],
@ -51,7 +56,6 @@ export default async (interaction) => {
};
return interaction.editReply({
embeds: [embed],
ephemeral: true,
});
})
.catch(console.error);

View file

@ -1,7 +1,8 @@
import logger from '../../../handlers/logger';
import { buy, cancel } from './addons';
export default async (interaction) => {
import buy from './addons/buy';
import cancel from './addons/cancel';
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
// Destructure member
const { member } = interaction;
@ -19,7 +20,9 @@ export default async (interaction) => {
// Send debug message
await logger.debug(
`Guild: ${member.guild.id} User: ${member.id} executed /${
`Guild: ${interaction?.guild?.id} User: ${
interaction?.user?.id
} executed /${
interaction.commandName
} ${interaction.options.getSubcommandGroup()} ${interaction.options.getSubcommand()}`
);

View file

@ -1,6 +1,6 @@
import config from '../../../../config.json';
export default async (interaction) => {
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
const interactionEmbed = {
title: ':hammer: Utilities - About',
description: `This bot is hosted by ${
@ -10,9 +10,9 @@ export default async (interaction) => {
}, the bot is developed by [Zyner](https://github.com/ZynerOrg)!
If you are interested in contributing, then just [fork it](https://github.com/ZynerOrg/xyter) yourself, we :heart: Open Source.`,
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
interaction.editReply({ embeds: [interactionEmbed] });
};

View file

@ -1,8 +1,8 @@
import axios from 'axios';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
export default async (interaction) => {
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
try {
// Get lookup query
const query = await interaction.options.getString('query');
@ -20,7 +20,7 @@ export default async (interaction) => {
const embed = {
title: ':hammer: Utilities - Lookup',
description: `${res.data.message}: ${res.data.query}`,
color: config.colors.error,
color: config.colors.error as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
@ -69,7 +69,7 @@ export default async (interaction) => {
value: `${res.data.org || 'Not available'}`,
},
],
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};

View file

@ -1,7 +1,8 @@
import config from '../../../../config.json';
export default async (interaction) => {
let totalSeconds = interaction.client.uptime / 1000;
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
if (interaction?.client?.uptime === null) return;
let totalSeconds = interaction?.client?.uptime / 1000;
const days = Math.floor(totalSeconds / 86400);
totalSeconds %= 86400;
const hours = Math.floor(totalSeconds / 3600);
@ -44,9 +45,9 @@ export default async (interaction) => {
inline: true,
},
],
color: config.colors.success,
color: config.colors.success as any,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
interaction.editReply({ embeds: [interactionEmbed] });
};

View file

@ -1,6 +1,8 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { lookup, about, stats } from './addons';
import lookup from './addons/lookup';
import about from './addons/about';
import stats from './addons/stats';
import { CommandInteraction } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('utilities')
@ -24,7 +26,7 @@ export default {
.addSubcommand((subcommand) =>
subcommand.setName('stats').setDescription('Check bot statistics!)')
),
async execute(interaction) {
async execute(interaction: CommandInteraction) {
// If subcommand is lookup
if (interaction.options.getSubcommand() === 'lookup') {
// Execute lookup addon

View file

@ -1,21 +1,25 @@
import { guilds, users } from '../../helpers/database/models';
import { points, credits, counter } from './modules';
import guilds from '../../helpers/database/models/guildSchema';
import users from '../../helpers/database/models/userSchema';
import points from './modules/points';
import credits from './modules/credits';
import counter from './modules/counter';
import { Message } from 'discord.js';
export default {
name: 'messageCreate',
async execute(message) {
async execute(message: Message) {
const { guild, author } = message;
// If message author is bot
if (author.bot) return;
// Get guild object
const guildDB = await guilds.findOne({ guildId: guild.id });
const guildDB = await guilds.findOne({ guildId: guild?.id });
// Get guild object
const userDB = await users.findOne({
guildId: guild.id,
userId: author.id,
guildId: guild?.id,
userId: author?.id,
});
// Manage credits

View file

@ -1,12 +1,14 @@
import logger from '../../../handlers/logger';
import { users, guilds, experiences, credits, counters, timeouts } from '../../../helpers/database/models';
import counters from '../../../helpers/database/models/counterSchema';
export default async (guildDB, userDB, message) => {
import { Message } from 'discord.js';
export default async (guildDB: any, userDB: any, message: Message) => {
const { guild, channel, content } = message;
// Get counter object
const counter = await counters.findOne({
guildId: guild.id,
guildId: guild?.id,
channelId: channel.id,
});
@ -20,7 +22,7 @@ export default async (guildDB, userDB, message) => {
// Add 1 to the counter object
await counters.findOneAndUpdate(
{
guildId: guild.id,
guildId: guild?.id,
channelId: channel.id,
},
{ $inc: { counter: 1 } }

View file

@ -1,7 +1,7 @@
import logger from '../../../handlers/logger';
import { users, guilds, experiences, credits, counters, timeouts } from '../../../helpers/database/models';
export default async (guildDB, userDB, message) => {
import timeouts from '../../../helpers/database/models/timeoutSchema';
import { Message } from 'discord.js';
export default async (guildDB: any, userDB: any, message: Message) => {
const { guild, author, channel, content } = message;
// If message length is below guild minimum length
@ -9,7 +9,7 @@ export default async (guildDB, userDB, message) => {
// Check if user has a timeout
const isTimeout = await timeouts.findOne({
guildId: guild.id,
guildId: guild?.id,
userId: author.id,
timeoutId: '2022-03-15-17-42',
});
@ -25,17 +25,17 @@ export default async (guildDB, userDB, message) => {
.then(async () => {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}`
`Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}`
);
})
.catch(async (e) => {
.catch(async (e: any) => {
// Send error message
await logger.error(e);
});
// Create a timeout for the user
await timeouts.create({
guildId: guild.id,
guildId: guild?.id,
userId: author.id,
timeoutId: '2022-03-15-17-42',
});
@ -43,7 +43,7 @@ export default async (guildDB, userDB, message) => {
setTimeout(async () => {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${author.id} Channel: ${
`Guild: ${guild?.id} User: ${author.id} Channel: ${
channel.id
} has not talked within last ${
guildDB.credits.timeout / 1000
@ -52,7 +52,7 @@ export default async (guildDB, userDB, message) => {
// When timeout is out, remove it from the database
await timeouts.deleteOne({
guildId: guild.id,
guildId: guild?.id,
userId: author.id,
timeoutId: '2022-03-15-17-42',
});
@ -60,7 +60,7 @@ export default async (guildDB, userDB, message) => {
} else {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${author.id} Channel: ${
`Guild: ${guild?.id} User: ${author.id} Channel: ${
channel.id
} has talked within last ${
guildDB.credits.timeout / 1000

View file

@ -1,7 +1,8 @@
import logger from '../../../handlers/logger';
import { timeouts } from '../../../helpers/database/models';
import timeouts from '../../../helpers/database/models/timeoutSchema';
export default async (guildDB, userDB, message) => {
import { Message } from 'discord.js';
export default async (guildDB: any, userDB: any, message: Message) => {
const { author, guild, channel, content } = message;
// If message length is below guild minimum length
@ -9,7 +10,7 @@ export default async (guildDB, userDB, message) => {
// Check if user has a timeout
const isTimeout = await timeouts.findOne({
guildId: guild.id,
guildId: guild?.id,
userId: author.id,
timeoutId: '2022-03-15-17-41',
});
@ -24,17 +25,17 @@ export default async (guildDB, userDB, message) => {
.then(async () => {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}`
`Guild: ${guild?.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}`
);
})
.catch(async (e) => {
.catch(async (e: any) => {
// Send error message
await logger.error(e);
});
// Create a timeout for the user
await timeouts.create({
guildId: guild.id,
guildId: guild?.id,
userId: author.id,
timeoutId: '2022-03-15-17-41',
});
@ -42,7 +43,7 @@ export default async (guildDB, userDB, message) => {
setTimeout(async () => {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${author.id} Channel: ${
`Guild: ${guild?.id} User: ${author.id} Channel: ${
channel.id
} has not talked within last ${
guildDB.points.timeout / 1000
@ -51,7 +52,7 @@ export default async (guildDB, userDB, message) => {
// When timeout is out, remove it from the database
await timeouts.deleteOne({
guildId: guild.id,
guildId: guild?.id,
userId: author.id,
timeoutId: '2022-03-15-17-41',
});
@ -59,7 +60,7 @@ export default async (guildDB, userDB, message) => {
} else {
// Send debug message
await logger.debug(
`Guild: ${guild.id} User: ${author.id} Channel: ${
`Guild: ${guild?.id} User: ${author.id} Channel: ${
channel.id
} has talked within last ${
guildDB.points.timeout / 1000

View file

@ -1,14 +1,14 @@
import { counters } from '../helpers/database/models';
import counters from '../helpers/database/models/counterSchema';
import { Message } from 'discord.js';
export default {
name: 'messageUpdate',
async execute(oldMessage, newMessage) {
async execute(oldMessage: Message, newMessage: Message) {
// If message author is bot
if (newMessage.author.bot) return;
// Get counter object
const counter = await counters.findOne({
guildId: newMessage.guild.id,
guildId: newMessage.guild?.id,
channelId: newMessage.channel.id,
});

View file

@ -1,16 +1,20 @@
import logger from '../handlers/logger';
import config from '../../config.json';
import { deployCommands, dbGuildFix, dbMemberFix } from '../helpers';
import deployCommands from '../helpers/deployCommands';
import dbGuildFix from '../helpers/dbGuildFix';
import dbMemberFix from '../helpers/dbMemberFix';
import { Client } from 'discord.js';
export default {
name: 'ready',
once: true,
async execute(client) {
async execute(client: Client) {
console.log('Test');
// Send info message
await logger.info(`Ready! Logged in as ${client.user.tag}`);
await logger.info(`Ready! Logged in as ${client?.user?.tag}`);
// Set client status
await client.user.setPresence({
await client?.user?.setPresence({
activities: [
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
],
@ -20,7 +24,7 @@ export default {
if (config.importToDB) {
const guilds = client.guilds.cache;
await guilds.map(async (guild) => {
await guild.members.fetch().then(async (members) => {
await guild?.members.fetch().then(async (members) => {
await members.forEach(async (member) => {
const { user } = member;
dbMemberFix(user, guild);

View file

@ -1,12 +1,12 @@
import fs from 'fs'; // fs
import { Collection, Client } from 'discord.js'; // discord.js
import { Collection } from 'discord.js'; // discord.js
import { Client } from '../types/common/discord';
export default async (client: Client) => {
client.commands = new Collection();
const commandFiles = fs.readdirSync('./src/commands');
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
client.commands.set(command.data.name, command);
client.commands.set(command.default.data.name, command.default);
}
};

View file

@ -7,9 +7,13 @@ export default async (client: Client) => {
for (const file of eventFiles) {
const event = require(`../events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
client.once(event.default.name, (...args) =>
event.default.execute(...args)
);
} else {
client.on(event.name, (...args) => event.execute(...args));
client.on(event.default.name, (...args) =>
event.default.execute(...args)
);
}
}
};

View file

@ -1,2 +1,2 @@
module.exports = (amount) =>
export default (amount: number) =>
`${amount <= 1 ? `${amount} credit` : `${amount} credits`}`;

View file

@ -1,17 +1,17 @@
const config = require('../../config.json');
const logger = require('../handlers/logger');
const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
import config from '../../config.json';
import logger from '../handlers/logger';
import fs from 'fs';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
module.exports = async () => {
export default async () => {
const commands = [];
const commandFiles = fs.readdirSync('./src/commands');
for (const file of commandFiles) {
// eslint-disable-next-line import/no-dynamic-require, global-require
const command = require(`../commands/${file}`);
commands.push(command.data.toJSON());
commands.push(command.default.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(config.bot.token);

View file

@ -1,12 +1,11 @@
const sleep = require('./sleep');
import sleep from './sleep';
import logger from '../handlers/logger';
const logger = require('../handlers/logger');
module.exports = async function saveUser(data, data2) {
export default async function saveUser(data: any, data2: any) {
process.nextTick(
async () => {
await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator
data.save((_) =>
data.save((_: any) =>
_
? logger.error(
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(
@ -16,7 +15,7 @@ module.exports = async function saveUser(data, data2) {
: 'No Error'
);
if (data2) {
data2.save((_) =>
data2.save((_: any) =>
_
? logger.error(
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(
@ -30,4 +29,4 @@ module.exports = async function saveUser(data, data2) {
data,
data2
);
};
}

View file

@ -1,5 +1,5 @@
module.exports = function sleep(milliseconds) {
export default function sleep(milliseconds: any) {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
};
}

View file

@ -3,6 +3,7 @@ import { Client, Intents } from 'discord.js'; // discord.js
import database from './helpers/database/index';
import events from './handlers/events';
import commands from './handlers/commands';
// import { database } from './helpers'; // helpers
// import { events, commands, locale, schedules } from './handlers'; // handlers
@ -21,7 +22,7 @@ import config from '../config.json'; // config.json
await database();
// await locale();
await events(client);
// await commands(client);
await commands(client);
// await schedules(client);
await client.login(config.bot.token);
})();

View file

@ -1,7 +1,8 @@
import { Collection } from 'discord.js';
import { Collection, Client as DJSClient } from 'discord.js';
declare module 'discord.js' {
export interface Client {
export interface Client extends DJSClient {
commands: Collection<unknown, any>;
}
}
export { Client };