Compare commits

...

13 Commits

  1. 1
      .gitignore
  2. 2
      Dockerfile
  3. 23
      bot.go
  4. 6
      go.mod
  5. 15
      go.sum

1
.gitignore vendored

@ -0,0 +1 @@ @@ -0,0 +1 @@
.idea/

2
Dockerfile

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
FROM golang:1.11-alpine3.7 AS build-env
FROM golang:1.12-alpine AS build-env
COPY . ${GOPATH}/src/git.jonasfranz.software/JonasFranzDEV/mensabot
WORKDIR ${GOPATH}/src/git.jonasfranz.software/JonasFranzDEV/mensabot

23
bot.go

@ -2,14 +2,13 @@ package main @@ -2,14 +2,13 @@ package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/kiliankoe/openmensa"
"os"
"os/signal"
"strings"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
"github.com/kiliankoe/openmensa"
)
var (
@ -32,13 +31,19 @@ var ( @@ -32,13 +31,19 @@ var (
func main() {
token := os.Getenv("MENSABOT_TOKEN")
if len(token) == 0 || token == "token" {
println("Please add token as environment variable: MENSABOT_TOKEN.")
if (len(token) == 0 || token == "token") && len(os.Args) <= 0 {
fmt.Println("Please add token as environment variable (MENSABOT_TOKEN) or cli argument.")
return
}
if len(os.Args) > 1 {
token = os.Args[1]
}
dg, err := discordgo.New(fmt.Sprintf("Bot %s", token))
if err != nil {
fmt.Println("error creating dicord bot: ", err)
fmt.Println("error creating discord bot: ", err)
return
}
canteens, err := openmensa.GetCanteens(175)
if err != nil {
@ -90,6 +95,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) { @@ -90,6 +95,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) {
meals, err := canteen.GetMeals(t)
if err != nil {
s.ChannelMessageSend(channel, ":angry: an error occured")
fmt.Println("an error occured while getting the meals: ", err)
return
}
var messages = make([]*discordgo.MessageEmbedField, len(meals))
@ -119,7 +125,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) { @@ -119,7 +125,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) {
footer += fmt.Sprintf("[%d] %s\n", i+1, strings.Join(meal.Notes, ", "))
}
}
s.ChannelMessageSendComplex(channel, &discordgo.MessageSend{
_, err = s.ChannelMessageSendComplex(channel, &discordgo.MessageSend{
Embed: &discordgo.MessageEmbed{
Title: fmt.Sprintf("**Menü vom %s**", t.Format("02.01.2006")),
Fields: messages,
@ -129,4 +135,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) { @@ -129,4 +135,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) {
},
},
})
if err != nil {
fmt.Println("an error occured while sending the meals: ", err)
}
}

6
go.mod

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
module git.jonasfranz.software/mensabot
require (
github.com/bwmarrin/discordgo v0.18.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/bwmarrin/discordgo v0.19.0
github.com/kiliankoe/openmensa v0.0.0-20160914233745-a68c3aca59c0
golang.org/x/crypto v0.0.0-20181025213731-e84da0312774 // indirect
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a // indirect
golang.org/x/sys v0.0.0-20190411185658-b44545bcd369 // indirect
)

15
go.sum

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
github.com/bwmarrin/discordgo v0.18.0 h1:XopVQXCIFy7Cr2eT7NcYcm4k0l2PYX+AP5RUbIWX2/8=
github.com/bwmarrin/discordgo v0.18.0/go.mod h1:5NIvFv5Z7HddYuXbuQegZ684DleQaCFqChP2iuBivJ8=
github.com/bwmarrin/discordgo v0.19.0 h1:kMED/DB0NR1QhRcalb85w0Cu3Ep2OrGAqZH1R5awQiY=
github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/kiliankoe/openmensa v0.0.0-20160914233745-a68c3aca59c0 h1:nqLa9Sn5qo4CvsPxTyvWZ6XkmUowbszZPJdW0U+O2O4=
github.com/kiliankoe/openmensa v0.0.0-20160914233745-a68c3aca59c0/go.mod h1:WAZWjpFB1pagPLV6awqMVlcG57PxYbAHPRsPpf60LHw=
golang.org/x/crypto v0.0.0-20181025213731-e84da0312774 h1:a4tQYYYuK9QdeO/+kEvNYyuR21S+7ve5EANok6hABhI=
golang.org/x/crypto v0.0.0-20181025213731-e84da0312774/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a h1:Igim7XhdOpBnWPuYJ70XcNpq8q3BCACtVgNfoJxOV7g=
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Loading…
Cancel
Save