Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
8f2129e
chore: move to TypeScript with pnpm, ESLint, Prettier and Vitest
topsinoty Nov 15, 2026
2941d5e
feat(core): config, logging, feature registry and interaction router
topsinoty Nov 15, 2026
d8c2e71
feat(core): persistent job scheduler, RBAC and guild settings
topsinoty Nov 15, 2026
f39c3e0
feat(roles): fix reaction roles and add select-menu role panels
topsinoty Nov 15, 2026
8590251
feat: permission and settings commands
topsinoty Nov 15, 2026
bc119bc
feat(reminders): personal, channel and recurring reminders
topsinoty Nov 15, 2026
ec219d6
feat(announcements): drafts, previews and scheduled publishing
topsinoty Nov 15, 2026
3a2072d
feat(events): events with RSVPs, capacity and reminders
topsinoty Nov 15, 2026
061aa8e
feat(birthdays): birthday announcements and temporary role
topsinoty Nov 15, 2026
780f424
feat(polls): persistent single and multiple choice polls
topsinoty Nov 15, 2026
ee12a56
feat(movies): suggestions, votes and movie nights
topsinoty Nov 15, 2026
6f0f4a1
feat(redmine): typed client, account linking and notifications
topsinoty Nov 15, 2026
24af986
feat: wire features into the app and add command registration
topsinoty Nov 15, 2026
c4a634c
chore: Docker, Compose and CI
topsinoty Nov 15, 2026
4255d38
docs: setup, permissions and architecture
topsinoty Nov 15, 2026
7c4fb95
build: bundle with tsdown, resolve ~/ paths without .js extensions
topsinoty Nov 15, 2026
55acd7e
style: adopt style-guide lint rules for padding, loops and imports
topsinoty Nov 15, 2026
2b292ca
test: move tests into tests/ mirroring src/
topsinoty Nov 15, 2026
7ab47d0
refactor: replace luxon with date-fns, drop comments, use ~/ imports
topsinoty Nov 15, 2026
0c1cbdc
refactor: move infrastructure into infra/, domain/, config/ and lib/ …
topsinoty Nov 15, 2026
18b4004
feat(core): domain model, ports and Discord adapters for messaging an…
topsinoty Nov 15, 2026
b21f473
refactor(permissions): actor-based authorization service behind ports
topsinoty Nov 15, 2026
e3f8fa9
refactor(roles): role service behind chat ports with a thin Discord a…
topsinoty Nov 15, 2026
036684d
refactor(reminders): reminder service with job queue port and Discord…
topsinoty Nov 15, 2026
d44318c
refactor(announcements): announcement service with multi-role mentions
topsinoty Nov 15, 2026
e964892
refactor(events): event service with calendar port and capped reminde…
topsinoty Nov 15, 2026
82171c7
refactor(polls, movies): poll and movie services; movies reuse polls …
topsinoty Nov 15, 2026
23fca5f
refactor(birthdays): birthday service with pure date rules in the domain
topsinoty Nov 15, 2026
b4fa78b
refactor(redmine): issue tracker port with Redmine as an adapter
topsinoty Nov 15, 2026
051526e
refactor: drop the transitional AppContext; run core jobs without Dis…
topsinoty Nov 15, 2026
9b39869
docs: describe the ports and adapters layout
topsinoty Nov 15, 2026
dc61161
feat(lib): escaping html template helper
topsinoty Nov 15, 2026
56a3b6e
feat(web): authenticator port with local operator and Discord OAuth a…
topsinoty Nov 15, 2026
e352205
feat(web): web UI with PSA composer, events, polls, permissions and s…
topsinoty Nov 15, 2026
21033d5
feat(web): start the web UI with the bot when WEB_PORT is set
topsinoty Nov 15, 2026
e1de0a4
test: check commands against the 4000 character registration limit
topsinoty Nov 15, 2026
bc3eec8
docs: web UI setup and Compose port on loopback
topsinoty Nov 15, 2026
5858d52
fix(discord): explain when the bot is not a member of the server
topsinoty Nov 16, 2026
cc4cee7
feat(announcements): pick any number of roles to mention in the creat…
topsinoty Nov 16, 2026
84cc196
feat(announcements): choose @everyone in the create form instead of a…
topsinoty Nov 16, 2026
35af563
refactor(web): drop the unconnected Discord OAuth adapter
topsinoty Nov 16, 2026
291100d
refactor(settings): drop the per-server timezone in favour of DEFAULT…
topsinoty Nov 16, 2026
67bc520
refactor(redmine): keep only channel notifications on the service key
topsinoty Nov 16, 2026
947e724
docs: drop crypto from the architecture overview
topsinoty Nov 16, 2026
deb4263
feat(announcements): post as a plain message by default
topsinoty Nov 16, 2026
2eb8fa4
refactor(roles): leave role selection to Discord onboarding, keep onl…
topsinoty Nov 16, 2026
b7a4ff6
refactor(scheduler): run jobs on pg-boss instead of the hand-rolled r…
topsinoty Nov 16, 2026
3448754
refactor(db): drop the scheduled_jobs table now that pg-boss owns jobs
topsinoty Nov 16, 2026
7449cd6
feat(announcements): post as plain text with the title as a heading
topsinoty Nov 16, 2026
8d88c6b
refactor(announcements): four statuses and one update with an optiona…
topsinoty Nov 16, 2026
21c1915
feat(announcements): preview with publish, schedule, edit and discard…
topsinoty Nov 16, 2026
a353284
feat(polls): post as plain text, limited to 10 options of 55 characte…
topsinoty Nov 16, 2026
4c2d4a9
feat(events): date, time and place lines with optional 🗓️ 🕐 📍 icons
topsinoty Nov 16, 2026
715172b
feat(events): reminder choices, end time read from the start, no time…
topsinoty Nov 16, 2026
d9d256f
feat(time): accept today, tomorrow, weekdays and day.month; drop the …
topsinoty Nov 16, 2026
6e427da
feat(commands): plain-language birthday visibility, drop /permissions…
topsinoty Nov 16, 2026
6ba48b1
refactor(web): rebuild the web UI on Hono JSX and Pico.css
topsinoty Nov 16, 2026
28cb195
refactor(web): real stylesheet, Pico from the CDN, keyed lists and ty…
topsinoty Nov 16, 2026
da7d2f5
refactor(web): call it a server, not a guild
topsinoty Nov 16, 2026
db3690b
fix(scheduler): job types without colons, which pg-boss rejects as qu…
topsinoty Nov 16, 2026
69d19d2
fix(web): use full Pico for grids, button groups and compact table bu…
topsinoty Nov 16, 2026
04d290b
feat(events): plain-text event message with RSVP buttons
topsinoty Nov 16, 2026
707da73
fix(web): smaller scale, aligned table buttons, PSAs lower in the menu
topsinoty Nov 16, 2026
1c4e377
feat(web): birthday settings and upcoming birthdays page
topsinoty Nov 16, 2026
7a0e2f5
feat(web): edit events from the events page
topsinoty Nov 16, 2026
26b43ee
fix(web): matching edit and cancel buttons, compact button groups
topsinoty Nov 16, 2026
19951e5
feat(reminders): Remind me tomorrow on any message, and /remindme def…
topsinoty Nov 16, 2026
2a15cb2
feat(web): sign in with Discord so the web UI acts as the real member
topsinoty Nov 16, 2026
0286c60
feat(birthdays): a lasting sign-up message whose button opens a birth…
topsinoty Nov 16, 2026
16d8d11
feat(movies): fill in trailer, poster and synopsis from TMDB, and kee…
topsinoty Nov 16, 2026
e5548f7
feat(movies): links in /movie suggest, /movie link and the suggestion…
topsinoty Nov 16, 2026
242e4b3
feat(web): movies page with posters, trailers and links
topsinoty Nov 16, 2026
10f2615
feat(web): only administrators, or roles granted web:access, can open…
topsinoty Nov 16, 2026
39530e1
feat(web): manage permissions per role with grouped checkboxes
topsinoty Nov 16, 2026
6ee3542
docs: dashboard access and the permissions page
topsinoty Nov 16, 2026
d818ff6
feat(web): show only the pages, forms and buttons each member may use…
topsinoty Nov 16, 2026
3bca90c
fix(web): full-width mention dropdown in a fieldset, inline permissio…
topsinoty Nov 16, 2026
0054df0
feat(web): event and poll forms on their own pages behind a header bu…
topsinoty Nov 16, 2026
fe4df37
feat(web): PSA composer and movie suggestions on their own pages too
topsinoty Nov 16, 2026
360ced1
fix(movies): link each movie in a vote and a movie night to its trail…
topsinoty Nov 16, 2026
9339b63
fix(movies): let movie night and movie replies preview their links; k…
topsinoty Nov 16, 2026
e9f8a64
fix(auth): replace role permissions atomically
topsinoty Nov 16, 2026
675832b
fix(redmine): process all pages before checkpointing
topsinoty Nov 16, 2026
fc2380c
fix(auth): enforce channel visibility for records
topsinoty Nov 16, 2026
ed18652
fix(auth): refresh Discord membership for actors
topsinoty Nov 16, 2026
689b314
fix(events): allow clearing optional fields
topsinoty Nov 16, 2026
de6eb7d
fix(web): preserve selected channels and PSA time
topsinoty Nov 16, 2026
e2d777d
docs: add implementation and architecture plan
topsinoty Nov 16, 2026
0236fe7
chore(editor): add project spelling exceptions
topsinoty Nov 16, 2026
e1f0deb
test: add isolated PostgreSQL test setup
topsinoty Nov 16, 2026
afa67fa
fix(birthdays): restrict configured roles and channels
topsinoty Nov 16, 2026
13d5d13
fix(announcements): enforce actor access checks
topsinoty Nov 16, 2026
014e0a0
fix(redmine): retry failed sends and page deadlines
topsinoty Nov 16, 2026
338b795
docs: refresh integration limitations
topsinoty Nov 16, 2026
6eeccb7
fix(time): validate clocks consistently
topsinoty Nov 16, 2026
f6a1dd1
fix(polls): bound posts and read consistent totals
topsinoty Nov 16, 2026
62f8bd3
fix(announcements): defer retries until due
topsinoty Nov 16, 2026
d420dc5
feat: add role panels and harden dashboard access
topsinoty Nov 16, 2026
8e67b6e
feat(web): add administrator log viewer
topsinoty Nov 17, 2026
1815f2e
feat(logging): persist complete log history
topsinoty Nov 17, 2026
31bb6d3
docs: define foundation consolidation boundaries
topsinoty Nov 17, 2026
2cf49fc
docs: refine foundation contracts and consolidation scope
topsinoty Nov 17, 2026
61879f9
docs: plan foundation consolidation implementation
topsinoty Nov 17, 2026
c3a3b43
docs: record consolidation verification baseline
topsinoty Nov 17, 2026
11e781b
refactor: add shared semantic input validation
topsinoty Nov 17, 2026
526d10c
refactor: compose birthday and poll input definitions
topsinoty Nov 17, 2026
3789f5a
refactor: compose dashboard forms from accessible controls
topsinoty Nov 17, 2026
d42147c
refactor: separate message presentation from feature services
topsinoty Nov 17, 2026
00a9a0b
refactor: extract managed posts from announcements
topsinoty Nov 17, 2026
789dbae
refactor: isolate calendar mapping and Discord adapter
topsinoty Nov 17, 2026
9cd0845
docs: explain composable application foundations
topsinoty Nov 17, 2026
f96291f
fix: preserve publication compatibility and deterministic rendering
topsinoty Nov 17, 2026
6e66e02
refactor: organize foundations by capability ownership
topsinoty Nov 17, 2026
8b8621b
refactor: colocate feature slices and isolate post content
topsinoty Nov 17, 2026
91dc837
refactor: name primitives core and keep tests outside src
topsinoty Nov 17, 2026
1795a3d
refactor: group core helpers and ports
topsinoty Nov 17, 2026
a9de6ca
refactor: use includes for choice membership
topsinoty Nov 17, 2026
e01607b
feat: support duration aliases with parse-duration
topsinoty Nov 17, 2026
d6c2d76
refactor: delegate duration grammar to parse-duration
topsinoty Nov 17, 2026
66559ed
refactor: use Chrono for bot time input
topsinoty Nov 17, 2026
6dc0022
refactor: let Chrono construct parsed dates
topsinoty Nov 17, 2026
0cde4e3
fix: use native fieldsets for form control groups
topsinoty Nov 17, 2026
352cfa1
fix: narrow described-by values before joining
topsinoty Nov 17, 2026
58dc754
fix: preserve native link semantics for navigation
topsinoty Nov 17, 2026
4f00c44
refactor: separate PSA publish and cancel routes
topsinoty Nov 17, 2026
706ca7c
refactor: use digit shorthand in numeric routes
topsinoty Nov 17, 2026
dd142d1
fix: explicitly associate form labels with controls
topsinoty Nov 17, 2026
a007568
style: replace en dashes with ASCII hyphens
topsinoty Nov 17, 2026
1914e27
refactor: consolidate web and Discord presentation
topsinoty Nov 17, 2026
516c390
refactor: use interfaces for object contracts
topsinoty Nov 17, 2026
7995fae
feat: group dashboard into post forms roles and settings
topsinoty Nov 17, 2026
e3e7043
refactor: categorize presentation modules by responsibility
topsinoty Nov 17, 2026
707a408
refactor: separate web and Discord entry points
topsinoty Nov 17, 2026
199db72
refactor: colocate web routes and components by flow
topsinoty Nov 17, 2026
3a5986a
fix: remove obsolete web route redirects
topsinoty Nov 17, 2026
b257b53
refactor: place web flows under pages
topsinoty Nov 17, 2026
888923e
refactor: replace application SQL strings with Drizzle queries
topsinoty Nov 17, 2026
019a344
refactor: wrap component props in Readonly
topsinoty Nov 17, 2026
7c5cc8c
fix(logging): preserve structured error details
topsinoty Nov 17, 2026
89ccf32
refactor: simplify helpers and async queries
topsinoty Nov 17, 2026
985f199
refactor(db): consolidate initial migrations
topsinoty Nov 17, 2026
8902815
test: remove redundant suites and cases
topsinoty Nov 17, 2026
0f38b10
refactor: remove standalone maintenance scripts
topsinoty Nov 17, 2026
30992c9
test: keep only critical behavior cases
topsinoty Nov 17, 2026
5f64329
test: group suites by critical concern
topsinoty Nov 17, 2026
354b3f9
chore: remove pointless shit
topsinoty Nov 17, 2026
bb97d05
chore: remove agent plan
topsinoty Nov 17, 2026
9410c80
refactor: remove Redmine feature
topsinoty Nov 17, 2026
ea6e204
refactor(announcements): reuse visible records helper
topsinoty Nov 17, 2026
3527412
perf(web): load dashboard permissions in one query
topsinoty Nov 17, 2026
b4cf82a
fix(discord): treat deleted channels as missing messages
topsinoty Nov 17, 2026
b263166
fix(announcements): check length before saving drafts
topsinoty Nov 17, 2026
696a9d4
fix(events): validate capacity on create and edit
topsinoty Nov 17, 2026
2e93262
fix(events): clear the Discord event id when cancelling
topsinoty Nov 17, 2026
6913f1d
feat(announcements): split long announcements across messages
topsinoty Nov 17, 2026
6ccf604
style: remove code comments
topsinoty Nov 17, 2026
7307762
style: replace em dashes with ASCII hyphens
topsinoty Nov 17, 2026
1833fb6
refactor(db): move tables and repositories into integrations/db
topsinoty Nov 17, 2026
ca93b95
chore: keep Docker for local development only
topsinoty Nov 17, 2026
5a1ac4c
ci: check pull requests and deploy main through Gitea
topsinoty Nov 17, 2026
b70f1d1
docs: rewrite README concisely
topsinoty Nov 17, 2026
8346c2d
feat(birthdays): post birthday messages in Estonian
topsinoty Nov 17, 2026
64f6cad
style: drop undefined from optional properties
topsinoty Nov 17, 2026
357ef65
feat(events): sync events to the club Google Calendar instead of Disc…
topsinoty Nov 17, 2026
cb60a85
docs: trim Google Calendar notes
topsinoty Nov 17, 2026
6603487
docs: cut README to what is needed
topsinoty Nov 17, 2026
3016299
docs: list only the bot's Discord permissions
topsinoty Nov 17, 2026
74d6bc4
feat: remove @everyone mentions
topsinoty Nov 17, 2026
893ad9e
ci: restart the bot through a path unit instead of sudo
topsinoty Nov 17, 2026
2af6513
ci: rewrite the deploy script in Python
topsinoty Nov 17, 2026
4d3d902
ci: name the deploy paths instead of relying on the working directory
topsinoty Nov 17, 2026
dd538ad
docs: say where the server clone must live
topsinoty Nov 17, 2026
43b4e3e
ci: clone the server repo on first deploy and document overrides
topsinoty Nov 17, 2026
763ffbe
ci: give deploy paths clearer names
topsinoty Nov 17, 2026
b2fb911
fix the deploy script
topsinoty Nov 17, 2026
a340454
fix(deploy): verify restarts and rollback health
topsinoty Nov 17, 2026
49d690f
test(db): reject unsafe database reset targets
topsinoty Nov 17, 2026
cdfbaa1
fix(announcements): recheck author authorization
topsinoty Nov 17, 2026
45339b6
feat(auth): add Juhatus admins and member grants
topsinoty Nov 17, 2026
7b91df0
feat(events): add suggestions and calendar crossposts
topsinoty Nov 17, 2026
4f9fd03
docs: clarify permissions and event crossposting
topsinoty Nov 17, 2026
f3738dc
refactor: remove duplicate implementation layers
topsinoty Nov 18, 2026
5ca1e3f
refactor: use Zod forms and shared test fixtures
topsinoty Nov 18, 2026
73d149b
clear out db to use init db
topsinoty Nov 18, 2026
4d2b6c7
use dict comprehension
topsinoty Nov 18, 2026
df2eef6
fix: restore role panels and publication recovery
topsinoty Nov 18, 2026
f48c86d
perf(web): cache server metadata for 30 seconds
topsinoty Nov 18, 2026
33d14b6
fix(web): compact logs with simple pagination
topsinoty Nov 18, 2026
043770b
fix(web): prevent log viewer edge clipping
topsinoty Nov 18, 2026
684d746
fix(web): keep logs in the shared page container
topsinoty Nov 18, 2026
cdd3b0e
refactor(logs): use Drizzle search operators
topsinoty Nov 18, 2026
387593c
final fix
topsinoty Nov 18, 2026
88d3fed
refactor(birthdays): remove temporary role feature
topsinoty Nov 18, 2026
7dac224
fix(birthdays): use a valid announcement time
topsinoty Nov 18, 2026
9c08c34
use here mention
topsinoty Nov 18, 2026
2f20e4c
allow @here...
topsinoty Nov 18, 2026
cd0129b
oop
topsinoty Nov 18, 2026
7023de9
fix lint
topsinoty Nov 18, 2026
53d0675
test(birthdays): expect here mention
topsinoty Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Required
DISCORD_TOKEN=
DATABASE_URL=postgres://lapbot:lapbot@localhost:5432/lapbot

