✨ shop role colors and devMode and fix delete role
This commit is contained in:
parent
0385ef4837
commit
63d7152a61
7 changed files with 109 additions and 80 deletions
|
@ -29,5 +29,6 @@
|
||||||
},
|
},
|
||||||
"secretKey": "SET A LONG RANDOM PASSWORD HERE, ITS FOR USE OF ENCRYPTION WITH LENGTH OF 32",
|
"secretKey": "SET A LONG RANDOM PASSWORD HERE, ITS FOR USE OF ENCRYPTION WITH LENGTH OF 32",
|
||||||
"importToDB": false,
|
"importToDB": false,
|
||||||
"clearUnused": false
|
"clearUnused": false,
|
||||||
|
"devMode": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +1,61 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import { SlashCommandBuilder } from "@discordjs/builders";
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
import { CommandInteraction } from "discord.js";
|
import { CommandInteraction } from 'discord.js';
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
import pterodactyl from "./modules/pterodactyl";
|
import pterodactyl from './modules/pterodactyl';
|
||||||
|
|
||||||
// Groups
|
// Groups
|
||||||
import roles from "./roles";
|
import roles from './roles';
|
||||||
|
|
||||||
// Handlers
|
// Handlers
|
||||||
import logger from "../../handlers/logger";
|
import logger from '../../handlers/logger';
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName("shop")
|
.setName('shop')
|
||||||
.setDescription("Open our shop.")
|
.setDescription('Open our shop.')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName("pterodactyl")
|
.setName('pterodactyl')
|
||||||
.setDescription("Buy pterodactyl power.")
|
.setDescription('Buy pterodactyl power.')
|
||||||
.addIntegerOption((option) =>
|
.addIntegerOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("amount")
|
.setName('amount')
|
||||||
.setDescription("How much credits you want to withdraw.")
|
.setDescription('How much credits you want to withdraw.')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addSubcommandGroup((group) =>
|
.addSubcommandGroup((group) =>
|
||||||
group
|
group
|
||||||
.setName("roles")
|
.setName('roles')
|
||||||
.setDescription("Manage custom roles.")
|
.setDescription('Manage custom roles.')
|
||||||
.addSubcommand((command) =>
|
.addSubcommand((command) =>
|
||||||
command
|
command
|
||||||
.setName("buy")
|
.setName('buy')
|
||||||
.setDescription("Buy a custom role")
|
.setDescription('Buy a custom role')
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("name")
|
.setName('name')
|
||||||
.setDescription("Name of the role you wish to purchase.")
|
.setDescription('Name of the role you wish to purchase.')
|
||||||
|
)
|
||||||
|
.addStringOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('color')
|
||||||
|
.setDescription(
|
||||||
|
'Color of the role you wish to purchase (For example RED or BLUE or GREEN).'
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addSubcommand((command) =>
|
.addSubcommand((command) =>
|
||||||
command
|
command
|
||||||
.setName("cancel")
|
.setName('cancel')
|
||||||
.setDescription("Cancel a custom role")
|
.setDescription('Cancel a custom role')
|
||||||
.addRoleOption((option) =>
|
.addRoleOption((option) =>
|
||||||
option
|
option
|
||||||
.setName("role")
|
.setName('role')
|
||||||
.setDescription("Name of the role you wish to cancel.")
|
.setDescription('Name of the role you wish to cancel.')
|
||||||
)
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
async execute(interaction: CommandInteraction) {
|
async execute(interaction: CommandInteraction) {
|
||||||
|
@ -56,13 +63,13 @@ export default {
|
||||||
const { options, commandName, user, guild } = interaction;
|
const { options, commandName, user, guild } = interaction;
|
||||||
|
|
||||||
// Module - Pterodactyl
|
// Module - Pterodactyl
|
||||||
if (options?.getSubcommand() === "pterodactyl") {
|
if (options?.getSubcommand() === 'pterodactyl') {
|
||||||
// Execute Module - Pterodactyl
|
// Execute Module - Pterodactyl
|
||||||
return pterodactyl(interaction);
|
return pterodactyl(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group - Roles
|
// Group - Roles
|
||||||
else if (options?.getSubcommandGroup() === "roles") {
|
else if (options?.getSubcommandGroup() === 'roles') {
|
||||||
// Execute Group - Roles
|
// Execute Group - Roles
|
||||||
return roles(interaction);
|
return roles(interaction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,31 +3,32 @@ import {
|
||||||
CommandInteraction,
|
CommandInteraction,
|
||||||
ColorResolvable,
|
ColorResolvable,
|
||||||
GuildMemberRoleManager,
|
GuildMemberRoleManager,
|
||||||
} from "discord.js";
|
} from 'discord.js';
|
||||||
|
|
||||||
// Configurations
|
// Configurations
|
||||||
import config from "../../../../../config.json";
|
import config from '../../../../../config.json';
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
import shopRolesSchema from "../../../../helpers/database/models/shopRolesSchema";
|
import shopRolesSchema from '../../../../helpers/database/models/shopRolesSchema';
|
||||||
import guildSchema from "../../../../helpers/database/models/guildSchema";
|
import guildSchema from '../../../../helpers/database/models/guildSchema';
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
import creditNoun from "../../../../helpers/creditNoun";
|
import creditNoun from '../../../../helpers/creditNoun';
|
||||||
import fetchUser from "../../../../helpers/fetchUser";
|
import fetchUser from '../../../../helpers/fetchUser';
|
||||||
|
|
||||||
// Function
|
// Function
|
||||||
export default async (interaction: CommandInteraction) => {
|
export default async (interaction: CommandInteraction) => {
|
||||||
const { options, guild, user, member } = interaction;
|
const { options, guild, user, member } = interaction;
|
||||||
|
|
||||||
const optionName = options?.getString("name");
|
const optionName = options?.getString('name');
|
||||||
|
const optionColor = options?.getString('color');
|
||||||
|
|
||||||
// If amount is null
|
// If amount is null
|
||||||
if (optionName === null) {
|
if (optionName === null) {
|
||||||
// Embed object
|
// Embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ":dollar: Shop - Roles [Buy]" as string,
|
title: ':dollar: Shop - Roles [Buy]' as string,
|
||||||
description: "We could not read your requested name." as string,
|
description: 'We could not read your requested name.' as string,
|
||||||
color: config?.colors?.error as ColorResolvable,
|
color: config?.colors?.error as ColorResolvable,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: {
|
footer: {
|
||||||
|
@ -43,7 +44,7 @@ export default async (interaction: CommandInteraction) => {
|
||||||
await guild?.roles
|
await guild?.roles
|
||||||
.create({
|
.create({
|
||||||
name: optionName,
|
name: optionName,
|
||||||
color: "RED",
|
color: optionColor as ColorResolvable,
|
||||||
reason: `${user?.id} bought from shop`,
|
reason: `${user?.id} bought from shop`,
|
||||||
})
|
})
|
||||||
.then(async (role) => {
|
.then(async (role) => {
|
||||||
|
@ -74,13 +75,13 @@ export default async (interaction: CommandInteraction) => {
|
||||||
await shopRolesSchema?.find()?.then((role: any) => console.log(role));
|
await shopRolesSchema?.find()?.then((role: any) => console.log(role));
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
title: ":shopping_cart: Shop - Roles [Buy]" as string,
|
title: ':shopping_cart: Shop - Roles [Buy]' as string,
|
||||||
description:
|
description:
|
||||||
`You have bought ${role?.name} for ${guildDB?.shop?.roles?.pricePerHour} per hour.` as string,
|
`You have bought ${role?.name} for ${guildDB?.shop?.roles?.pricePerHour} per hour.` as string,
|
||||||
color: config?.colors?.success as ColorResolvable,
|
color: config?.colors?.success as ColorResolvable,
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: "Your balance" as string,
|
name: 'Your balance' as string,
|
||||||
value: `${creditNoun(userDB?.credits)}` as string,
|
value: `${creditNoun(userDB?.credits)}` as string,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
import logger from "../../handlers/logger";
|
import logger from '../../handlers/logger';
|
||||||
import config from "../../../config.json";
|
import config from '../../../config.json';
|
||||||
import deployCommands from "../../helpers/deployCommands";
|
import deployCommands from '../../helpers/deployCommands';
|
||||||
import dbGuildFix from "../../helpers/dbGuildFix";
|
import dbGuildFix from '../../helpers/dbGuildFix';
|
||||||
import dbMemberFix from "../../helpers/dbMemberFix";
|
import dbMemberFix from '../../helpers/dbMemberFix';
|
||||||
|
|
||||||
import userSchema from "../../helpers/database/models/userSchema";
|
import userSchema from '../../helpers/database/models/userSchema';
|
||||||
|
|
||||||
import { Client } from "discord.js";
|
import { Client } from 'discord.js';
|
||||||
import updatePresence from "../../helpers/updatePresence";
|
import updatePresence from '../../helpers/updatePresence';
|
||||||
export default {
|
export default {
|
||||||
name: "ready",
|
name: 'ready',
|
||||||
once: true,
|
once: true,
|
||||||
async execute(client: Client) {
|
async execute(client: Client) {
|
||||||
// Send info message
|
// Send info message
|
||||||
|
@ -30,6 +30,19 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (client === null) return;
|
||||||
|
if (client.application === null) return;
|
||||||
|
|
||||||
|
if (!config?.devMode) {
|
||||||
|
client?.application?.commands
|
||||||
|
?.set([], config.bot.guildId)
|
||||||
|
.then(async (commands) => {
|
||||||
|
logger.info(
|
||||||
|
`Removed all guild based commands from ${config.bot.guildId}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (config.clearUnused) {
|
if (config.clearUnused) {
|
||||||
await userSchema.find().then(
|
await userSchema.find().then(
|
||||||
async (result) =>
|
async (result) =>
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import schedule from "node-schedule";
|
import schedule from 'node-schedule';
|
||||||
import users from "../helpers/database/models/userSchema";
|
import users from '../helpers/database/models/userSchema';
|
||||||
import shopRoles from "../helpers/database/models/shopRolesSchema";
|
import shopRoles from '../helpers/database/models/shopRolesSchema';
|
||||||
import guilds from "../helpers/database/models/guildSchema";
|
import guilds from '../helpers/database/models/guildSchema';
|
||||||
import logger from "./logger";
|
import logger from './logger';
|
||||||
import { Client } from "discord.js";
|
import { Client } from 'discord.js';
|
||||||
|
|
||||||
export default async (client: Client) => {
|
export default async (client: Client) => {
|
||||||
schedule.scheduleJob("*/5 * * * *", async () => {
|
schedule.scheduleJob('*/5 * * * *', async () => {
|
||||||
shopRoles.find().then(async (shopRoles: any) => {
|
shopRoles.find().then(async (shopRoles: any) => {
|
||||||
shopRoles.map(async (shopRole: any) => {
|
shopRoles.map(async (shopRole: any) => {
|
||||||
const payed = new Date(shopRole.lastPayed);
|
const payed = new Date(shopRole.lastPayed);
|
||||||
|
@ -37,10 +37,12 @@ export default async (client: Client) => {
|
||||||
const rGuild = await client.guilds.cache.get(`${shopRole.guildId}`);
|
const rGuild = await client.guilds.cache.get(`${shopRole.guildId}`);
|
||||||
const rMember = await rGuild?.members.fetch(`${shopRole.userId}`);
|
const rMember = await rGuild?.members.fetch(`${shopRole.userId}`);
|
||||||
|
|
||||||
|
shopRoles.deleteOne({ _id: shopRole._id });
|
||||||
|
|
||||||
await rMember?.roles
|
await rMember?.roles
|
||||||
.remove(`${shopRole.roleId}`)
|
.remove(`${shopRole.roleId}`)
|
||||||
.then(async (test) => console.log("4", test))
|
.then(async (test) => console.log('4', test))
|
||||||
.catch(async (test) => console.log("5", test)); // Removes all roles
|
.catch(async (test) => console.log('5', test)); // Removes all roles
|
||||||
}
|
}
|
||||||
|
|
||||||
shopRole.lastPayed = new Date();
|
shopRole.lastPayed = new Date();
|
||||||
|
@ -54,6 +56,6 @@ export default async (client: Client) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await logger.debug("Checking schedules! (Every 5 minutes)");
|
await logger.debug('Checking schedules! (Every 5 minutes)');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,9 +20,13 @@ export default async () => {
|
||||||
body: commands,
|
body: commands,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (config?.devMode) {
|
||||||
await rest
|
await rest
|
||||||
.put(
|
.put(
|
||||||
Routes.applicationGuildCommands(config.bot.clientId, config.bot.guildId),
|
Routes.applicationGuildCommands(
|
||||||
|
config.bot.clientId,
|
||||||
|
config.bot.guildId
|
||||||
|
),
|
||||||
{
|
{
|
||||||
body: commands,
|
body: commands,
|
||||||
}
|
}
|
||||||
|
@ -33,4 +37,5 @@ export default async () => {
|
||||||
.catch(async (err) => {
|
.catch(async (err) => {
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
14
src/index.ts
14
src/index.ts
|
@ -1,13 +1,13 @@
|
||||||
// Dependencies
|
// Dependencies
|
||||||
import { Client, Intents } from "discord.js"; // discord.js
|
import { Client, Intents } from 'discord.js'; // discord.js
|
||||||
|
|
||||||
import database from "./helpers/database";
|
import database from './helpers/database';
|
||||||
import events from "./handlers/events";
|
import events from './handlers/events';
|
||||||
import commands from "./handlers/commands";
|
import commands from './handlers/commands';
|
||||||
import locale from "./handlers/locale";
|
import locale from './handlers/locale';
|
||||||
import schedules from "./handlers/schedules";
|
import schedules from './handlers/schedules';
|
||||||
|
|
||||||
import config from "../config.json"; // config.json
|
import config from '../config.json'; // config.json
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Initialize discord.js client
|
// Initialize discord.js client
|
||||||
|
|
Loading…
Add table
Reference in a new issue