all repos — honk @ facf1bba11595ec5a5e51801ae170755924f4c9c

my fork of honk

honk.go (view raw)

  1//
  2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
  3//
  4// Permission to use, copy, modify, and distribute this software for any
  5// purpose with or without fee is hereby granted, provided that the above
  6// copyright notice and this permission notice appear in all copies.
  7//
  8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15
 16package main
 17
 18import (
 19	"fmt"
 20	"html/template"
 21	"log"
 22	"os"
 23	"time"
 24)
 25
 26type WhatAbout struct {
 27	ID        int64
 28	Name      string
 29	Display   string
 30	About     string
 31	Key       string
 32	URL       string
 33	SkinnyCSS bool
 34}
 35
 36type Honk struct {
 37	ID       int64
 38	UserID   int64
 39	Username string
 40	What     string
 41	Honker   string
 42	Handle   string
 43	Oonker   string
 44	Oondle   string
 45	XID      string
 46	RID      string
 47	Date     time.Time
 48	URL      string
 49	Noise    string
 50	Precis   string
 51	Format   string
 52	Convoy   string
 53	Audience []string
 54	Public   bool
 55	Whofore  int64
 56	Replies  []*Honk
 57	Flags    int64
 58	HTPrecis template.HTML
 59	HTML     template.HTML
 60	Style    string
 61	Open     string
 62	Donks    []*Donk
 63	Onts     []string
 64}
 65
 66const (
 67	flagIsAcked  = 1
 68	flagIsBonked = 2
 69)
 70
 71func (honk *Honk) IsAcked() bool {
 72	return honk.Flags&flagIsAcked != 0
 73}
 74
 75func (honk *Honk) IsBonked() bool {
 76	return honk.Flags&flagIsBonked != 0
 77}
 78
 79type Donk struct {
 80	FileID  int64
 81	XID     string
 82	Name    string
 83	Desc    string
 84	URL     string
 85	Media   string
 86	Local   bool
 87	Content []byte
 88}
 89
 90type Honker struct {
 91	ID     int64
 92	UserID int64
 93	Name   string
 94	XID    string
 95	Handle string
 96	Flavor string
 97	Combos []string
 98}
 99
100type Zonker struct {
101	ID        int64
102	Name      string
103	Wherefore string
104}
105
106var serverName string
107var iconName = "icon.png"
108var serverMsg = "Things happen."
109
110func ElaborateUnitTests() {
111}
112
113func main() {
114	cmd := "run"
115	if len(os.Args) > 1 {
116		cmd = os.Args[1]
117	}
118	switch cmd {
119	case "init":
120		initdb()
121	case "upgrade":
122		upgradedb()
123	}
124	db := opendatabase()
125	dbversion := 0
126	getconfig("dbversion", &dbversion)
127	if dbversion != myVersion {
128		log.Fatal("incorrect database version. run upgrade.")
129	}
130	getconfig("servermsg", &serverMsg)
131	getconfig("servername", &serverName)
132	getconfig("usersep", &userSep)
133	getconfig("honksep", &honkSep)
134	prepareStatements(db)
135	switch cmd {
136	case "adduser":
137		adduser()
138	case "cleanup":
139		arg := "30"
140		if len(os.Args) > 2 {
141			arg = os.Args[2]
142		}
143		cleanupdb(arg)
144	case "ping":
145		if len(os.Args) < 4 {
146			fmt.Printf("usage: honk ping from to\n")
147			return
148		}
149		name := os.Args[2]
150		targ := os.Args[3]
151		user, err := butwhatabout(name)
152		if err != nil {
153			log.Printf("unknown user")
154			return
155		}
156		ping(user, targ)
157	case "peep":
158		peeppeep()
159	case "run":
160		serve()
161	case "test":
162		ElaborateUnitTests()
163	default:
164		log.Fatal("unknown command")
165	}
166}