JSX component support and time command
This commit is contained in:
@@ -47,7 +47,7 @@ async function execute(interaction: ExecutableInteraction, ctx: CommandContext)
|
||||
appraiseModal: {
|
||||
key: 'appraiseModal',
|
||||
type: PageType.MODAL,
|
||||
render: async () => renderAppraisalModal(interaction),
|
||||
render: () => renderAppraisalModal(interaction) as any,
|
||||
},
|
||||
appraisalResult: {
|
||||
key: 'appraisalResult',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ExecutableInteraction } from '@star-kitten/lib/discord';
|
||||
import * as StarKitten from '@star-kitten/lib/discord';
|
||||
import { createActionRow, createButton, createContainer, createTextDisplay } from '@star-kitten/lib/discord/components';
|
||||
import { actionRow, button, container, text } from '@star-kitten/lib/discord/components';
|
||||
import type { PageContext } from '@star-kitten/lib/discord/pages';
|
||||
import { type Appraisal } from '@star-kitten/lib/eve/third-party/janice.js';
|
||||
import { formatNumberToShortForm } from '@star-kitten/lib/util/text.js';
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import type { Interaction } from '@projectdysnomia/dysnomia';
|
||||
import { createModalLabel, createStringSelect, createTextInput } from '@star-kitten/lib/discord/components';
|
||||
import { markets } from '@star-kitten/lib/eve/third-party/janice.js';
|
||||
|
||||
export function renderAppraisalModal(interaction: Interaction) {
|
||||
return {
|
||||
// next page to render will be appraisalResult
|
||||
custom_id: `appraisalResult`,
|
||||
title: 'Appraise Items',
|
||||
components: [
|
||||
createModalLabel(
|
||||
'Select your market (default: Jita)',
|
||||
createStringSelect(
|
||||
'market',
|
||||
{
|
||||
placeholder: 'Select a market',
|
||||
},
|
||||
...markets.map((m) => ({
|
||||
label: m.name,
|
||||
value: m.id.toString(),
|
||||
default: m.id === 2, // Jita
|
||||
})),
|
||||
),
|
||||
),
|
||||
createModalLabel(
|
||||
'Enter items to appraise',
|
||||
createTextInput('input', {
|
||||
isParagraph: true,
|
||||
placeholder: `Enter list of items to be appraised.
|
||||
Tritanium 22222
|
||||
Pyerite 8000
|
||||
Mexallon 2444`,
|
||||
}),
|
||||
),
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { markets } from '@star-kitten/lib/eve/third-party/janice.js';
|
||||
import type { ExecutableInteraction } from '@star-kitten/lib/discord';
|
||||
|
||||
export function renderAppraisalModal(interaction: ExecutableInteraction) {
|
||||
return (
|
||||
<modal customId="appraisalResult" title="Appraise Items">
|
||||
<label label="Select a market">
|
||||
<stringSelect customId="market" placeholder="Select a market" minValues={1} maxValues={1}>
|
||||
{markets.map((m) => (
|
||||
<option
|
||||
label={m.name}
|
||||
value={m.id.toString()}
|
||||
default={m.id === 2} // Jita
|
||||
/>
|
||||
))}
|
||||
</stringSelect>
|
||||
</label>
|
||||
<label label="Enter items to appraise">
|
||||
<textInput
|
||||
customId="input"
|
||||
isParagraph={true}
|
||||
placeholder={`e.g. Tritanium 22222
|
||||
Pyerite 8000
|
||||
Mexallon 2444`}
|
||||
/>
|
||||
</label>
|
||||
</modal>
|
||||
);
|
||||
}
|
||||
@@ -2,11 +2,11 @@ import { renderSubroutes, type Page } from '@star-kitten/lib/discord/pages';
|
||||
import type { SearchState } from '../search.command';
|
||||
import {
|
||||
ButtonStyle,
|
||||
createContainer,
|
||||
createSection,
|
||||
createSeparator,
|
||||
createTextDisplay,
|
||||
createThumbnail,
|
||||
container,
|
||||
section,
|
||||
separator,
|
||||
text,
|
||||
thumbnail,
|
||||
Padding,
|
||||
} from '@star-kitten/lib/discord/components';
|
||||
import {
|
||||
@@ -88,11 +88,11 @@ const page: Page<SearchState> = {
|
||||
|
||||
return {
|
||||
components: [
|
||||
createContainer(
|
||||
container(
|
||||
{},
|
||||
createSection(
|
||||
createThumbnail(`https://images.evetech.net/types/${type.type_id}/icon`),
|
||||
createTextDisplay(`# [${type.name.en}](https://everef.net/types/${type.type_id})\n## Attributes`),
|
||||
section(
|
||||
thumbnail(`https://images.evetech.net/types/${type.type_id}/icon`),
|
||||
text(`# [${type.name.en}](https://everef.net/types/${type.type_id})\n## Attributes`),
|
||||
),
|
||||
...renderSubroutes(
|
||||
context,
|
||||
@@ -125,11 +125,11 @@ const page: Page<SearchState> = {
|
||||
const unit = attr.attribute.unit_id ? renderUnit(getUnit(attr.attribute.unit_id), attr.value) : '';
|
||||
lines.push(`${attr.attribute.display_name.en.padEnd(24)} ${unit}`);
|
||||
});
|
||||
return createTextDisplay('```\n' + lines.join('\n') + '\n```');
|
||||
return text('```\n' + lines.join('\n') + '\n```');
|
||||
},
|
||||
{ style: ButtonStyle.SECONDARY },
|
||||
),
|
||||
createSeparator(Padding.LARGE),
|
||||
separator(Padding.LARGE),
|
||||
searchActionRow('attributes'),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { createActionRow, createButton } from '@star-kitten/lib/discord/components';
|
||||
import { actionRow, button } from '@star-kitten/lib/discord/components';
|
||||
|
||||
export function searchActionRow(pageKey: string) {
|
||||
return createActionRow(
|
||||
createButton('Main', 'main', { disabled: pageKey === 'main' }),
|
||||
createButton('Attributes', 'attributes', { disabled: pageKey === 'attributes' }),
|
||||
createButton('Fittings', 'fittings', { disabled: pageKey === 'fittings' }),
|
||||
createButton('Skills', 'skills', { disabled: pageKey === 'skills' }),
|
||||
createButton('Industry', 'industry', { disabled: pageKey === 'industry' }),
|
||||
return actionRow(
|
||||
button('Main', 'main', { disabled: pageKey === 'main' }),
|
||||
button('Attributes', 'attributes', { disabled: pageKey === 'attributes' }),
|
||||
button('Fittings', 'fittings', { disabled: pageKey === 'fittings' }),
|
||||
button('Skills', 'skills', { disabled: pageKey === 'skills' }),
|
||||
button('Industry', 'industry', { disabled: pageKey === 'industry' }),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import type { Page } from '@star-kitten/lib/discord/pages';
|
||||
import type { SearchState } from '../search.command';
|
||||
import {
|
||||
createContainer,
|
||||
createMediaGallery,
|
||||
createSection,
|
||||
createTextDisplay,
|
||||
createThumbnail,
|
||||
createURLButton,
|
||||
} from '@star-kitten/lib/discord/components';
|
||||
import { container, gallery, section, text, thumbnail, urlButton } from '@star-kitten/lib/discord/components';
|
||||
import { getRoleBonuses, getSkillBonuses, getType } from '@star-kitten/lib/eve/models/type.js';
|
||||
import { cleanText } from '@star-kitten/lib/eve/utils/markdown.js';
|
||||
import { typeSearch } from '@star-kitten/lib/eve/utils/typeSearch.js';
|
||||
@@ -25,7 +18,7 @@ const page: Page<SearchState> = {
|
||||
|
||||
if (!found) {
|
||||
return {
|
||||
components: [createTextDisplay(`No item found for: ${typeName}`)],
|
||||
components: [text(`No item found for: ${typeName}`)],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,11 +33,11 @@ const page: Page<SearchState> = {
|
||||
|
||||
return {
|
||||
components: [
|
||||
createContainer(
|
||||
container(
|
||||
{},
|
||||
createSection(
|
||||
createThumbnail(`https://images.evetech.net/types/${type.type_id}/icon`),
|
||||
createTextDisplay(`
|
||||
section(
|
||||
thumbnail(`https://images.evetech.net/types/${type.type_id}/icon`),
|
||||
text(`
|
||||
# [${type.name.en}](https://everef.net/types/${type.type_id})
|
||||
|
||||
${skillBonuses
|
||||
@@ -67,18 +60,18 @@ ${roleBonuses
|
||||
}
|
||||
`),
|
||||
),
|
||||
createMediaGallery({
|
||||
gallery({
|
||||
url: 'https://iili.io/KTPCFRt.md.webp',
|
||||
}),
|
||||
// createSeparator(Padding.LARGE),
|
||||
createSection(
|
||||
createURLButton('View on EVE Tycoon', `https://evetycoon.com/market/${type.type_id}`),
|
||||
createTextDisplay(
|
||||
section(
|
||||
urlButton('View on EVE Tycoon', `https://evetycoon.com/market/${type.type_id}`),
|
||||
text(
|
||||
`## Buy: ${price ? formatNumberToShortForm(price.buyAvgFivePercent) : '--'} ISK
|
||||
## Sell: ${price ? formatNumberToShortForm(price.sellAvgFivePercent) : '--'} ISK`,
|
||||
),
|
||||
),
|
||||
createTextDisplay(`-# Type Id: ${type.type_id}`),
|
||||
text(`-# Type Id: ${type.type_id}`),
|
||||
searchActionRow('main'),
|
||||
),
|
||||
],
|
||||
|
||||
78
packages/star-kitten-bot/src/commands/time.command.tsx
Normal file
78
packages/star-kitten-bot/src/commands/time.command.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Constants, type ChatInputApplicationCommandStructure } from '@projectdysnomia/dysnomia';
|
||||
import {
|
||||
type ExecutableInteraction,
|
||||
type CommandContext,
|
||||
isApplicationCommand,
|
||||
Locale,
|
||||
} from '@star-kitten/lib/discord';
|
||||
|
||||
const definition: ChatInputApplicationCommandStructure = {
|
||||
type: Constants.ApplicationCommandTypes.CHAT_INPUT,
|
||||
name: 'time',
|
||||
nameLocalizations: {
|
||||
[Locale.DE]: 'zeit',
|
||||
[Locale.ES_ES]: 'hora',
|
||||
[Locale.FR]: 'heure',
|
||||
[Locale.JA]: '時間',
|
||||
[Locale.KO]: '시간',
|
||||
[Locale.RU]: 'время',
|
||||
[Locale.ZH_CN]: '时间',
|
||||
},
|
||||
description: 'Get the current EVE time',
|
||||
descriptionLocalizations: {
|
||||
[Locale.DE]: 'Holen Sie sich die aktuelle EVE-Zeit',
|
||||
[Locale.ES_ES]: 'Obtén la hora actual de EVE',
|
||||
[Locale.FR]: "Obtenez l'heure actuelle d'EVE",
|
||||
[Locale.JA]: '現在のEVE時間を取得します',
|
||||
[Locale.KO]: '현재 EVE 시간을 가져옵니다',
|
||||
[Locale.RU]: 'Получите текущее время EVE',
|
||||
[Locale.ZH_CN]: '获取当前的EVE时间',
|
||||
},
|
||||
};
|
||||
|
||||
const eveTimeText = {
|
||||
[Locale.EN_US]: 'EVE Time',
|
||||
[Locale.EN_GB]: 'EVE Time',
|
||||
[Locale.DE]: 'EVE-Zeit',
|
||||
[Locale.ES_ES]: 'Hora EVE',
|
||||
[Locale.FR]: "Heure d'EVE",
|
||||
[Locale.JA]: 'EVE時間',
|
||||
[Locale.KO]: 'EVE 시간',
|
||||
[Locale.RU]: 'Время EVE',
|
||||
[Locale.ZH_CN]: 'EVE时间',
|
||||
};
|
||||
|
||||
function renderTimeDisplay(locale: string = 'en-US') {
|
||||
const now = new Date();
|
||||
const eveTime = now.toISOString().split('T')[1].split('.')[0];
|
||||
const eveDate = now.toLocaleDateString(locale, {
|
||||
timeZone: 'UTC',
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: '2-digit',
|
||||
weekday: 'long',
|
||||
});
|
||||
return (
|
||||
<container>
|
||||
<textDisplay>
|
||||
{`### ${eveTimeText[locale] || eveTimeText[Locale.EN_US]}
|
||||
${eveTime}
|
||||
${eveDate}`}
|
||||
</textDisplay>
|
||||
</container>
|
||||
);
|
||||
}
|
||||
|
||||
async function execute(interaction: ExecutableInteraction, ctx: CommandContext) {
|
||||
if (!isApplicationCommand(interaction)) return;
|
||||
|
||||
interaction.createMessage({
|
||||
flags: Constants.MessageFlags.IS_COMPONENTS_V2,
|
||||
components: [renderTimeDisplay(interaction.locale)],
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
definition,
|
||||
execute,
|
||||
};
|
||||
@@ -1,3 +1,3 @@
|
||||
import { startDiscordBot } from '@star-kitten/lib/discord';
|
||||
import { startBot } from '@star-kitten/lib/discord';
|
||||
|
||||
startDiscordBot();
|
||||
startBot();
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
export function renderAppraisal() {
|
||||
const formatter = new Intl.NumberFormat('en-US', {
|
||||
maximumFractionDigits: 2,
|
||||
minimumFractionDigits: 2,
|
||||
});
|
||||
const world = 'world';
|
||||
const rand = Math.random() * 1000;
|
||||
const pageCtx = { state: { currentPage: 'home' } };
|
||||
|
||||
let jsx = (
|
||||
<actionRow>
|
||||
<container accent={0x1da57a}>
|
||||
<textDisplay content={`Hello ${world}`} />
|
||||
{pageCtx.state.currentPage !== 'share' ? (
|
||||
<actionRow>
|
||||
<button customId="share" label="Share in Channel" disabled={rand < 500} />
|
||||
</actionRow>
|
||||
) : undefined}
|
||||
</container>
|
||||
</actionRow>
|
||||
);
|
||||
|
||||
console.log(jsx);
|
||||
}
|
||||
|
||||
renderAppraisal();
|
||||
Reference in New Issue
Block a user