feat: disable tools on opentest

This commit is contained in:
TrèsAbhi committed 2024-08-27 14:55:43 -05:00
1 parent 48dcbbc227
commit b9c978548a
20 files changed
+107 -99

No files matched your search

+4 -4
View File
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { assertSecrete } from '../../../../../core/blitzkit/secrete';
import { assertSecret } from '../../../../../core/blitzkit/secret';
export async function GET(
request: Request,
@@ -8,11 +8,11 @@ export async function GET(
const response = await fetch(
`https://www.patreon.com/api/oauth2/token?code=${
params.code
}&grant_type=authorization_code&client_id=${assertSecrete(
}&grant_type=authorization_code&client_id=${assertSecret(
process.env.NEXT_PUBLIC_PATREON_CLIENT_ID,
)}&client_secret=${assertSecrete(
)}&client_secret=${assertSecret(
process.env.PATREON_CLIENT_SECRET,
)}&redirect_uri=${assertSecrete(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI)}`,
)}&redirect_uri=${assertSecret(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI)}`,
{
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { assertSecrete } from '../../../../../core/blitzkit/secrete';
import { assertSecret } from '../../../../../core/blitzkit/secret';
interface PatreonMembershipResponse {
data: {
@@ -69,7 +69,7 @@ export async function GET(
(item) =>
item.type === 'member' &&
item.relationships.campaign.data.id ===
assertSecrete(process.env.PATREON_CAMPAIGN_ID) &&
assertSecret(process.env.PATREON_CAMPAIGN_ID) &&
item.attributes.patron_status === 'active_patron',
),
);
+3 -3
View File
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { assertSecrete } from '../../../../../core/blitzkit/secrete';
import { assertSecret } from '../../../../../core/blitzkit/secret';
export async function GET(
request: Request,
@@ -8,9 +8,9 @@ export async function GET(
const response = await fetch(
`https://www.patreon.com/api/oauth2/token?grant_type=refresh_token&refresh_token=${
params.token
}&client_id=${assertSecrete(
}&client_id=${assertSecret(
process.env.NEXT_PUBLIC_PATREON_CLIENT_ID,
)}&client_secret=${assertSecrete(process.env.PATREON_CLIENT_SECRET)}`,
)}&client_secret=${assertSecret(process.env.PATREON_CLIENT_SECRET)}`,
{ method: 'POST' },
);
const json = await response.json();
+40 -55
View File
@@ -2,14 +2,16 @@ import { CaretRightIcon } from '@radix-ui/react-icons';
import {
Box,
Button,
Code,
Flex,
FlexProps,
Heading,
Link,
Text,
} from '@radix-ui/themes';
import { Link } from '../../components/Link';
import { Tool } from '../../constants/tools';
import { ImgurSize, imgur } from '../../core/blitzkit/imgur';
import { assertSecret } from '../../core/blitzkit/secret';
type ToolCardProps = FlexProps & {
tool: Tool;
@@ -19,10 +21,14 @@ export function ToolCard({ tool, style, ...props }: ToolCardProps) {
const size = tool.significant
? ImgurSize.HugeThumbnail
: ImgurSize.LargeThumbnail;
const unavailableOnBranch = tool.branches?.every(
(branch) => branch !== assertSecret(process.env.NEXT_PUBLIC_ASSET_BRANCH),
);
return (
<Flex
style={{
opacity: unavailableOnBranch ? 0.25 : 1,
position: 'relative',
borderRadius: 'var(--radius-2)',
overflow: 'hidden',
@@ -33,17 +39,11 @@ export function ToolCard({ tool, style, ...props }: ToolCardProps) {
...style,
}}
flexGrow={tool.significant ? undefined : '1'}
flexBasis={
tool.significant
? undefined
: {
initial: undefined,
sm: '0',
}
}
flexBasis={tool.significant ? undefined : { initial: undefined, sm: '0' }}
{...props}
>
<Link
disabled={unavailableOnBranch}
href={tool.href ?? `/tools/${tool.id}`}
target={tool.href ? '_blank' : undefined}
style={{
@@ -65,22 +65,13 @@ export function ToolCard({ tool, style, ...props }: ToolCardProps) {
/>
<Flex
px={{
initial: '6',
md: tool.significant ? '8' : '6',
}}
py={{
initial: '4',
sm: tool.significant ? '6' : '4',
}}
px={{ initial: '6', md: tool.significant ? '8' : '6' }}
py={{ initial: '4', sm: tool.significant ? '6' : '4' }}
gap="4"
align="center"
justify="between"
width="100%"
direction={{
initial: 'column',
xs: 'row',
}}
direction={{ initial: 'column', xs: 'row' }}
style={{
backgroundColor: 'var(--color-panel-translucent)',
backdropFilter: 'blur(64px)',
@@ -90,52 +81,46 @@ export function ToolCard({ tool, style, ...props }: ToolCardProps) {
<Flex
direction="column"
justify="center"
align={{
initial: 'center',
xs: 'start',
}}
align={{ initial: 'center', xs: 'start' }}
>
<Heading
align={{
initial: 'center',
sm: 'left',
}}
size={{
initial: '6',
sm: tool.significant ? '7' : '5',
}}
align={{ initial: 'center', sm: 'left' }}
size={{ initial: '6', sm: tool.significant ? '7' : '5' }}
weight="medium"
>
{tool.title}
</Heading>
<Text
align={{
initial: 'center',
sm: 'left',
}}
size={{
initial: '3',
sm: tool.significant ? '4' : '3',
}}
align={{ initial: 'center', sm: 'left' }}
size={{ initial: '3', sm: tool.significant ? '4' : '3' }}
color="gray"
>
{tool.description}
{unavailableOnBranch ? (
<>
Unavailable on{' '}
<Code>
{assertSecret(process.env.NEXT_PUBLIC_ASSET_BRANCH)}
</Code>
</>
) : (
tool.description
)}
</Text>
</Flex>
<Button
size={{
initial: undefined,
sm: tool.significant ? '3' : undefined,
}}
color={tool.button.color}
style={{
cursor: 'inherit',
}}
>
{tool.button.text}
<CaretRightIcon />
</Button>
{!unavailableOnBranch && (
<Button
size={{
initial: undefined,
sm: tool.significant ? '3' : undefined,
}}
color={tool.button.color}
style={{ cursor: 'inherit' }}
>
{tool.button.text}
<CaretRightIcon />
</Button>
)}
</Flex>
</Link>
</Flex>
+2 -2
View File
@@ -3,7 +3,7 @@ import Markdown from 'markdown-to-jsx';
import { use } from 'react';
import { Link } from '../../../../components/Link';
import PageWrapper from '../../../../components/PageWrapper';
import { assertSecrete } from '../../../../core/blitzkit/secrete';
import { assertSecret } from '../../../../core/blitzkit/secret';
export default function Page({
params,
@@ -12,7 +12,7 @@ export default function Page({
}) {
const markdown = use(
fetch(
`https://raw.githubusercontent.com/tresabhi/blitzkit/${assertSecrete(
`https://raw.githubusercontent.com/tresabhi/blitzkit/${assertSecret(
process.env.NEXT_PUBLIC_ASSET_BRANCH,
)}/docs/${params.directory}/${params.document}.md`,
).then((response) => response.text()),
+17 -3
View File
@@ -1,19 +1,33 @@
'use client';
import { LinkProps, Link as RadixLink } from '@radix-ui/themes';
import {
Link as RadixLink,
LinkProps as RadixLinkProps,
} from '@radix-ui/themes';
import { useRouter } from 'next/navigation';
import { forwardRef } from 'react';
type LinkProps = RadixLinkProps & {
disabled?: boolean;
};
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
({ href, onClick, target, ...props }, ref) => {
({ href, onClick, target, disabled, style, ...props }, ref) => {
const router = useRouter();
return (
<RadixLink
style={{
cursor: disabled ? 'not-allowed' : 'pointer',
...style,
}}
ref={ref}
href={href}
href={disabled ? undefined : href}
onClick={(event) => {
if (disabled) return;
event.preventDefault();
if (href) {
if (event.ctrlKey || event.metaKey || target === '_blank') {
window.open(href);
+8
View File
@@ -14,6 +14,7 @@ export interface Tool {
color: ComponentProps<typeof Button>['color'];
};
significant?: boolean;
branches?: string[];
}
export const tankopediaTool: Tool = {
@@ -28,6 +29,7 @@ export const tankopediaTool: Tool = {
color: 'purple',
},
significant: true,
branches: ['main', 'dev', 'opentest'],
};
export const ratingTool: Tool = {
@@ -41,6 +43,7 @@ export const ratingTool: Tool = {
text: 'View leaderboard',
color: 'orange',
},
branches: ['main', 'dev'],
};
export const compareTool: Tool = {
@@ -54,6 +57,7 @@ export const compareTool: Tool = {
text: 'Compare tanks',
color: 'crimson',
},
branches: ['main', 'dev', 'opentest'],
};
export const sessionTool: Tool = {
@@ -68,6 +72,7 @@ export const sessionTool: Tool = {
text: 'Start tracking',
color: 'blue',
},
branches: ['main', 'dev'],
};
export const discordTool: Tool = {
@@ -105,6 +110,7 @@ export const playerStatsTool: Tool = {
},
image: 'YelSOfT',
href: '_', // TODO: remove this to re-enable link
branches: ['main', 'dev'],
};
export const tankPerformanceTool: Tool = {
@@ -117,6 +123,7 @@ export const tankPerformanceTool: Tool = {
color: 'jade',
},
image: 'vOKFB03',
branches: ['main', 'dev'],
};
export const embedTool: Tool = {
@@ -130,6 +137,7 @@ export const embedTool: Tool = {
color: 'red',
},
image: 'Q0faRYg',
branches: ['main', 'dev', 'opentest'],
};
export const homeTool: Tool = {
+2 -2
View File
@@ -1,8 +1,8 @@
import { ASSETS_REPO } from '../../constants/assets';
import { assertSecrete } from './secrete';
import { assertSecret } from './secret';
export function asset(path: string) {
return `https://raw.githubusercontent.com/tresabhi/${ASSETS_REPO}/${assertSecrete(
return `https://raw.githubusercontent.com/tresabhi/${ASSETS_REPO}/${assertSecret(
process.env.NEXT_PUBLIC_ASSET_BRANCH,
)}/${path}`;
}
+2 -2
View File
@@ -1,6 +1,6 @@
import { ASSETS_REPO } from '../../constants/assets';
import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
import { assertSecrete } from './secrete';
import { assertSecret } from './secret';
export async function commitAssets(message: string, changes: FileChange[]) {
console.log(`Committing ${message}...`);
@@ -10,7 +10,7 @@ export async function commitAssets(message: string, changes: FileChange[]) {
await commitMultipleFiles(
'tresabhi',
ASSETS_REPO,
assertSecrete(process.env.NEXT_PUBLIC_ASSET_BRANCH),
assertSecret(process.env.NEXT_PUBLIC_ASSET_BRANCH),
`${message} - ${new Date().toDateString()}`,
changes,
);
+2 -2
View File
@@ -1,9 +1,9 @@
import { throttling } from '@octokit/plugin-throttling';
import { Octokit } from '@octokit/rest';
import { assertSecrete } from './secrete';
import { assertSecret } from './secret';
Octokit.plugin(throttling);
export const octokit = new Octokit({
auth: assertSecrete(process.env.GH_TOKEN),
auth: assertSecret(process.env.GH_TOKEN),
});
+3 -3
View File
@@ -1,10 +1,10 @@
import { assertSecrete } from './secrete';
import { assertSecret } from './secret';
export function patreonLoginUrl() {
const params = new URLSearchParams({
response_type: 'code',
client_id: assertSecrete(process.env.NEXT_PUBLIC_PATREON_CLIENT_ID),
redirect_uri: assertSecrete(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI),
client_id: assertSecret(process.env.NEXT_PUBLIC_PATREON_CLIENT_ID),
redirect_uri: assertSecret(process.env.NEXT_PUBLIC_PATREON_REDIRECT_URI),
scope: 'identity',
});
+4
View File
@@ -0,0 +1,4 @@
export function assertSecret(secret?: string) {
if (secret === undefined) throw new Error('Missing secret');
return secret;
}
-4
View File
@@ -1,4 +0,0 @@
export function assertSecrete(secrete?: string) {
if (secrete === undefined) throw new Error('Missing secret');
return secrete;
}
+2 -2
View File
@@ -1,6 +1,6 @@
import { ShardingManager } from 'discord.js';
import { assertSecrete } from '../blitzkit/secrete';
import { assertSecret } from '../blitzkit/secret';
export const manager = new ShardingManager('dist/bot/workers/bot.js', {
token: assertSecrete(process.env.DISCORD_TOKEN),
token: assertSecret(process.env.DISCORD_TOKEN),
});
+3 -3
View File
@@ -1,7 +1,7 @@
import { ASSETS_REPO } from '../../constants/assets';
import { GithubChangeBlob, createBlob } from '../blitzkit/createBlob';
import { octokit } from '../blitzkit/octokit';
import { assertSecrete } from '../blitzkit/secrete';
import { assertSecret } from '../blitzkit/secret';
export class AssetCommit {
constructor(public message: string) {}
@@ -26,7 +26,7 @@ export class AssetCommit {
await octokit.git.getRef({
owner: 'tresabhi',
repo: ASSETS_REPO,
ref: `heads/${assertSecrete(process.env.NEXT_PUBLIC_ASSET_BRANCH)}`,
ref: `heads/${assertSecret(process.env.NEXT_PUBLIC_ASSET_BRANCH)}`,
})
).data.object.sha;
const treeSha = (
@@ -54,7 +54,7 @@ export class AssetCommit {
await octokit.git.updateRef({
owner: 'tresabhi',
repo: ASSETS_REPO,
ref: `heads/${assertSecrete(process.env.NEXT_PUBLIC_ASSET_BRANCH)}`,
ref: `heads/${assertSecret(process.env.NEXT_PUBLIC_ASSET_BRANCH)}`,
sha: newCommitData.sha,
});
}
+3 -3
View File
@@ -33,7 +33,7 @@ import { searchPlayersCommand } from '../../commands/searchPlayers';
import { statsCommand } from '../../commands/stats';
import { todayCommand } from '../../commands/today';
import { RenderConfiguration } from '../../core/blitzkit/renderConfiguration';
import { assertSecrete } from '../../core/blitzkit/secrete';
import { assertSecret } from '../../core/blitzkit/secret';
import handleAutocomplete from './handlers/autocomplete';
import handleButton from './handlers/button';
import handleChatInputCommand from './handlers/chatInputCommand';
@@ -115,7 +115,7 @@ export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => {
);
});
const rest = new REST().setToken(assertSecrete(process.env.DISCORD_TOKEN));
const rest = new REST().setToken(assertSecret(process.env.DISCORD_TOKEN));
commands.then((awaitedCommands) => {
const body = Object.values(awaitedCommands).map((registry) =>
@@ -123,7 +123,7 @@ commands.then((awaitedCommands) => {
);
rest.put(
Routes.applicationCommands(assertSecrete(process.env.DISCORD_CLIENT_ID)),
Routes.applicationCommands(assertSecret(process.env.DISCORD_CLIENT_ID)),
{
body,
},
+2 -2
View File
@@ -1,9 +1,9 @@
import { registerProcesses } from '../core/blitzkit/processes';
import { assertSecrete } from '../core/blitzkit/secrete';
import { assertSecret } from '../core/blitzkit/secret';
import { client } from '../core/discord/client';
console.log(`🟡 Launching bot ${client.shard?.ids[0]}`);
registerProcesses();
client.login(assertSecrete(process.env.DISCORD_TOKEN));
client.login(assertSecret(process.env.DISCORD_TOKEN));