mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
fix: remove refresh button if not enough permissions
This commit is contained in:
1 parent
96a9e5b938
commit
716b446272
5 files changed
+30
-17
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
import { Locale } from 'discord.js';
|
||||||
import { chunk } from 'lodash';
|
import { chunk } from 'lodash';
|
||||||
import * as Breakdown from '../components/Breakdown';
|
import * as Breakdown from '../components/Breakdown';
|
||||||
import CommandWrapper from '../components/CommandWrapper';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
@@ -18,7 +19,7 @@ import addPeriodicFilterOptions from '../core/discord/addPeriodicFilterOptions';
|
|||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import buttonPrimary from '../core/discord/buttonPrimary';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
@@ -44,6 +45,7 @@ export async function renderBreakdown(
|
|||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
const awaitedTankDefinitions = await tankDefinitions;
|
const awaitedTankDefinitions = await tankDefinitions;
|
||||||
const awaitedTankAverages = await tankAverages;
|
const awaitedTankAverages = await tankAverages;
|
||||||
@@ -52,7 +54,7 @@ export async function renderBreakdown(
|
|||||||
const accountInfo = await getAccountInfo(region, id);
|
const accountInfo = await getAccountInfo(region, id);
|
||||||
const clanData = await getClanAccountInfo(region, id, ['clan']);
|
const clanData = await getClanAccountInfo(region, id, ['clan']);
|
||||||
const tankStats = await getTankStats(region, id);
|
const tankStats = await getTankStats(region, id);
|
||||||
const filterDescriptions = await filtersToDescription(filters);
|
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||||
const orderedCurrentStats: AllStats[] = [];
|
const orderedCurrentStats: AllStats[] = [];
|
||||||
const orderedCareerStats: AllStats[] = [];
|
const orderedCareerStats: AllStats[] = [];
|
||||||
const orderedCurrentWN8: (number | undefined)[] = [];
|
const orderedCurrentWN8: (number | undefined)[] = [];
|
||||||
@@ -312,8 +314,13 @@ export const breakdownCommand = new Promise<CommandRegistry>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(await renderBreakdown(player, period, filters)),
|
...(await renderBreakdown(
|
||||||
buttonPrimary(path, 'Refresh'),
|
player,
|
||||||
|
period,
|
||||||
|
filters,
|
||||||
|
interaction.locale,
|
||||||
|
)),
|
||||||
|
buttonRefresh(interaction, path),
|
||||||
await getBlitzStarsLinkButton(player.region, player.id),
|
await getBlitzStarsLinkButton(player.region, player.id),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
@@ -328,7 +335,12 @@ export const breakdownCommand = new Promise<CommandRegistry>(
|
|||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
const filters = getFiltersFromButton(interaction);
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await renderBreakdown(player, period, filters);
|
return await renderBreakdown(
|
||||||
|
player,
|
||||||
|
period,
|
||||||
|
filters,
|
||||||
|
interaction.locale,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import addTankChoices from '../core/discord/addTankChoices';
|
|||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import buttonPrimary from '../core/discord/buttonPrimary';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
@@ -148,7 +148,7 @@ export const evolutionCommand = new Promise<CommandRegistry>(
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
await render(player, period, commandGroup, tankId),
|
await render(player, period, commandGroup, tankId),
|
||||||
buttonPrimary(path, 'Refresh'),
|
buttonRefresh(interaction, path),
|
||||||
await getBlitzStarsLinkButton(
|
await getBlitzStarsLinkButton(
|
||||||
player.region,
|
player.region,
|
||||||
player.id,
|
player.id,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { SlashCommandBuilder } from 'discord.js';
|
import { Locale, SlashCommandBuilder } from 'discord.js';
|
||||||
import CommandWrapper from '../components/CommandWrapper';
|
import CommandWrapper from '../components/CommandWrapper';
|
||||||
import GenericAllStats from '../components/GenericAllStats';
|
import GenericAllStats from '../components/GenericAllStats';
|
||||||
import NoData, { NoDataType } from '../components/NoData';
|
import NoData, { NoDataType } from '../components/NoData';
|
||||||
@@ -35,6 +35,7 @@ async function render(
|
|||||||
{ region, id }: ResolvedPlayer,
|
{ region, id }: ResolvedPlayer,
|
||||||
{ start, end, name }: ResolvedPeriod,
|
{ start, end, name }: ResolvedPeriod,
|
||||||
filters: StatFilters,
|
filters: StatFilters,
|
||||||
|
locale: Locale,
|
||||||
) {
|
) {
|
||||||
const { nickname } = await getAccountInfo(region, id);
|
const { nickname } = await getAccountInfo(region, id);
|
||||||
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
const clan = (await getClanAccountInfo(region, id, ['clan']))?.clan;
|
||||||
@@ -44,7 +45,7 @@ async function render(
|
|||||||
diffedTankStats,
|
diffedTankStats,
|
||||||
filters,
|
filters,
|
||||||
);
|
);
|
||||||
const filterDescriptions = await filtersToDescription(filters);
|
const filterDescriptions = await filtersToDescription(filters, locale);
|
||||||
const tierWeights = await getTierWeights(diffedTankStats.diff, filteredOrder);
|
const tierWeights = await getTierWeights(diffedTankStats.diff, filteredOrder);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -90,7 +91,7 @@ export const fullStatsCommand = new Promise<CommandRegistry>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
render(player, period, filters),
|
render(player, period, filters, interaction.locale),
|
||||||
buttonRefresh(interaction, path),
|
buttonRefresh(interaction, path),
|
||||||
getBlitzStarsLinkButton(player.region, player.id),
|
getBlitzStarsLinkButton(player.region, player.id),
|
||||||
]);
|
]);
|
||||||
@@ -106,7 +107,7 @@ export const fullStatsCommand = new Promise<CommandRegistry>(
|
|||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
const filters = getFiltersFromButton(interaction);
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await render(player, period, filters);
|
return await render(player, period, filters, interaction.locale);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { addFilterOptions } from '../core/discord/addFilterOptions';
|
|||||||
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
import addUsernameChoices from '../core/discord/addUsernameChoices';
|
||||||
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
import autocompleteTanks from '../core/discord/autocompleteTanks';
|
||||||
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
import autocompleteUsername from '../core/discord/autocompleteUsername';
|
||||||
import buttonPrimary from '../core/discord/buttonPrimary';
|
import { buttonRefresh } from '../core/discord/buttonRefresh';
|
||||||
import commandToURL from '../core/discord/commandToURL';
|
import commandToURL from '../core/discord/commandToURL';
|
||||||
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
import { getCustomPeriodParams } from '../core/discord/getCustomPeriodParams';
|
||||||
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
import { getFiltersFromButton } from '../core/discord/getFiltersFromButton';
|
||||||
@@ -47,8 +47,8 @@ export const todayCommand = new Promise<CommandRegistry>(async (resolve) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(await renderBreakdown(player, period, filters)),
|
...(await renderBreakdown(player, period, filters, interaction.locale)),
|
||||||
buttonPrimary(path, 'Refresh'),
|
buttonRefresh(interaction, path),
|
||||||
await getBlitzStarsLinkButton(player.region, player.id),
|
await getBlitzStarsLinkButton(player.region, player.id),
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
@@ -63,7 +63,7 @@ export const todayCommand = new Promise<CommandRegistry>(async (resolve) => {
|
|||||||
const period = resolvePeriodFromButton(player.region, interaction);
|
const period = resolvePeriodFromButton(player.region, interaction);
|
||||||
const filters = getFiltersFromButton(interaction);
|
const filters = getFiltersFromButton(interaction);
|
||||||
|
|
||||||
return await renderBreakdown(player, period, filters);
|
return await renderBreakdown(player, period, filters, interaction.locale);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -6,10 +6,10 @@ export function buttonRefresh(
|
|||||||
path: string,
|
path: string,
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
interaction.appPermissions?.has('AttachFiles') &&
|
interaction.appPermissions?.has('ReadMessageHistory') &&
|
||||||
interaction.appPermissions?.has('ViewChannel')
|
interaction.appPermissions?.has('ViewChannel')
|
||||||
) {
|
) {
|
||||||
return buttonPrimary(path, 'Refresh');
|
return buttonPrimary(path, 'Refresh', '🔄️');
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in new issue
Block a user