You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.3 KiB
69 lines
1.3 KiB
package main |
|
|
|
import ( |
|
"fmt" |
|
"image" |
|
"math/rand" |
|
"os" |
|
"strings" |
|
"time" |
|
|
|
"github.com/llgcode/draw2d/draw2dimg" |
|
"github.com/rogpeppe/misc/svg" |
|
"github.com/rudi9719/loggy" |
|
"samhofi.us/x/keybase/v2" |
|
"samhofi.us/x/keybase/v2/types/chat1" |
|
) |
|
|
|
var ( |
|
k = keybase.NewKeybase() |
|
|
|
configFile = "config.json" |
|
config Config |
|
log = loggy.NewLogger(config.LogOpts) |
|
r = rand.New(rand.NewSource(time.Now().UnixNano())) |
|
) |
|
|
|
func printChat(m chat1.MsgSummary) { |
|
defer log.PanicSafe() |
|
if m.Sender.Username == k.Username { |
|
return |
|
} |
|
if strings.HasPrefix(m.Content.Text.Body, "@chessbot") { |
|
chessCommand(m) |
|
return |
|
} |
|
log.LogInfo("%s: %s\n", m.Sender.Username, m.Content.Text.Body) |
|
} |
|
func main() { |
|
loadConfig() |
|
log = loggy.NewLogger(config.LogOpts) |
|
defer log.PanicSafe() |
|
chat := printChat |
|
err := log.LogErrorType |
|
handlers := keybase.Handlers{ |
|
ChatHandler: &chat, |
|
ErrorHandler: &err, |
|
} |
|
log.LogCritical("Starting Chessbot") |
|
k.Run(handlers, &keybase.RunOptions{}) |
|
} |
|
func svgToPNG(path string) bool { |
|
defer log.PanicSafe() |
|
file, err := os.Open(fmt.Sprintf("%+v.svg", path)) |
|
if err != nil { |
|
return false |
|
} |
|
defer file.Close() |
|
size := image.Point{512, 512} |
|
dest, err := svg.Render(file, size) |
|
if err != nil { |
|
return false |
|
} |
|
err = draw2dimg.SaveToPngFile(fmt.Sprintf("%+v.png", path), dest) |
|
if err != nil { |
|
return false |
|
} |
|
return true |
|
|
|
}
|
|
|