# Commands register at startup. With DISCORD_GUILD_ID set, commands are
# registered to that server only and update instantly.
DISCORD_APPLICATION_ID=
DISCORD_GUILD_ID=

LOG_LEVEL=info
LOG_DATABASE_PATH=logs/lapbot.sqlite
DEFAULT_TIMEZONE=Europe/Tallinn

# Legacy reaction role panel. Leave ROLE_SELECTION_CHANNEL_ID empty to disable.
ROLE_SELECTION_CHANNEL_ID=
TARKVARA_ROLE_ID=
HELPDESK_ROLE_ID=
KULTUUR_ROLE_ID=

# Movie details (optional). A TMDB "API Read Access Token" from
# https://www.themoviedb.org/settings/api fills in trailers, posters and synopses.
TMDB_ACCESS_TOKEN=

# Club Google Calendar (optional): lapikud@gmail.com, and the service
# account's JSON key on one line. Share the calendar with the service
# account's email with "Make changes to events".
GOOGLE_CALENDAR_ID=
GOOGLE_SERVICE_ACCOUNT_KEY=

# Web UI. Off unless WEB_PORT is set; needs DISCORD_GUILD_ID and Discord
# sign-in: DISCORD_CLIENT_SECRET from the developer portal (OAuth2), with
# <WEB_URL>/login added there as a redirect.
WEB_PORT=
WEB_HOST=127.0.0.1
WEB_URL=
DISCORD_CLIENT_SECRET=
# openssl rand -hex 32; keeps people signed in across restarts.
SESSION_SECRET=

