mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 11:07:22 +00:00
Merge branch 'feature/TypeCommands' of keybase://team/dxb_.rudi9719/kbtui
This commit is contained in:
12
build.go
Normal file
12
build.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// +build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/magefile/mage/mage"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
os.Exit(mage.Main())
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -20,11 +21,19 @@ func init() {
|
|||||||
|
|
||||||
func cmdHelp(cmd []string) {
|
func cmdHelp(cmd []string) {
|
||||||
var helpText string
|
var helpText string
|
||||||
|
var tCommands []string
|
||||||
if len(cmd) == 1 {
|
if len(cmd) == 1 {
|
||||||
sort.Strings(baseCommands)
|
sort.Strings(baseCommands)
|
||||||
for _, c := range baseCommands {
|
for _, c := range baseCommands {
|
||||||
helpText = fmt.Sprintf("%s%s%s\t\t%s\n", helpText, cmdPrefix, c, commands[c].Description)
|
helpText = fmt.Sprintf("%s%s%s\t\t%s\n", helpText, cmdPrefix, c, commands[c].Description)
|
||||||
}
|
}
|
||||||
|
if len(typeCommands) > 0 {
|
||||||
|
for c, _ := range typeCommands {
|
||||||
|
tCommands = append(tCommands, typeCommands[c].Name)
|
||||||
|
}
|
||||||
|
sort.Strings(tCommands)
|
||||||
|
helpText = fmt.Sprintf("%s\nThe following Type Commands are currently loaded: %s", helpText, strings.Join(tCommands, ", "))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printToView("Chat", helpText)
|
printToView("Chat", helpText)
|
||||||
}
|
}
|
||||||
|
|||||||
32
mage.go
Normal file
32
mage.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// +build mage
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/magefile/mage/sh"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Build kbtui with just the basic commands.
|
||||||
|
func Build() {
|
||||||
|
sh.Run("go", "build")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build kbtui with the basic commands, and the ShowReactions "TypeCommand".
|
||||||
|
// The ShowReactions TypeCommand will print a message in the feed window when
|
||||||
|
// a reaction is received in the current conversation.
|
||||||
|
func BuildShowReactions() {
|
||||||
|
sh.Run("go", "build", "-tags", "showreactionscmd")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build kbtui with the basec commands, and the AutoReact "TypeCommand".
|
||||||
|
// The AutoReact TypeCommand will automatically react to every message
|
||||||
|
// received in the current conversation. This gets pretty annoying, and
|
||||||
|
// is not recommended.
|
||||||
|
func BuildAutoReact() {
|
||||||
|
sh.Run("go", "build", "-tags", "autoreactcmd")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build kbtui with all Commands and TypeCommands enabled.
|
||||||
|
func BuildAllCommands() {
|
||||||
|
sh.Run("go", "build", "-tags", "type_commands")
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
// +build ignore
|
// +ignore
|
||||||
// +build type_commands autoreactcmd
|
// +build type_commands autoreactcmd
|
||||||
|
|
||||||
package main
|
package main
|
||||||
@ -10,6 +10,7 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
command := TypeCommand{
|
command := TypeCommand{
|
||||||
Cmd: []string{"text"},
|
Cmd: []string{"text"},
|
||||||
|
Name: "AutoReact",
|
||||||
Description: "Automatically reacts to every incoming message with an emoji",
|
Description: "Automatically reacts to every incoming message with an emoji",
|
||||||
Exec: tcmdAutoReact,
|
Exec: tcmdAutoReact,
|
||||||
}
|
}
|
||||||
|
|||||||
25
tcmdShowReactions.go
Normal file
25
tcmdShowReactions.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// +ignore
|
||||||
|
// +build type_commands showreactionscmd
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"samhofi.us/x/keybase"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
command := TypeCommand{
|
||||||
|
Cmd: []string{"reaction"},
|
||||||
|
Name: "ShowReactions",
|
||||||
|
Description: "Prints a message in the feed any time a reaction is received",
|
||||||
|
Exec: tcmdShowReactions,
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterTypeCommand(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tcmdShowReactions(m keybase.ChatAPI) {
|
||||||
|
printToView("Feed", fmt.Sprintf("%s reacted to %d with %s", m.Msg.Sender.Username, m.Msg.Content.Reaction.M, m.Msg.Content.Reaction.B))
|
||||||
|
}
|
||||||
1
types.go
1
types.go
@ -13,6 +13,7 @@ type Command struct {
|
|||||||
// TypeCommand outlines a command that reacts on message type
|
// TypeCommand outlines a command that reacts on message type
|
||||||
type TypeCommand struct {
|
type TypeCommand struct {
|
||||||
Cmd []string // Message types that trigger this command
|
Cmd []string // Message types that trigger this command
|
||||||
|
Name string // The name of this command
|
||||||
Description string // A short description of the command
|
Description string // A short description of the command
|
||||||
Exec func(keybase.ChatAPI) // A function that takes a raw chat message as input
|
Exec func(keybase.ChatAPI) // A function that takes a raw chat message as input
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user