-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upcomingRaids #113): List upcoming raids for a server
- Loading branch information
1 parent
81abb77
commit 1b391a8
Showing
11 changed files
with
452 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { convertToDiscordDate } from "../../../interactions/messageComponents/utils/date/dateToDiscordTimeStamp"; | ||
|
||
const createRaidSummary = ({ | ||
userId, | ||
raidsList, | ||
timestamp = new Date(), | ||
requestedTime = Date.now(), | ||
}) => { | ||
const hasRaidList = createRaidSummary?.length; | ||
return { | ||
type: "rich", | ||
title: `Raid summary for the upcoming week`, | ||
description: `${raidsList?.length} available raids for the upcoming week\n | ||
Last updated - ${convertToDiscordDate("now", { | ||
relative: true, | ||
})} | ||
`, | ||
color: 0xffa200, | ||
timestamp, | ||
// thumbnail: { | ||
// url: `https://www.dasithsblog.com/images/Ranger-Hunter-Build.png`, | ||
// height: 0, | ||
// width: 0, | ||
// }, | ||
// author: { | ||
// name: `${userName}`, | ||
// }, | ||
fields: raidsList.map( | ||
({ | ||
raidName, | ||
eventDiscordDateTime, | ||
type, | ||
createdBy, | ||
raidUrl, | ||
authorName, | ||
}) => { | ||
const relativeProcessedTime = | ||
Number( | ||
eventDiscordDateTime.substring(3, eventDiscordDateTime.length - 3) | ||
) * 1000; | ||
const relativeProcessedTimeDiscordConvertion = convertToDiscordDate( | ||
new Date(relativeProcessedTime).toUTCString(), | ||
{ relative: true } | ||
); | ||
console.log({ | ||
relativeProcessedTime, | ||
relativeProcessedTimeDiscordConvertion, | ||
requestedTime, | ||
}); | ||
return { | ||
name: `${raidName} [${type}]`, | ||
value: `[Go to raid - ${raidName}](${raidUrl})\n⏱️ ${eventDiscordDateTime}\n⌛ ${relativeProcessedTimeDiscordConvertion} \n created by <@${createdBy}>`, | ||
inline: false, | ||
}; | ||
} | ||
), | ||
// footer: { | ||
// text: `Footer text`, | ||
// }, | ||
}; | ||
}; | ||
|
||
export const raidSummaryBuilder = ({ userId, raidsList }) => { | ||
const serverProfileEmbed = createRaidSummary({ | ||
userId, | ||
raidsList, | ||
}); | ||
return { | ||
components: [ | ||
{ | ||
type: 1, | ||
components: [ | ||
{ | ||
style: 3, | ||
label: `Refresh`, | ||
emoji: { | ||
id: `1074205923154858014`, | ||
name: `refresh`, | ||
animated: false, | ||
}, | ||
custom_id: `button_raidsummary_refresh`, | ||
disabled: false, | ||
type: 2, | ||
}, | ||
], | ||
}, | ||
], | ||
embeds: [serverProfileEmbed], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
APIChatInputApplicationCommandInteractionData, | ||
ApplicationCommandOptionType, | ||
REST, | ||
Routes, | ||
APIInteractionGuildMember, | ||
APIApplicationCommandInteractionDataSubcommandOption, | ||
RESTGetAPIChannelMessageResult, | ||
} from "discord.js"; | ||
|
||
import { Logger } from "winston"; | ||
import { | ||
getNewClassOptionsList, | ||
getOptionsList, | ||
} from "../../../embeds/templates/neverwinter/classesList"; | ||
import { | ||
profileBuilder, | ||
UserStatusValues, | ||
} from "../../../embeds/templates/neverwinter/profile"; | ||
import { raidSummaryBuilder } from "../../../embeds/templates/raidSummary/raidSummary"; | ||
import { convertToDiscordDate } from "../../messageComponents/utils/date/dateToDiscordTimeStamp"; | ||
import { displayArtifactAsEmoji } from "../../messageComponents/utils/helper/artifactsRenderer"; | ||
import { fieldSorter } from "../../messageComponents/utils/helper/artifactsSorter"; | ||
import { | ||
createFieldName, | ||
defaultJoinStatus, | ||
statusSymbols, | ||
} from "../../messageComponents/utils/helper/embedFieldAttribute"; | ||
import { getUpcomingWeekRaids } from "../../messageComponents/utils/storeOps/fetchData"; | ||
import { IfactoryInitializations } from "../../typeDefinitions/event"; | ||
import { getAvailableUpcomingWeekRaids } from "../../utils/util"; | ||
|
||
export const raidSummaryCommand = async ( | ||
data: APIChatInputApplicationCommandInteractionData, | ||
factoryInits: IfactoryInitializations | ||
) => { | ||
const { rest, logger, interactionConfig, documentClient } = factoryInits; | ||
const [{ type: subCommandType, options: subCommandOptions = [] }] = | ||
data.options as APIApplicationCommandInteractionDataSubcommandOption[]; | ||
const processedUpcomingRaids = await getAvailableUpcomingWeekRaids({ | ||
serverId: interactionConfig.guild_id, | ||
documentClient, | ||
rest, | ||
logger, | ||
}); | ||
logger.log("info", "processed raids", { processedUpcomingRaids }); | ||
const buildData = raidSummaryBuilder({ | ||
userId: interactionConfig.member.user.id, | ||
raidsList: processedUpcomingRaids, | ||
}); | ||
|
||
return { | ||
body: { | ||
...buildData, | ||
content: ``, | ||
allowed_mentions: { | ||
parse: [], | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
bot/interactions/messageComponents/buttons/raidSummary/refresh.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { APIMessageSelectMenuInteractionData } from "discord-api-types/payloads/v10/interactions"; | ||
import { IfactoryInitializations } from "../../../typeDefinitions/event"; | ||
import { | ||
Category, | ||
determineActions, | ||
getEmbedFieldsSeperatedSections, | ||
getExistingMemberRecordDetails, | ||
} from "../../utils/categorizeEmbedFields/categorizeEmbedFields"; | ||
import { defaultJoinStatus } from "../../utils/helper/embedFieldAttribute"; | ||
import { | ||
createRaidContent, | ||
determineRaidTemplateType, | ||
getRaidTime, | ||
getRaidTitle, | ||
} from "../../utils/helper/raid"; | ||
import { raidSummaryBuilder } from "../../../../embeds/templates/raidSummary/raidSummary"; | ||
import { getAvailableUpcomingWeekRaids } from "../../../../interactions/utils/util"; | ||
export const refreshRaidSummary = async ( | ||
data: APIMessageSelectMenuInteractionData, | ||
factoryInits: IfactoryInitializations | ||
) => { | ||
const { | ||
logger, | ||
rest, | ||
documentClient, | ||
interactionConfig: { | ||
application_id, | ||
token, | ||
guild_id, | ||
channel_id, | ||
member, | ||
message, | ||
}, | ||
} = factoryInits; | ||
const processedUpcomingRaids = await getAvailableUpcomingWeekRaids({ | ||
serverId: guild_id, | ||
documentClient, | ||
rest, | ||
logger, | ||
}); | ||
|
||
logger.log("info", "processed raids", { processedUpcomingRaids }); | ||
|
||
const buildData = raidSummaryBuilder({ | ||
userId: member.user.id, | ||
raidsList: processedUpcomingRaids, | ||
}); | ||
|
||
return { | ||
body: { | ||
...buildData, | ||
content: ``, | ||
allowed_mentions: { | ||
parse: [], | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { RESTGetAPIChannelMessageResult, Routes } from "discord.js"; | ||
import { getUpcomingWeekRaids } from "../messageComponents/utils/storeOps/fetchData"; | ||
export const getAvailableUpcomingWeekRaids = async ({ | ||
serverId, | ||
documentClient, | ||
rest, | ||
logger, | ||
}) => { | ||
const upcomingWeekRaids = await getUpcomingWeekRaids( | ||
{ serverId }, | ||
{ | ||
documentClient, | ||
} | ||
); | ||
logger.log("info", "Raid", { upcomingWeekRaids }); | ||
|
||
const processedUpcomingRaids = upcomingWeekRaids | ||
.filter(({ title, messageId }) => title && messageId) | ||
.map( | ||
async ({ | ||
title, | ||
creatorId, | ||
autorName, | ||
eventDiscordDateTime, | ||
isFivePerson, | ||
description, | ||
template, | ||
raidEmbed, | ||
serverId, | ||
messageId, | ||
channelId, | ||
type, | ||
updatedAt, | ||
}) => { | ||
const raidMessage = (await rest.get( | ||
(Routes as any).channelMessage(channelId, messageId) | ||
)) as RESTGetAPIChannelMessageResult; | ||
return { | ||
authorName: autorName, | ||
raidName: title, | ||
eventDiscordDateTime, | ||
type, | ||
createdBy: creatorId, | ||
raidMessage, | ||
raidUrl: `https://discord.com/channels/${serverId}/${channelId}/${messageId}`, | ||
}; | ||
} | ||
); | ||
|
||
const resolvedUpcomingRaids = await Promise.allSettled( | ||
processedUpcomingRaids as any[] | ||
); | ||
|
||
const upcomingExisitingRecords = ( | ||
resolvedUpcomingRaids.filter( | ||
({ status }) => status === "fulfilled" | ||
) as PromiseFulfilledResult<any>[] | ||
).map(({ value }) => value); | ||
return upcomingExisitingRecords; | ||
}; |
Oops, something went wrong.