# Juhatus role members are application administrators (all bot permissions).
JUHATUS_ROLE_ID=
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEST_DATABASE_URL=postgres://lapbot:lapbot@127.0.0.1:5433/lapbot_test
16 changes: 16 additions & 0 deletions .gitea/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Deploy to production

on:
push:
branches: [main]

jobs:
deploy:
name: Deploy to LXC
runs-on: lapbot
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Run deploy script
run: scripts/deploy/deploy.py
9 changes: 9 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Summary

<!-- What does this PR change, and why? -->

## Testing

<!-- How did you verify it? Commands run, manual steps, screenshots. -->

Closes #<!-- issue number, or write "none" -->
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

on:
pull_request:
workflow_call:

jobs:
check:
name: Lint, test and build
runs-on: ubuntu-latest
timeout-minutes: 20

services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: lapbot
POSTGRES_PASSWORD: lapbot
POSTGRES_DB: lapbot_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U lapbot"
--health-interval 5s
--health-timeout 5s
--health-retries 10

env:
TEST_DATABASE_URL: postgres://lapbot:lapbot@localhost:5432/lapbot_test

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check formatting
run: pnpm format:check

- name: Lint
run: pnpm lint

- name: Check types
run: pnpm typecheck

- name: Run tests
run: pnpm test

