|
1 | 1 | import { getTextBasedChannel } from '#lib/discord-fetch'; |
2 | | -import { getEmbedBuilder, stringsToEmbedField } from '#lib/discord-messaging'; |
3 | | -import { |
4 | | - GetGiveaways, |
5 | | - GiveawayStatuses, |
6 | | - isGiveawayStatus, |
7 | | -} from '@/services/giveaway/index.js'; |
| 2 | +import { FetchAndSendGiveaways } from '@/services/giveaway'; |
| 3 | +import { GiveawayStatusEnum } from '@/services/giveaway/giveaway-status'; |
8 | 4 | import { Command } from '@sapphire/framework'; |
9 | 5 | import { PermissionsBitField } from 'discord.js'; |
10 | 6 |
|
11 | 7 | export class FetchGiveawaysCommand extends Command { |
12 | | - public constructor(context: Command.Context, options: Command.Options) { |
| 8 | + public constructor(context: Command.LoaderContext, options: Command.Options) { |
13 | 9 | super(context, { |
14 | 10 | ...options, |
15 | 11 | description: 'Send giveaways to this channel', |
@@ -44,34 +40,11 @@ export class FetchGiveawaysCommand extends Command { |
44 | 40 | } |
45 | 41 |
|
46 | 42 | await interaction.editReply('Will search for new giveaways'); |
47 | | - const giveaways = await GetGiveaways(); |
48 | | - if (isGiveawayStatus(giveaways)) { |
49 | | - const status = GiveawayStatuses[giveaways]; |
50 | | - return interaction.editReply(status.log_message); |
51 | | - } |
| 43 | + const giveawayStatus = await FetchAndSendGiveaways(channel); |
52 | 44 |
|
53 | | - for (const giveaway of giveaways) { |
54 | | - const embedFields = stringsToEmbedField(giveaway.body); |
55 | | - const builder = getEmbedBuilder() |
56 | | - .setTitle(giveaway.title) |
57 | | - .addFields(embedFields); |
58 | | - if (giveaway.imageURL) { |
59 | | - builder.setImage(giveaway.imageURL); |
60 | | - } |
61 | | - const builtEmbed = builder.toJSON(); |
62 | | - await channel.send({ embeds: [builtEmbed] }); |
63 | | - return; |
| 45 | + if (giveawayStatus.status === GiveawayStatusEnum.SUCCESS) { |
| 46 | + return interaction.followUp('Giveaway fetch finished!'); |
64 | 47 | } |
65 | | - return; |
66 | | - // const result = await GetGiveaways(channel, { |
67 | | - // noFilter: true, |
68 | | - // ignorePreviousMessage: force, |
69 | | - // }); |
70 | | - |
71 | | - // if (result === 'SUCCESS') { |
72 | | - // void interaction.followUp('Giveaway fetch finished!'); |
73 | | - // } else { |
74 | | - // void interaction.editReply(GiveawayFetchMessages[result]); |
75 | | - // } |
| 48 | + return interaction.editReply(giveawayStatus.statusInformation.log_message); |
76 | 49 | } |
77 | 50 | } |
0 commit comments