Something went wrong. Try again.
fossabot clone for streamplace superbot.mmatt.net
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368import { useQuery, useQueryClient } from '@tanstack/react-query'import { Bell, BookOpenCheck, Boxes, ChevronsUpDown, Gift, Hash, Heart, KeyRound, LayoutDashboard, LogOut, Menu, MessageSquareText, Moon, Music2, Plug, Radiation, ScanText, Settings, ShieldBan, ShieldCheck, Sun, Timer, Users, X, Zap,} from 'lucide-react'import { Suspense, useEffect, useState, type ReactNode } from 'react'import { Link, NavLink, Outlet, useLocation, useNavigate, useParams } from 'react-router'import { api, ApiError } from '../lib/api.ts'import { ChannelProvider, useChannel, useChannelInfo, useOptionalChannel } from '../lib/channel.tsx'import { Avatar, Button, Callout, Spinner, cx } from './ui.tsx'
export interface Me { user: { did: string; handle: string; displayName: string; avatar: string } | null channels: { id: string; kind: 'channel' | 'preset'; handle: string; displayName: string; avatar: string; slug: string | null; owner: boolean }[]}
export const useMe = () => useQuery({ queryKey: ['me'], queryFn: () => api.get<Me>('/me') })
export function Logo({ className }: { className?: string }) { return ( <span className={cx('inline-flex items-center gap-2 font-semibold tracking-tight text-text', className)}> <img src="/icon.svg" alt="" width="24" height="24" className="size-6 shrink-0" /> Superbot </span> )}
export function ThemeToggle() { const [theme, setTheme] = useState<string>(() => document.documentElement.dataset.theme ?? (matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) const toggle = () => { const next = theme === 'dark' ? 'light' : 'dark' document.documentElement.dataset.theme = next try { localStorage.setItem('theme', next) } catch {} setTheme(next) } return ( <button type="button" onClick={toggle} aria-label={`Switch to ${theme === 'dark' ? 'light' : 'dark'} mode`} className="inline-flex size-8 items-center justify-center rounded-md text-muted hover:bg-raised hover:text-text"> {theme === 'dark' ? <Sun className="size-4" /> : <Moon className="size-4" />} </button> )}
interface NavItem { to: string label: string icon: ReactNode permission?: string}
function navFor(preset: boolean): { group: string; items: NavItem[] }[] { if (preset) return [ { group: 'Preset', items: [ { to: 'commands', label: 'Commands', icon: <MessageSquareText /> }, { to: 'keywords', label: 'Keywords', icon: <KeyRound /> }, { to: 'timers', label: 'Timers', icon: <Timer /> }, { to: 'blocked-terms', label: 'Blocked terms', icon: <ShieldBan /> }, { to: 'filters', label: 'Spam filters', icon: <ShieldCheck /> }, { to: 'settings', label: 'Preset settings', icon: <Settings /> }, ], }, ] return [ { group: 'Main', items: [ { to: 'dashboard', label: 'Dashboard', icon: <LayoutDashboard /> }, { to: 'commands', label: 'Commands', icon: <MessageSquareText />, permission: 'commands' }, { to: 'keywords', label: 'Keywords', icon: <KeyRound />, permission: 'keywords' }, { to: 'timers', label: 'Timers', icon: <Timer />, permission: 'timers' }, ], }, { group: 'Moderation', items: [ { to: 'blocked-terms', label: 'Blocked terms', icon: <ShieldBan />, permission: 'blocked_terms' }, { to: 'filters', label: 'Spam filters', icon: <ShieldCheck />, permission: 'filters' }, { to: 'nukes', label: 'Nukes & bans', icon: <Radiation />, permission: 'nukes' }, ], }, { group: 'Community', items: [ { to: 'alerts', label: 'Chat alerts', icon: <Bell />, permission: 'alerts' }, { to: 'giveaways', label: 'Giveaways', icon: <Gift />, permission: 'giveaways' }, { to: 'loyalty', label: 'Loyalty', icon: <Heart />, permission: 'loyalty' }, { to: 'modules', label: 'Modules', icon: <Boxes />, permission: 'modules' }, { to: 'media', label: 'Media request', icon: <Music2 />, permission: 'media' }, { to: 'integrations', label: 'Integrations', icon: <Plug />, permission: 'integrations' }, ], }, { group: 'Settings', items: [ { to: 'settings', label: 'Channel settings', icon: <Settings />, permission: 'settings' }, { to: 'roles', label: 'Roles', icon: <Users />, permission: 'roles' }, { to: 'tester', label: 'Configuration tester', icon: <BookOpenCheck /> }, { to: 'lookalikes', label: 'Lookalikes', icon: <ScanText />, permission: 'lookalikes' }, { to: 'presets', label: 'Presets', icon: <Hash />, permission: 'presets' }, ], }, ]}
function Sidebar({ onNavigate }: { onNavigate?: () => void }) { const { base, info, can, isPreset } = useChannel() const { data: me } = useMe() const navigate = useNavigate() const [switching, setSwitching] = useState(false) const others = me?.channels.filter((c) => c.id !== info.channel.id) ?? [] return ( <div className="flex h-full flex-col"> <div className="flex h-14 items-center px-4"> <Link to="/channels" onClick={onNavigate}> <Logo /> </Link> </div> <div className="relative px-3 pb-2"> <button type="button" onClick={() => setSwitching((s) => !s)} className="flex w-full items-center gap-2.5 rounded-md border border-line bg-panel px-2.5 py-2 text-left hover:border-line-strong" aria-expanded={switching} > <Avatar src={info.channel.avatar} name={info.channel.displayName || info.channel.handle} size={26} /> <span className="min-w-0 flex-1"> <span className="block truncate text-[13px] font-medium">{info.channel.displayName || info.channel.handle}</span> <span className="block truncate text-xs text-muted">{isPreset ? `Preset · ${info.channel.slug}` : `@${info.channel.handle}`}</span> </span> <ChevronsUpDown className="size-4 shrink-0 text-faint" /> </button> {switching && ( <div className="absolute inset-x-3 top-full z-30 mt-1 rounded-md border border-line bg-panel py-1 shadow-pop"> {others.map((c) => ( <button key={c.id} type="button" onClick={() => { setSwitching(false) onNavigate?.() navigate(c.kind === 'preset' ? `/p/${c.slug}` : `/c/${c.handle}`) }} className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-[13px] hover:bg-raised" > <Avatar src={c.avatar} name={c.displayName || c.handle} size={18} /> <span className="truncate">{c.kind === 'preset' ? `Preset: ${c.displayName}` : c.displayName || c.handle}</span> </button> ))} <Link to="/channels" className="block px-3 py-1.5 text-[13px] text-muted hover:bg-raised hover:text-text" onClick={() => setSwitching(false)}> All channels & presets </Link> </div> )} </div> <nav className="flex-1 overflow-y-auto px-3 pb-4"> {navFor(isPreset).map((g) => { const items = g.items.filter((i) => !i.permission || can(i.permission)) if (!items.length) return null return ( <div key={g.group} className="mt-4"> <div className="px-2.5 pb-1 text-[11px] font-medium text-faint">{g.group}</div> {items.map((i) => ( <NavLink key={i.to} to={`${base}/${i.to}`} onClick={onNavigate} className={({ isActive }) => cx('flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-[13px] transition-colors [&>svg]:size-4 [&>svg]:shrink-0', isActive ? 'bg-raised font-medium text-text [&>svg]:text-accent' : 'text-muted hover:bg-raised/60 hover:text-text') } > {i.icon} {i.label} </NavLink> ))} </div> ) })} </nav> <UserFooter /> </div> )}
function UserFooter() { const { data: me } = useMe() const qc = useQueryClient() const navigate = useNavigate() if (!me?.user) return null return ( <div className="flex items-center gap-2 border-t border-line px-3 py-3"> <Avatar src={me.user.avatar} name={me.user.handle} size={26} /> <div className="min-w-0 flex-1"> <div className="truncate text-[13px] font-medium">{me.user.displayName || me.user.handle}</div> <div className="truncate text-xs text-muted">@{me.user.handle}</div> </div> <ThemeToggle /> <button type="button" aria-label="Sign out" title="Sign out" className="inline-flex size-8 items-center justify-center rounded-md text-muted hover:bg-raised hover:text-text" onClick={async () => { await fetch('/auth/logout', { method: 'POST' }).catch(() => {}) qc.clear() navigate('/') }} > <LogOut className="size-4" /> </button> </div> )}
function StatusBanners() { const { info, can, isPreset } = useChannel() if (isPreset) return null const banners: ReactNode[] = [] const reconnect = ( <Button variant="primary" size="sm" onClick={() => (location.href = `/auth/login?handle=${encodeURIComponent(info.channel.handle)}&next=${encodeURIComponent(location.pathname)}`)}> Reconnect </Button> ) // Only the moderation scopes stop the bot working; the rest just hold up publishing. const moderationMissing = !info.connection.connected || info.connection.missingScopes.some((s) => !s.startsWith('gay.evil.superbot.')) if (info.owner && moderationMissing) { banners.push( <Callout key="conn" tone="warn" title="Superbot can’t moderate your chat right now" action={reconnect}> Sign in again to give Superbot permission to hide messages, time people out, and update your stream. </Callout>, ) } else if (info.owner && (info.connection.missingScopes.length || info.records.needsSignIn)) { const n = info.records.pending banners.push( <Callout key="records" tone="info" title="Reconnect to publish your setup to your account" action={reconnect}> Your commands, timers, quotes, alerts and module messages are saved as public records on your atproto account, so they belong to you. Sign in again to let Superbot write them{n ? ` (${n} ${n === 1 ? 'change is' : 'changes are'} waiting)` : ''}. Everything keeps working in the meantime. </Callout>, ) } if (!info.bot.ready && can('stream')) { banners.push( <Callout key="bot" tone="danger" title="The bot account isn’t signed in on this server"> Superbot can read your chat but can’t send messages. Set BOT_IDENTIFIER and BOT_APP_PASSWORD on the server. </Callout>, ) } if (!info.channel.botJoined && can('stream')) { banners.push( <Callout key="join" tone="info" title="Superbot isn’t in your chat"> Join it from the dashboard’s bot controls to turn everything on. </Callout>, ) } if (!banners.length) return null return <div className="mb-6 space-y-2">{banners}</div>}
export function ChannelLayout({ kind }: { kind: 'channel' | 'preset' }) { const { ref = '' } = useParams() const channelRef = kind === 'preset' ? `preset:${ref}` : ref const base = kind === 'preset' ? `/p/${ref}` : `/c/${ref}` const { data, error, isLoading } = useChannelInfo(channelRef) const [mobileOpen, setMobileOpen] = useState(false) const location = useLocation() const navigate = useNavigate() useEffect(() => setMobileOpen(false), [location.pathname]) useEffect(() => { if (error instanceof ApiError && error.status === 401) navigate(`/login?next=${encodeURIComponent(location.pathname)}`, { replace: true }) }, [error, navigate, location.pathname])
if (isLoading) return ( <div className="flex min-h-dvh items-center justify-center"> <Spinner /> </div> ) if (error || !data) return ( <div className="flex min-h-dvh flex-col items-center justify-center gap-3 px-4 text-center"> <Logo /> <p className="text-[13px] text-muted">{error instanceof ApiError && error.status === 403 ? 'You don’t have access to this channel.' : 'This channel doesn’t exist on Superbot.'}</p> <Link to="/channels" className="text-[13px] text-accent-text hover:underline"> Go to your channels </Link> </div> )
return ( <ChannelProvider info={data} base={base}> <div className="flex min-h-dvh"> <aside className="sticky top-0 hidden h-dvh w-60 shrink-0 border-r border-line bg-sidebar lg:block"> <Sidebar /> </aside> {mobileOpen && ( <div className="fixed inset-0 z-40 lg:hidden"> <div className="absolute inset-0 bg-[var(--overlay)]" onClick={() => setMobileOpen(false)} /> <aside className="absolute inset-y-0 left-0 w-64 border-r border-line bg-sidebar"> <Sidebar onNavigate={() => setMobileOpen(false)} /> </aside> </div> )} <div className="min-w-0 flex-1"> <header className="sticky top-0 z-30 flex h-12 items-center gap-2 border-b border-line bg-bg/90 px-4 backdrop-blur lg:hidden"> <button type="button" aria-label={mobileOpen ? 'Close menu' : 'Open menu'} onClick={() => setMobileOpen((o) => !o)} className="inline-flex size-8 items-center justify-center rounded-md text-muted hover:bg-raised"> {mobileOpen ? <X className="size-4" /> : <Menu className="size-4" />} </button> <Logo /> <LiveDot className="ml-auto" /> </header> <main className="mx-auto w-full max-w-6xl px-4 py-6 sm:px-8 sm:py-8"> <StatusBanners /> <Suspense fallback={ <div className="flex justify-center py-20"> <Spinner /> </div> } > <Outlet /> </Suspense> </main> </div> </div> </ChannelProvider> )}
export function LiveDot({ className }: { className?: string }) { const ctx = useOptionalChannel() if (!ctx || ctx.isPreset) return null const live = ctx.info.live.isLive return ( <span className={cx('inline-flex items-center gap-1.5 text-xs font-medium', live ? 'text-danger' : 'text-faint', className)}> <span className={cx('size-2 rounded-full', live ? 'bg-danger' : 'bg-line-strong')} /> {live ? 'Live' : 'Offline'} </span> )}
export const ZapIcon = Zap