- name: Test the deploy script
run: python3 scripts/ci/deploy-test.py

- name: Build
run: pnpm build
31 changes: 31 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy to production

on:
push:
branches: [main]

jobs:
check:
name: CI
uses: ./.github/workflows/ci.yml

mirror:
name: Push main to Gitea
needs: check
runs-on: ubuntu-latest
timeout-minutes: 5
environment: production
concurrency:
group: mirror
cancel-in-progress: false

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Push to Gitea
env:
GITEA_REMOTE: ${{ secrets.GITEA_REMOTE }}
run: git push --force "$GITEA_REMOTE" HEAD:main
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules

# Log files
logs
/logs/
*.log
npm-debug.log*

Expand Down
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist
coverage
pnpm-lock.yaml
drizzle/meta

# Ignored execution artifacts
.superpowers
13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"singleQuote": true,
"semi": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "all",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"objectWrap": "preserve",
"endOfLine": "lf"
}
192 changes: 183 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,187 @@
# LAPbot

### SETUP
Install node_modules using `npm install` <br>
Create a `.env` file <br>
Put there `BOT TOKEN`, `CHANNELS IDs` and `ROLES IDs`
The Lapikud Discord bot and web dashboard.

`DISCORD_TOKEN=` <br>
`ROLE_SELECTION_CHANNEL_ID=` - Separate channel where bots role message goes. NB! MAKE SURE THAT NOBODY CAN SEND MESSAGES HERE (except for admins (bot has admin privileges)) <br>
`TARKVARA_ROLE_ID=` <br>
`HELPDESK_ROLE_ID=` <br>
`KULTUUR_ROLE_ID=` <br>
## Setup

