From 05dd8635f948cafc9bc8ae0c0b4c25433cdc973a Mon Sep 17 00:00:00 2001 From: donuts-are-good <96031819+donuts-are-good@users.noreply.github.com> Date: Thu, 20 Apr 2023 23:15:01 -0500 Subject: [PATCH] preliminary API draft fixes #8 --- db.go | 6 ++++++ main.go | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/db.go b/db.go index 05a2dc5..65ed9cc 100644 --- a/db.go +++ b/db.go @@ -35,3 +35,9 @@ func initBoardSchema(db *sqlx.DB) { log.Fatalln(err) } } + + +func createReply(db *sqlx.DB, postID int, authorHash string, replyBody string) error { + _, err := db.Exec("INSERT INTO replies (discussion_id, author, message) VALUES (?, ?, ?)", postID, authorHash, replyBody) + return err +} diff --git a/main.go b/main.go index 946e158..e3c70fd 100644 --- a/main.go +++ b/main.go @@ -77,6 +77,9 @@ func main() { } defer listener.Close() fmt.Println("Listening on :" + os.Args[1]) + + go api(db) + for { conn, err := listener.Accept() if err != nil { @@ -181,6 +184,12 @@ func handleConnection(db *sqlx.DB, channel ssh.Channel, sshConn *ssh.ServerConn, listDiscussions(db, term) case strings.HasPrefix(input, "/history"): printCachedMessages(term) + case strings.HasPrefix(input, "/tokens new"): + handleTokenNew(db, term, hash) + case strings.HasPrefix(input, "/tokens list"): + handleTokenList(db, term, hash) + case strings.HasPrefix(input, "/tokens revoke"): + handleTokenRevoke(db, input, term, hash) case strings.HasPrefix(input, "/quit") || strings.HasPrefix(input, "/q") || strings.HasPrefix(input, "/exit") || strings.HasPrefix(input, "/x") || strings.HasPrefix(input, "/leave") || strings.HasPrefix(input, "/part"): @@ -195,7 +204,7 @@ func handleConnection(db *sqlx.DB, channel ssh.Channel, sshConn *ssh.ServerConn, term.Write([]byte("Unrecognized command. Type /help for available commands.\n")) } else { message := fmt.Sprintf("[%s] %s: %s", time.Now().String()[11:16], hash, input) - broadcast(message + "\r") + broadcast(hash, message+"\r") } } } @@ -261,9 +270,12 @@ func disconnect(hash string) { removeUser(hash) } -func broadcast(message string) { +func broadcast(senderHash, message string) { addToCache(message) for _, user := range getAllUsers() { + if user.Hash == senderHash { + continue + } saveCursorPos(user.Conn) moveCursorUp(user.Conn, 1) fmt.Fprintln(user.Conn, message) @@ -663,12 +675,12 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - `)) +`)) } func writeVersionInfo(term *term.Terminal) { term.Write([]byte(` - shhhbb bbs ` + semverInfo + ` - MIT License 2023 donuts-are-good - https://github.com/donuts-are-good/shhhbb - `)) +shhhbb bbs ` + semverInfo + ` +MIT License 2023 donuts-are-good +https://github.com/donuts-are-good/shhhbb +`)) }