parent
d9d2c37cd0
commit
fc69d41d50
3 changed files with 345 additions and 0 deletions
@ -0,0 +1,21 @@ |
|||||||
|
module sport |
||||||
|
|
||||||
|
go 1.18 |
||||||
|
|
||||||
|
require ( |
||||||
|
github.com/Jeffail/gabs v1.4.0 // indirect |
||||||
|
github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20221121042443-a3fd332d56d9 // indirect |
||||||
|
github.com/bwmarrin/discordgo v0.27.1 // indirect |
||||||
|
github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4 // indirect |
||||||
|
github.com/gorilla/websocket v1.4.2 // indirect |
||||||
|
github.com/jackc/pgpassfile v1.0.0 // indirect |
||||||
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect |
||||||
|
github.com/jackc/pgx/v5 v5.3.1 // indirect |
||||||
|
github.com/jackc/puddle/v2 v2.2.0 // indirect |
||||||
|
github.com/sony/sonyflake v1.0.0 // indirect |
||||||
|
golang.org/x/crypto v0.6.0 // indirect |
||||||
|
golang.org/x/net v0.6.0 // indirect |
||||||
|
golang.org/x/sync v0.1.0 // indirect |
||||||
|
golang.org/x/sys v0.5.0 // indirect |
||||||
|
golang.org/x/text v0.7.0 // indirect |
||||||
|
) |
@ -0,0 +1,93 @@ |
|||||||
|
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo= |
||||||
|
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc= |
||||||
|
github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20221121042443-a3fd332d56d9 h1:vuu1KBsr6l7XU3CHsWESP/4B1SNd+VZkrgeFZsUXrsY= |
||||||
|
github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20221121042443-a3fd332d56d9/go.mod h1:rjP7sIipbZcagro/6TCk6X0ZeFT2eyudH5+fve/cbBA= |
||||||
|
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY= |
||||||
|
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= |
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
||||||
|
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= |
||||||
|
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/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= |
||||||
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= |
||||||
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= |
||||||
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= |
||||||
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= |
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= |
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= |
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= |
||||||
|
github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4 h1:4EZlYQIiyecYJlUbVkFXCXHz1QPhVXcHnQKAzBTPfQo= |
||||||
|
github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4/go.mod h1:lEO7XoHJ/xNRBCxrn4h/CEB67h0kW1B0t4ooP2yrjUA= |
||||||
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= |
||||||
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
||||||
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= |
||||||
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= |
||||||
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= |
||||||
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= |
||||||
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= |
||||||
|
github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= |
||||||
|
github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= |
||||||
|
github.com/jackc/puddle/v2 v2.2.0 h1:RdcDk92EJBuBS55nQMMYFXTxwstHug4jkhT5pq8VxPk= |
||||||
|
github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= |
||||||
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= |
||||||
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= |
||||||
|
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= |
||||||
|
github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= |
||||||
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= |
||||||
|
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= |
||||||
|
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= |
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
||||||
|
github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM= |
||||||
|
github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4= |
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= |
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= |
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= |
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= |
||||||
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= |
||||||
|
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= |
||||||
|
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= |
||||||
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= |
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= |
||||||
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= |
||||||
|
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= |
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= |
||||||
|
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q= |
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= |
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= |
||||||
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= |
||||||
|
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= |
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||||
|
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||||
|
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||||
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||||
|
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= |
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= |
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= |
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= |
||||||
|
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= |
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= |
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
||||||
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= |
||||||
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= |
||||||
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= |
||||||
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= |
||||||
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= |
||||||
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= |
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
||||||
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= |
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= |
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
@ -0,0 +1,231 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"bytes" |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"os" |
||||||
|
"strings" |
||||||
|
"text/tabwriter" |
||||||
|
"time" |
||||||
|
"github.com/bwmarrin/discordgo" |
||||||
|
"github.com/jackc/pgx/v5" |
||||||
|
) |
||||||
|
|
||||||
|
var conn *pgx.Conn |
||||||
|
var token = "BOT-TOKEN" |
||||||
|
|
||||||
|
func main() { |
||||||
|
var err error |
||||||
|
urlExample := "DB-URL" |
||||||
|
conn, err = pgx.Connect(context.Background(), urlExample) |
||||||
|
if err != nil { |
||||||
|
fmt.Fprintf(os.Stderr, "Unable to connect to the database: %v\n", err) |
||||||
|
os.Exit(1) |
||||||
|
} |
||||||
|
|
||||||
|
discord, err := discordgo.New("Bot " + token) |
||||||
|
if err != nil { |
||||||
|
fmt.Fprintf(os.Stderr, "Error creating Discord session: %v\n", err) |
||||||
|
os.Exit(1) |
||||||
|
} |
||||||
|
|
||||||
|
discord.AddHandler(messageCreate) |
||||||
|
|
||||||
|
err = discord.Open() |
||||||
|
if err != nil { |
||||||
|
fmt.Fprintf(os.Stderr, "Error opening connection to Discord: %v\n", err) |
||||||
|
os.Exit(1) |
||||||
|
} |
||||||
|
|
||||||
|
defer discord.Close() |
||||||
|
|
||||||
|
fmt.Println("Bot is now running. Press CTRL-C to exit.") |
||||||
|
<-make(chan struct{}) |
||||||
|
} |
||||||
|
|
||||||
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { |
||||||
|
if m.Author.Bot { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
args := strings.Fields(m.Content) |
||||||
|
if len(args) < 2 { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
switch args[1] { |
||||||
|
case "tug": |
||||||
|
printTug(s, m.ChannelID) |
||||||
|
case "dev": |
||||||
|
printDev(s, m.ChannelID) |
||||||
|
case "help": |
||||||
|
printHelp(s, m.ChannelID) |
||||||
|
case "epg": |
||||||
|
printEpg(s, m.ChannelID) |
||||||
|
case "utc": |
||||||
|
printCurrentTimeUTC(s, m.ChannelID) |
||||||
|
case "guide": |
||||||
|
userTerm := "" |
||||||
|
if len(args) >= 3 { |
||||||
|
userTerm = args[2] |
||||||
|
} |
||||||
|
err := guideTerm(s, m.ChannelID, userTerm) |
||||||
|
if err != nil { |
||||||
|
fmt.Fprintf(os.Stderr, "Unable to list events: %v\n", err) |
||||||
|
s.ChannelMessageSend(m.ChannelID, "An error occurred while retrieving data.") |
||||||
|
} |
||||||
|
case "whatson": |
||||||
|
userTerm := "" |
||||||
|
if len(args) >= 3 { |
||||||
|
userTerm = args[2] |
||||||
|
} |
||||||
|
err := whatsonTerm(s, m.ChannelID, userTerm) |
||||||
|
if err != nil { |
||||||
|
fmt.Fprintf(os.Stderr, "Unable to list events: %v\n", err) |
||||||
|
s.ChannelMessageSend(m.ChannelID, "An error occurred while retrieving data.") |
||||||
|
} |
||||||
|
case "upcoming": |
||||||
|
userTerm := "" |
||||||
|
if len(args) >= 3 { |
||||||
|
userTerm = args[2] |
||||||
|
} |
||||||
|
err := upcomingTerm(s, m.ChannelID, userTerm) |
||||||
|
if err != nil { |
||||||
|
fmt.Fprintf(os.Stderr, "Unable to list events: %v\n", err) |
||||||
|
s.ChannelMessageSend(m.ChannelID, "An error occurred while retrieving data.") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func printTug(s *discordgo.Session, channelID string) { |
||||||
|
message := ":eggplant: chaturbate integration coming soon :eggplant:" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
} |
||||||
|
|
||||||
|
func printDev(s *discordgo.Session, channelID string) { |
||||||
|
message := "check out https://gc04.xyz" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
} |
||||||
|
|
||||||
|
func printEpg(s *discordgo.Session, channelID string) { |
||||||
|
message := "Web EPG: https://epg.gc04.xyz" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
} |
||||||
|
|
||||||
|
func printCurrentTimeUTC(s *discordgo.Session, channelID string) { |
||||||
|
currentTime := time.Now().UTC().Format(time.RFC3339) |
||||||
|
message := "Current Time (UTC): " + currentTime |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
} |
||||||
|
|
||||||
|
func guideTerm(s *discordgo.Session, channelID string, userTerm string) error { |
||||||
|
//rows, err := conn.Query(context.Background(), "SELECT sport, event, time_utc, string_agg(channel_name, ', ') AS channels FROM vw_gc04_epg_join_view vgejv WHERE (old_event = 'No') AND (sport = $1 OR event LIKE '%' || $1 || '%' OR league LIKE '%' || $1 || '%') GROUP BY 1, 2, 3 ORDER BY sport, time_utc ASC;", userTerm)
|
||||||
|
//rows, err := conn.Query(context.Background(), "SELECT distinct sport, league, event, time_utc FROM vw_gc04_epg_join_view vgejv WHERE (old_event = 'No') AND (sport = $1 OR event LIKE '%' || $1 || '%' OR league LIKE '%' || $1 || '%') ORDER BY sport, time_utc ASC;", userTerm)
|
||||||
|
rows, err := conn.Query(context.Background(), "SELECT distinct sport, substring(league, 1, 3) as league, event, time_utc FROM vw_gc04_epg_join_view vgejv WHERE (old_event = 'No' and guide = 'Yes') AND (sport = $1 OR event LIKE '%' || $1 || '%' OR league LIKE '%' || $1 || '%') ORDER BY sport, league, time_utc ASC;", userTerm) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
defer rows.Close() |
||||||
|
|
||||||
|
var buffer bytes.Buffer |
||||||
|
writer := tabwriter.NewWriter(&buffer, 0, 0, 3, ' ', tabwriter.Debug) |
||||||
|
fmt.Fprintln(writer, "sport league event Time (UTC)") |
||||||
|
|
||||||
|
for rows.Next() { |
||||||
|
var sport string |
||||||
|
var event string |
||||||
|
var timeUtc string |
||||||
|
var league string |
||||||
|
err := rows.Scan(&sport, &league, &event, &timeUtc) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
fmt.Fprintf(writer, "%s %s %s %s\n", sport, league, event, timeUtc) |
||||||
|
} |
||||||
|
|
||||||
|
writer.Flush() |
||||||
|
|
||||||
|
message := "```\n" + buffer.String() + "```" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
|
||||||
|
return rows.Err() |
||||||
|
} |
||||||
|
|
||||||
|
func whatsonTerm(s *discordgo.Session, channelID string, userTerm string) error { |
||||||
|
rows, err := conn.Query(context.Background(), "SELECT sport, event, time_utc, string_agg(channel_name, ', ') AS channels FROM vw_gc04_epg_join_view vgejv WHERE (old_event = 'No' AND on_air = 'Yes') AND (sport = $1 OR event LIKE '%' || $1 || '%' OR league LIKE '%' || $1 || '%') GROUP BY 1, 2, 3 ORDER BY sport, time_utc ASC;", userTerm) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
defer rows.Close() |
||||||
|
|
||||||
|
var buffer bytes.Buffer |
||||||
|
writer := tabwriter.NewWriter(&buffer, 0, 0, 3, ' ', tabwriter.Debug) |
||||||
|
fmt.Fprintln(writer, "sport Event Time (UTC) Channels") |
||||||
|
|
||||||
|
for rows.Next() { |
||||||
|
var sport string |
||||||
|
var event string |
||||||
|
var timeUtc string |
||||||
|
var channels string |
||||||
|
err := rows.Scan(&sport, &event, &timeUtc, &channels) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
fmt.Fprintf(writer, "%s %s %s \n%s\n\n", sport, event, timeUtc, channels) |
||||||
|
} |
||||||
|
|
||||||
|
writer.Flush() |
||||||
|
|
||||||
|
message := "```\n" + buffer.String() + "```" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
|
||||||
|
return rows.Err() |
||||||
|
} |
||||||
|
|
||||||
|
func upcomingTerm(s *discordgo.Session, channelID string, userTerm string) error { |
||||||
|
rows, err := conn.Query(context.Background(), "SELECT sport, event, time_utc, string_agg(channel_name, ', ') AS channels FROM vw_gc04_epg_join_view vgejv WHERE (old_event = 'No' AND upcoming = 'Yes') AND (sport = $1 OR event LIKE '%' || $1 || '%' OR league LIKE '%' || $1 || '%') GROUP BY 1, 2, 3 ORDER BY sport, time_utc ASC;", userTerm) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
defer rows.Close() |
||||||
|
|
||||||
|
var buffer bytes.Buffer |
||||||
|
writer := tabwriter.NewWriter(&buffer, 0, 0, 3, ' ', tabwriter.Debug) |
||||||
|
fmt.Fprintln(writer, "sport Event Time (UTC) Channels") |
||||||
|
|
||||||
|
for rows.Next() { |
||||||
|
var sport string |
||||||
|
var event string |
||||||
|
var timeUtc string |
||||||
|
var channels string |
||||||
|
err := rows.Scan(&sport, &event, &timeUtc, &channels) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
fmt.Fprintf(writer, "%s %s %s \n%s\n\n", sport, event, timeUtc, channels) |
||||||
|
} |
||||||
|
|
||||||
|
writer.Flush() |
||||||
|
|
||||||
|
message := "```\n" + buffer.String() + "```" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
|
||||||
|
return rows.Err() |
||||||
|
} |
||||||
|
|
||||||
|
func printHelp(s *discordgo.Session, channelID string) { |
||||||
|
message := "```\n" + ` |
||||||
|
Usage: |
||||||
|
sportGPT whatson <term> : shows currently airing events
|
||||||
|
sportGPT guide <term> : shows all upcoming events (24 hours) |
||||||
|
sportGPT upcoming <term> : shows all upcoming events (4 hours) |
||||||
|
sportGPT epg : link to web-based full epg. useful to find unlisted events.
|
||||||
|
sportGPT utc : shows current time UTC |
||||||
|
sportGPT tug : td |
||||||
|
sportGPT help : shows this help text |
||||||
|
|
||||||
|
` + "```\n" |
||||||
|
s.ChannelMessageSend(channelID, message) |
||||||
|
} |
||||||
|
|
Loading…
Reference in new issue