Skip to content

Commit

Permalink
bugfixes 🐛
Browse files Browse the repository at this point in the history
fixes #5
  • Loading branch information
derhuerst committed Feb 15, 2018
1 parent b8eb6d3 commit 3362b05
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
21 changes: 19 additions & 2 deletions commands/departures.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
const time = require('parse-messy-time')
const search = require('vbb-stations-autocomplete')
const getStations = require('vbb-stations')
const splitLines = require('split-lines')

const api = require('../lib/api')
const render = require('../lib/render')
const frequent = require('../lib/frequent')


// https://core.telegram.org/method/messages.sendMessage#return-errors
const SIZE_LIMIT = 4096

const unknownStation = `\
I don't know about this station, please double-check for typos.
Expand Down Expand Up @@ -44,7 +46,22 @@ const when = async (ctx, tmp, freq, msg) => {

ctx.typing()
const deps = await api.deps(station.id, when)
await ctx.keyboard(render.deps(station, deps), ctx.commands)
let rendered = render.deps(station, deps)
// This is a terrible fix.
// - It makes assumptions about how the rendered response looks.
// - It assumes that half of the message won't be too long.
// todo: properly fix this
if (rendered.length >= SIZE_LIMIT) {
rendered = splitLines(rendered)
const splitI = Math.ceil(rendered.length / 2)
const firstPart = rendered.slice(0, splitI).join('\n') + '\n```'
const secondPart = '```\n' + rendered.slice(splitI).join('\n')

await ctx.message(firstPart, ctx.commands)
await ctx.keyboard(secondPart, ctx.commands)
} else {
await ctx.keyboard(rendered, ctx.commands)
}
}


Expand Down
4 changes: 3 additions & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ if (!TIMEZONE) {
}

const relative = (when) => {
if (when === null) return '?'

// todo: timezone
const now = new Date()
const now = new Date()
if (new Date(when).getDate() !== now.getDate()) {
return moment(when).locale('de').format('dd, LT')
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"node-telegram-bot-api": "^0.30.0",
"parse-messy-time": "^2.1",
"shorthash": "^0.0.2",
"split-lines": "^1.1.0",
"vbb-client": "^3.0.1",
"vbb-lines-at": "^3.2.0",
"vbb-stations": "^6.2.1",
Expand Down

0 comments on commit 3362b05

Please sign in to comment.