import { 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') }) export function Logo({ className }: { className?: string }) { return ( Superbot ) } export function ThemeToggle() { const [theme, setTheme] = useState(() => 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 ( ) } 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: }, { to: 'keywords', label: 'Keywords', icon: }, { to: 'timers', label: 'Timers', icon: }, { to: 'blocked-terms', label: 'Blocked terms', icon: }, { to: 'filters', label: 'Spam filters', icon: }, { to: 'settings', label: 'Preset settings', icon: }, ], }, ] return [ { group: 'Main', items: [ { to: 'dashboard', label: 'Dashboard', icon: }, { to: 'commands', label: 'Commands', icon: , permission: 'commands' }, { to: 'keywords', label: 'Keywords', icon: , permission: 'keywords' }, { to: 'timers', label: 'Timers', icon: , permission: 'timers' }, ], }, { group: 'Moderation', items: [ { to: 'blocked-terms', label: 'Blocked terms', icon: , permission: 'blocked_terms' }, { to: 'filters', label: 'Spam filters', icon: , permission: 'filters' }, { to: 'nukes', label: 'Nukes & bans', icon: , permission: 'nukes' }, ], }, { group: 'Community', items: [ { to: 'alerts', label: 'Chat alerts', icon: , permission: 'alerts' }, { to: 'giveaways', label: 'Giveaways', icon: , permission: 'giveaways' }, { to: 'loyalty', label: 'Loyalty', icon: , permission: 'loyalty' }, { to: 'modules', label: 'Modules', icon: , permission: 'modules' }, { to: 'media', label: 'Media request', icon: , permission: 'media' }, { to: 'integrations', label: 'Integrations', icon: , permission: 'integrations' }, ], }, { group: 'Settings', items: [ { to: 'settings', label: 'Channel settings', icon: , permission: 'settings' }, { to: 'roles', label: 'Roles', icon: , permission: 'roles' }, { to: 'tester', label: 'Configuration tester', icon: }, { to: 'lookalikes', label: 'Lookalikes', icon: , permission: 'lookalikes' }, { to: 'presets', label: 'Presets', icon: , 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 (
{switching && (
{others.map((c) => ( ))} setSwitching(false)}> All channels & presets
)}
) } function UserFooter() { const { data: me } = useMe() const qc = useQueryClient() const navigate = useNavigate() if (!me?.user) return null return (
{me.user.displayName || me.user.handle}
@{me.user.handle}
) } function StatusBanners() { const { info, can, isPreset } = useChannel() if (isPreset) return null const banners: ReactNode[] = [] const reconnect = ( ) // 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( Sign in again to give Superbot permission to hide messages, time people out, and update your stream. , ) } else if (info.owner && (info.connection.missingScopes.length || info.records.needsSignIn)) { const n = info.records.pending banners.push( 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. , ) } if (!info.bot.ready && can('stream')) { banners.push( Superbot can read your chat but can’t send messages. Set BOT_IDENTIFIER and BOT_APP_PASSWORD on the server. , ) } if (!info.channel.botJoined && can('stream')) { banners.push( Join it from the dashboard’s bot controls to turn everything on. , ) } if (!banners.length) return null return
{banners}
} 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 (
) if (error || !data) return (

{error instanceof ApiError && error.status === 403 ? 'You don’t have access to this channel.' : 'This channel doesn’t exist on Superbot.'}

Go to your channels
) return (
{mobileOpen && (
setMobileOpen(false)} />
)}
} >
) } export function LiveDot({ className }: { className?: string }) { const ctx = useOptionalChannel() if (!ctx || ctx.isPreset) return null const live = ctx.info.live.isLive return ( {live ? 'Live' : 'Offline'} ) } export const ZapIcon = Zap