ref: 7eeca4c25afb01df3f134237014f9583975fc608
dir: /main.go/
package main
import (
"fmt"
)
func main() {
hc, err := NewHellclient()
if err != nil {
fmt.Printf("Error starting account: %v\n", err)
return
}
rl := hc.rl
client := *hc.client
enablePipeHack(rl)
go StreamHomeTimeline(&client, hc.homeMap, hc)
for {
func() {
line, err := rl.Readline()
hc.lock()
defer hc.unlock()
command, arguments, _ := processInput(line, []string{})
//empty line
if command == "" && arguments == "" && err == nil {
hc.togglepause()
return
}
if command == "" && arguments == "" && err != nil {
return
}
//if we didn't get a slash command then the user is just posting
if command == "" && arguments != "" {
hc.dispatchStatus(line, "public")
return
}
result, err := hc.cmdload.run(line)
if err != nil {
fmt.Print(err)
}
fmt.Print(result)
return
if !found {
fmt.Printf("Command not found: \"%s\"\n", command)
return
}
index, content, _ := strings.Cut(arguments, " ")
postItem, postOK := homeMap[index]
//Wether we got a post index or not
foundindex := false
//If there's no index selected load the last post we operated on
if postOK {
foundindex = true
lastindex = index
} else {
postItem, postOK = homeMap[lastindex]
}
//Okay now see if the post we end up with is a reblog
if postOK {
if postItem.Reblog != nil {
postItem = postItem.Reblog
}
}
cmdctx, _ := hc.cmdload.processLine(line)
hc.PrintObjectProperties(cmdctx.account)
hc.PrintObjectProperties(cmdctx.status)
hc.PrintObjectProperties(cmdctx.reblogger)
fmt.Println(cmdctx.raw_argument)
fmt.Println(cmdctx.command)
fmt.Println(cmdctx.content)
fmt.Println(cmdctx.index)
accByNameOrRef := func() (account *mastodon.Account) {
if lastaccount != nil {
account = lastaccount
return
}
if lastindex != "" {
account = &postItem.Account
return
}
account = hc.resolveAccount(arguments)
lastindex = ""
postItem = nil
lastaccount = account
return
}
formatter := &StatusFormatter{prefs: hc.preferences, status: postItem, postContext: hc.ctxref, localindex: index}
templater := newStatusTemplateRenderer(formatter)
//Commands require status indexes
switch command {
case "block":
var account *mastodon.Account
if foundindex || index == "" {
account = &postItem.Account
} else {
account = hc.resolveAccount(index)
if account == nil {
fmt.Printf("Account or index not found.\n")
return
}
}
blockfunc := func() {
_, err := client.AccountBlock(context.Background(), account.ID)
if err != nil {
fmt.Printf("Error blocking account: %s.\n")
return
}
fmt.Printf("Account blocked: %s\n", account.Acct)
}
hc.dispatchAnon(blockfunc).Wait()
return
case "unblock":
var account *mastodon.Account
if foundindex || index == "" {
account = &postItem.Account
} else {
account = hc.resolveAccount(index)
if account == nil {
fmt.Printf("Account or index not found.\n")
return
}
}
unblockfunc := func() {
_, err := client.AccountBlock(context.Background(), account.ID)
if err != nil {
fmt.Printf("Error blocking account: %s.\n")
return
}
fmt.Printf("Account unblocked: %s\n", account.Acct)
}
hc.dispatchAnon(unblockfunc).Wait()
return
}
//Posts that need an index and an argument
if content == "" {
fmt.Printf("\"%v\" requires an argument\n", command)
return
}
}()
}
}