feat: add pvta (with map support!)

This commit is contained in:
Jack Merrill 2023-08-19 00:27:57 -05:00
parent 62706e8309
commit ebc85c4b9a
No known key found for this signature in database
GPG Key ID: B8E3CDF57DD80CA5
6 changed files with 293 additions and 2 deletions

10
go.mod
View File

@ -11,10 +11,16 @@ require (
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/charmbracelet/log v0.2.3 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/flopp/go-coordsparser v0.0.0-20201115094714-8baaeb7062d5 // indirect
github.com/flopp/go-staticmaps v0.0.0-20220221183018-c226716bec53 // indirect
github.com/fogleman/gg v1.3.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-redis/redis/v8 v8.11.0 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jackmerrill/hamp-api v0.0.0-20230818235104-8d222c9674c9 // indirect
github.com/jackmerrill/pvta-go v0.0.0-20220912020258-36dee8883b6e // indirect
github.com/labstack/echo/v4 v4.9.1 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
@ -26,12 +32,14 @@ require (
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sarulabs/di/v2 v2.4.2 // indirect
github.com/sashabaranov/go-openai v1.14.2 // indirect
github.com/tkrajina/gpxgo v1.3.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/zekroTJA/shireikan v0.7.0 // indirect
github.com/zekrotja/dgrs v0.3.1 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
)

31
go.sum
View File

@ -18,6 +18,12 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/flopp/go-coordsparser v0.0.0-20201115094714-8baaeb7062d5 h1:o5yuyiGtJ4c9ECOq12K6EqsQNnsGF6I+WqBZynB2Hlw=
github.com/flopp/go-coordsparser v0.0.0-20201115094714-8baaeb7062d5/go.mod h1:t5EAdR9sDhKR06Ix2ZS/8jt8INpzeV3P5uVyEkCDYJc=
github.com/flopp/go-staticmaps v0.0.0-20220221183018-c226716bec53 h1:bpgLIxOpmht6HkBsajYmp+CvNAtdXnb+uGZQw3pIxtU=
github.com/flopp/go-staticmaps v0.0.0-20220221183018-c226716bec53/go.mod h1:vGgI6wKa1TTiN9iumpzYZgNc/C7KxqsZbw9OH8O10iQ=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
@ -25,6 +31,11 @@ github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KE
github.com/go-redis/redis/v8 v8.10.0/go.mod h1:vXLTvigok0VtUX0znvbcEW1SOt4OA9CU1ZfnOtKOaiM=
github.com/go-redis/redis/v8 v8.11.0 h1:O1Td0mQ8UFChQ3N9zFQqo6kTU2cJ+/it88gDB+zg0wo=
github.com/go-redis/redis/v8 v8.11.0/go.mod h1:DLomh7y2e3ggQXQLd1YgmvIfecPJoFl7WU5SOQ/r06M=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI=
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 h1:HKlyj6in2JV6wVkmQ4XmG/EIm+SCYlPZ+V4GWit7Z+I=
github.com/golang/geo v0.0.0-20230421003525-6adc56603217/go.mod h1:8wI0hitZ3a1IxZfeH3/5I97CI8i5cLGsYe7xNhQGs9U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
@ -45,6 +56,10 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jackmerrill/hamp-api v0.0.0-20230818235104-8d222c9674c9 h1:ZP4cMycNDHXMk5LQ+VbDq7So0e7gbYPetPpvqbD2XLo=
github.com/jackmerrill/hamp-api v0.0.0-20230818235104-8d222c9674c9/go.mod h1:KS8EBP1su7OHA4Kq5+wZkx162SEVDbIbUV9yo0MMRac=
github.com/jackmerrill/pvta-go v0.0.0-20220912020258-36dee8883b6e h1:Mo9/4mW8hbak/VKFZt3Xp7Vuq7mKpUQO4d7AwR5CqZA=
github.com/jackmerrill/pvta-go v0.0.0-20220912020258-36dee8883b6e/go.mod h1:olGzOWsVmkZNZzHU1ERqtCwMkQelMH6MGMTR0t0GKeE=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/joeshaw/gengen v0.0.0-20190604015154-c77d87825f5a/go.mod h1:v2qvRL8Xwk4OlARK6gPlf2JreZXzv0dYp/8+kUJ0y7Q=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@ -86,6 +101,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tkrajina/gpxgo v1.1.2/go.mod h1:795sjVRFo5wWyN6oOZp0RYienGGBJjpAlgOz2nCngA0=
github.com/tkrajina/gpxgo v1.3.0 h1:rXqIey0Mc6wOvEoKHEnhZG6Kgxq/vQsOUs7/AME128Q=
github.com/tkrajina/gpxgo v1.3.0/go.mod h1:795sjVRFo5wWyN6oOZp0RYienGGBJjpAlgOz2nCngA0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
@ -117,25 +135,35 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5U
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -146,6 +174,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
@ -172,9 +201,11 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190603231351-8aaa1484dc10/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -59,7 +59,7 @@ func (c *Laundry) GetGroup() string {
}
func (c *Laundry) GetDomainName() string {
return "hamp.util.laundry"
return "hamp.studentlife.laundry"
}
func (c *Laundry) GetSubPermissionRules() []shireikan.SubPermission {

View File

@ -0,0 +1,179 @@
package studentlife
import (
"bytes"
"fmt"
"image/color"
"image/png"
"os"
"strings"
"github.com/bwmarrin/discordgo"
sm "github.com/flopp/go-staticmaps"
"github.com/golang/geo/s2"
"github.com/jackmerrill/hampbot/internal/utils/config"
"github.com/jackmerrill/hampbot/internal/utils/embed"
pvtago "github.com/jackmerrill/pvta-go"
"github.com/zekroTJA/shireikan"
)
type PVTA struct {
}
func (c *PVTA) GetInvokes() []string {
return []string{"pvta", "bus"}
}
func (c *PVTA) GetDescription() string {
return "Get the details and location of a PVTA bus"
}
func (c *PVTA) GetHelp() string {
return "`pvta [route] <vehicle>` - Get the details and location of a PVTA bus"
}
func (c *PVTA) GetGroup() string {
return config.GroupUtil
}
func (c *PVTA) GetDomainName() string {
return "hamp.studentlife.pvta"
}
func (c *PVTA) GetSubPermissionRules() []shireikan.SubPermission {
return nil
}
func (c *PVTA) IsExecutableInDMChannels() bool {
return true
}
func getRouteByShortName(shortName string) (*pvtago.RouteDetail, error) {
client := pvtago.NewClient()
routes, err := client.GetRoutes()
if err != nil {
return nil, err
}
for _, route := range routes {
if route.ShortName == shortName {
return &route, nil
}
}
return nil, nil
}
func (c *PVTA) Exec(ctx shireikan.Context) error {
client := pvtago.NewClient()
route := ctx.GetArgs().Get(0).AsString()
if route == "" {
routes, err := client.GetVisibleRoutes()
if err != nil {
return err
}
var routeIds []string
for _, route := range routes {
if route.ShortName != "" {
routeIds = append(routeIds, route.ShortName)
}
}
ctx.ReplyEmbed(embed.NewSuccessEmbed(ctx).SetTitle("Available PVTA routes").SetDescription(strings.Join(routeIds, ", ")).MessageEmbed)
return nil
}
vehicle := ctx.GetArgs().Get(1).AsString()
if vehicle == "" {
route, err := getRouteByShortName(route)
if err != nil {
ctx.ReplyEmbed(embed.NewErrorEmbed(ctx).SetTitle("Error").SetDescription("An error occured while fetching the route.").AddField("Error", err.Error(), false).MessageEmbed)
return err
}
vehicles, err := client.GetVehiclesForRoute(route.RouteID)
if err != nil {
return err
}
e := embed.NewSuccessEmbed(ctx).SetTitle(":bus: PVTA Route Details").SetDescription(fmt.Sprintf("**Route:** %s\n**Name:** %s", route.ShortName, route.LongName))
tileProvider := &sm.TileProvider{
Name: "thunderforest-transit",
Attribution: "Maps (c) Thundeforest; Data (c) OSM and contributors, ODbL",
TileSize: 256,
URLPattern: "https://%[1]s.tile.thunderforest.com/transport/%[2]d/%[3]d/%[4]d.png?apikey=" + os.Getenv("TF_API_KEY"),
Shards: []string{"a", "b", "c"},
}
mapCtx := sm.NewContext()
mapCtx.SetSize(600, 400)
mapCtx.SetTileProvider(tileProvider)
for _, vehicle := range vehicles {
e.AddField(fmt.Sprintf("Vehicle #`%d`", vehicle.VehicleID), fmt.Sprintf(":round_pushpin: **Destination:** %s (%s)\n:globe_with_meridians: **Lat/Long:** `%f` `%f`", vehicle.Destination, vehicle.Direction, vehicle.Latitude, vehicle.Longitude), false)
rgb, err := config.Hex2RGB(config.Hex(route.Color))
if err != nil {
return err
}
mapCtx.AddObject(
sm.NewMarker(
s2.LatLngFromDegrees(vehicle.Latitude, vehicle.Longitude),
color.RGBA{R: rgb.Red, G: rgb.Green, B: rgb.Blue, A: 255},
16.0,
),
)
}
img, err := mapCtx.Render()
if err != nil {
return err
}
// convert to base64
buf := new(bytes.Buffer)
err = png.Encode(buf, img)
if err != nil {
return err
}
e.SetImage("attachment://map.png")
_, err = ctx.GetSession().ChannelMessageSendComplex(ctx.GetChannel().ID, &discordgo.MessageSend{
Embed: e.MessageEmbed,
Reference: ctx.GetMessage().Reference(),
Files: []*discordgo.File{
{
Name: "map.png",
ContentType: "image/png",
Reader: buf,
},
},
})
if err != nil {
return err
}
return nil
}
return nil
}

View File

@ -2,7 +2,10 @@ package config
import (
"fmt"
"strconv"
"time"
"github.com/bwmarrin/discordgo"
)
var (
@ -30,6 +33,29 @@ var (
GroupDev = "Dev"
)
var Statuses = []discordgo.Activity{
{
Name: "with frogs",
Type: discordgo.ActivityTypeGame,
},
{
Name: fmt.Sprintf("PVTA Simulator %d", time.Now().Year()),
Type: discordgo.ActivityTypeGame,
},
{
Name: "Stray",
Type: discordgo.ActivityTypeGame,
},
{
Name: "the Dakin fire alarm",
Type: discordgo.ActivityTypeListening,
},
{
Name: "at the Roos-Rhode house",
Type: discordgo.ActivityTypeGame,
},
}
func ConvertTimestampToDiscordTimestamp(t time.Time) string {
// format: <t:1234567890> where 1234567890 is the unix timestamp
@ -45,3 +71,32 @@ func ConvertTimestampToDiscordTimestampWithFormat(t time.Time, format string) st
return "<t:" + fmt.Sprint(u) + ":" + format + ">"
}
type Hex string
type RGB struct {
Red uint8
Green uint8
Blue uint8
}
func (h Hex) toRGB() (RGB, error) {
return Hex2RGB(h)
}
func Hex2RGB(hex Hex) (RGB, error) {
var rgb RGB
values, err := strconv.ParseUint(string(hex), 16, 32)
if err != nil {
return RGB{}, err
}
rgb = RGB{
Red: uint8(values >> 16),
Green: uint8((values >> 8) & 0xFF),
Blue: uint8(values & 0xFF),
}
return rgb, nil
}

18
main.go
View File

@ -73,8 +73,26 @@ func main() {
handler.Register(&fun.Dalle{})
log.Debug("Registered dalle command")
handler.Register(&studentlife.PVTA{})
log.Debug("Registered PVTA command")
log.Info("Registered all commands")
log.Info("Setting up activities...")
activities := config.Statuses
go func() {
for {
activity := activities[rand.Intn(len(activities))]
session.UpdateStatusComplex(discordgo.UpdateStatusData{
Activities: []*discordgo.Activity{&activity},
Status: "online",
})
time.Sleep(10 * time.Second)
}
}()
handler.Setup(session)
log.Info("Bot is now running. Press CTRL-C to exit.")