Requires Node.js 24, pnpm and Docker.

```sh
pnpm install
cp .env.example .env
docker compose up -d
pnpm dev
```

Migrations and command registration run on start.

### Discord permissions

View Channels, Send Messages, Embed Links, Read Message History, Add Reactions,
Manage Messages and Manage Roles. The bot's role must be
above every role it hands out.

### Configuration

Settings are documented in `.env.example`.

- Application administrators: set `JUHATUS_ROLE_ID` to the Juhatus Discord role ID.
- Role selection: `ROLE_SELECTION_CHANNEL_ID` and the role IDs.
- Movie details: `TMDB_ACCESS_TOKEN`.
- Google Calendar: `GOOGLE_CALENDAR_ID=lapikud@gmail.com` and
`GOOGLE_SERVICE_ACCOUNT_KEY`.
- Dashboard: `WEB_PORT`, `DISCORD_GUILD_ID`, `DISCORD_CLIENT_SECRET` and
`SESSION_SECRET`, with `<WEB_URL>/login` as an OAuth2 redirect.

## Permissions

| Command | Who |
| ------------------------------------------------------------------- | ------------------------------------------------------ |
| `/remindme`, `/reminders list/edit/cancel` | everyone; channel reminders need `reminder:channel` |
| `/announce create/edit` | `announcement:create`, `:publish`, `:schedule` |
| `/event create/edit/cancel/list/view/attendees` | `event:create`; the organizer or `event:manage` edits |
| `/birthday set/remove/view/upcoming/post/settings` | everyone; `post` and `settings` need `birthday:manage` |
| `/poll create/list/results/close/cancel` | `poll:create`; the creator or `poll:manage` manages |
| `/movie suggest/suggestions/link/remove/vote/night/watched/history` | `vote`, `night` and `watched` need `movie:manage` |
| `/permissions grant/revoke/list` | `permissions:manage` |
| Web dashboard | `web:access` |

