Skip to content

Commit

Permalink
add connect to discord for epic-web
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Oct 9, 2023
1 parent 0970f83 commit 179236b
Show file tree
Hide file tree
Showing 31 changed files with 8,668 additions and 20,558 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SESSION_SECRET="super-duper-s3cret"

KCD_GUILD_ID="SOME_LONG_NUMBER"
DISCORD_APP_ID="SOME_LONG_NUMBER"
DISCORD_CLIENT_SECRET="RANDOM_STRING_OF_CHARACTERS"
DISCORD_BOT_TOKEN="SOME_LONG_SERIES_OF_CHARACTERS"

CHANNEL_ID_BOT_LOGS="SOME_LONG_NUMBER"
Expand Down
12 changes: 0 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ FROM node:18-bullseye-slim as base
# set for base and all layer that inherit from it
ENV NODE_ENV production

# Install openssl for Prisma
RUN apt-get update && apt-get install -y openssl sqlite3

# Install all node_modules, including dev dependencies
FROM base as deps

Expand Down Expand Up @@ -34,32 +31,23 @@ WORKDIR /myapp

COPY --from=deps /myapp/node_modules /myapp/node_modules

ADD prisma .
RUN npx prisma generate

ADD . .
RUN npm run build

# Finally, build the production image with minimal footprint
FROM base

ENV DATABASE_URL=file:/data/sqlite.db
ENV PORT="8080"
ENV NODE_ENV="production"

# add shortcut for connecting to database CLI
RUN echo "#!/bin/sh\nset -x\nsqlite3 \$DATABASE_URL" > /usr/local/bin/database-cli && chmod +x /usr/local/bin/database-cli

WORKDIR /myapp

COPY --from=production-deps /myapp/node_modules /myapp/node_modules
COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma

COPY --from=build /myapp/build /myapp/build
COPY --from=build /myapp/public /myapp/public
COPY --from=build /myapp/package.json /myapp/package.json
COPY --from=build /myapp/start.sh /myapp/start.sh
COPY --from=build /myapp/prisma /myapp/prisma
COPY --from=build /myapp/scripts /myapp/scripts

ENTRYPOINT [ "./start.sh" ]
7 changes: 5 additions & 2 deletions app/bot/admin/livestream-chat.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// When a new YouTube live stream starts, create a new thread in the livestream chat channel
// and send a message with a link to the live stream.

import { fetchLivestreamChatChannel, getKcdOfficeHoursChannel } from '../utils'
import { lookupYouTubeVideo } from '~/utils/youtube.server'
import { ref } from '../'
import { fetchKCDGuild } from '../utils'
import {
fetchKCDGuild,
fetchLivestreamChatChannel,
getKcdOfficeHoursChannel,
} from '../utils'
import * as dt from 'date-fns'
import * as dtt from 'date-fns-tz'
import { sendTweet } from '~/utils/twitter.server'
Expand Down
3 changes: 2 additions & 1 deletion app/bot/commands/kif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { matchSorter } from 'match-sorter'
import * as Sentry from '@sentry/node'
import { listify, getMember, getErrorMessage, botLog } from '../utils'
import type { AutocompleteFn, CommandFn } from './utils'
import invariant from 'tiny-invariant'
import { invariant } from '~/utils'

type KifData = {
aliases?: Array<string>
Expand Down Expand Up @@ -35,6 +35,7 @@ async function getKifInfo(guild: Discord.Guild, { force = false } = {}) {
)
.json()
.then(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(data: any) => {
const kifsData = data as KifsRawData
return JSON.parse(
Expand Down
2 changes: 1 addition & 1 deletion app/bot/commands/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import invariant from 'tiny-invariant'
import { invariant } from '~/utils'
import { getMember, listify } from '../utils/index'
import type { AutocompleteFn, CommandFn } from './utils'

Expand Down
23 changes: 0 additions & 23 deletions app/db.server.ts

This file was deleted.

4 changes: 2 additions & 2 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PassThrough } from 'stream'
import { renderToPipeableStream } from 'react-dom/server'
import { RemixServer } from '@remix-run/react'
import { Response } from '@remix-run/node'
import type { EntryContext, Headers } from '@remix-run/node'
import type { EntryContext } from '@remix-run/node'
import isbot from 'isbot'
import * as env from './utils/env.server'
import * as sentry from './utils/sentry.server'
Expand Down Expand Up @@ -31,7 +31,7 @@ export default function handleRequest(
<RemixServer context={remixContext} url={request.url} />,
{
[callbackName]() {
let body = new PassThrough()
const body = new PassThrough()

responseHeaders.set('Content-Type', 'text/html')

Expand Down
59 changes: 0 additions & 59 deletions app/models/user.server.ts

This file was deleted.

20 changes: 7 additions & 13 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { LinksFunction, LoaderArgs, MetaFunction } from '@remix-run/node'
import { json } from '@remix-run/node'
import type { LinksFunction, V2_MetaFunction } from '@remix-run/node'
import {
Links,
LiveReload,
Expand All @@ -10,22 +9,17 @@ import {
} from '@remix-run/react'

import tailwindStylesheetUrl from './styles/tailwind.css'
import { getUser } from './session.server'

export const links: LinksFunction = () => {
return [{ rel: 'stylesheet', href: tailwindStylesheetUrl }]
}

export const meta: MetaFunction = () => ({
charset: 'utf-8',
title: 'Remix Notes',
viewport: 'width=device-width,initial-scale=1',
})

export async function loader({ request }: LoaderArgs) {
return json({
user: await getUser(request),
})
export const meta: V2_MetaFunction = () => {
return [
{ name: 'charset', content: 'utf-8' },
{ title: 'KCD Bot App' },
{ name: 'viewport', content: 'width=device-width,initial-scale=1' },
]
}

export default function App() {
Expand Down
3 changes: 3 additions & 0 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Index() {
return <main>Nothing to see here...</main>
}
25 changes: 25 additions & 0 deletions app/routes/connect-epic-web.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { json, type DataFunctionArgs } from '@remix-run/node'
import { Link, useLoaderData } from '@remix-run/react'

export async function loader({ request }: DataFunctionArgs) {
const port = new URL(request.url).searchParams.get('port') ?? '5639'
const authUrl = new URL('https://discord.com/api/oauth2/authorize')
authUrl.searchParams.append('client_id', process.env.DISCORD_APP_ID)
authUrl.searchParams.append(
'redirect_uri',
`http://localhost:${port}/discord/callback`,
)
authUrl.searchParams.append('response_type', 'code')
authUrl.searchParams.append('scope', 'identify')
return json({ authUrl: authUrl.toString() })
}

export default function ConnectEpicWeb() {
const data = useLoaderData<typeof loader>()

return (
<div>
<Link to={data.authUrl}>Authenticate with Discord and KCD</Link>
</div>
)
}
109 changes: 0 additions & 109 deletions app/routes/index.tsx

This file was deleted.

Loading

0 comments on commit 179236b

Please sign in to comment.