Discord administrators and members of `JUHATUS_ROLE_ID` hold every bot permission.
Roles and Logs are admin-only. Losing Juhatus removes its admin access.

Grant permissions to a role or member with `/permissions grant/revoke`, using
`role:` or `user:`. Personal and role grants combine. Non-admins can only grant
permissions they hold, to roles or members below their own. Only admins can
delegate `permissions:manage`.

### Events

`/event suggest text:going to the park` saves an idea and posts it in the current
channel without pings. The dashboard inbox needs `event:suggestions:manage`,
which grants inbox access without `web:access`.

Calendar crossposting is opt-in and needs `event:calendar:publish`. Choose it when
creating an event, or use `/event calendar id:` or the dashboard to post an
existing event. Only public-channel events can be crossposted. Editing linked
calendar details needs the same permission; cancellation removes the entry.
Retry failed calendar posts from the existing event.

## Development

| Script | Purpose |
| -------------------------------------------------- | ------------------------------------- |
| `pnpm dev` | Run with reload |
| `pnpm typecheck`, `pnpm lint`, `pnpm format:check` | Static checks |
| `pnpm test:db`, `pnpm test:integration` | Run all tests against a test database |
| `pnpm db:generate` | Create a migration |

The integration tests reset the database schema. Never point
`TEST_DATABASE_URL` at real data.

```text
src/
core/ shared primitives and ports
features/<name>/ models, rules and services
integrations/ adapters, including db/<name>/ tables and repositories
web/ dashboard
discord/ commands and listeners
app.ts wiring
tests/ role message, permissions, delivery, integrity
```

## Deploying

Pull requests run CI. A push to `main` runs CI, then mirrors to
`git.lapikud.ee`, where a runner in the LXC container runs
`scripts/deploy/deploy.py`. It builds a new release, restarts the `lapbot`
service and rolls back if the bot doesn't log `Ready` within 90 seconds.
Migrations are not rolled back, so each must work with the previous release.

`deploy.py` reads these from the runner's environment:

| Variable | Default | Purpose |
| ---------------------- | ------------------------------------- | ------------------------------ |
| `LAPBOT_ROOT` | `/opt/lapbot` | Where releases and `.env` live |
| `LAPBOT_SERVICE` | `lapbot` | The systemd service |
| `LAPBOT_READY_TIMEOUT` | `90` | Seconds to wait for `Ready` |
| `LAPBOT_REMOTE` | `origin` of the checkout it runs from | Where to clone `repo/` from |

If you change the root or service, change the unit files below to match.

### Server setup

As root, with PostgreSQL running:

1. Install Node 24, Python 3, git and act_runner, and run `corepack enable`.
2. Create the user and root:

```sh
useradd --system --create-home --shell /usr/sbin/nologin lapbot
usermod -aG systemd-journal lapbot
install -d -o lapbot -g lapbot /opt/lapbot
```

3. Write `/opt/lapbot/.env` (owner `lapbot`, mode `600`).
4. Add `/etc/systemd/system/lapbot.service`:

```ini
[Unit]
Description=LAPbot
After=network-online.target postgresql.service

[Service]
User=lapbot
WorkingDirectory=/opt/lapbot/current
EnvironmentFile=/opt/lapbot/.env
Environment=NODE_ENV=production
ExecStart=/usr/bin/node --enable-source-maps dist/index.mjs
Restart=on-failure
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target
```

5. Add the restart trigger, since `lapbot` has no sudo.
`/etc/systemd/system/lapbot-restart.path`:

```ini
[Path]
PathModified=/opt/lapbot/.restart

[Install]
WantedBy=multi-user.target
```

`/etc/systemd/system/lapbot-restart.service`:

```ini
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart lapbot
```

```sh
systemctl daemon-reload
systemctl enable lapbot
systemctl enable --now lapbot-restart.path
```

6. Register a repository-only runner and run `act_runner daemon` as `lapbot`:

```sh
cd /home/lapbot && runuser -u lapbot -- act_runner register --no-interactive \
--instance https://git.lapikud.ee --token <token> --name lapbot-lxc --labels lapbot:host
```

The runner can read production secrets. Restrict Gitea pushes to trusted
maintainers or use a read-only mirror.

Private repo: set `LAPBOT_REMOTE` in the runner environment. Use an SSH URL,
a read-only deploy key and configured known hosts.

7. On GitHub, add a `production` environment with the secret `GITEA_REMOTE`:
`https://<user>:<token>@git.lapikud.ee/<owner>/lapbot.git`.
8. Push to `main`. The first deploy clones `/opt/lapbot/repo`.

Logs: `journalctl -u lapbot`. Back up the database and `/opt/lapbot/logs`.
Loading
Loading