Skip to content

Commit

Permalink
feat: update on study-website-stalker updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo committed Oct 2, 2021
1 parent 3b312a8 commit 6ca52ca
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 105 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ additionalEvents
eventfiles
meals
mensa-data
tmp
userconfig
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ additionalEvents
eventfiles
meals
mensa-data
tmp
userconfig
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ RUN apk upgrade --no-cache \
&& apk --no-cache add git

WORKDIR /app
EXPOSE 3000
VOLUME /app/eventfiles
VOLUME /app/mensa-data
VOLUME /app/tmp
VOLUME /app/userconfig

COPY package.json ./
Expand Down
3 changes: 1 addition & 2 deletions init-debug-environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
set -e

# assumes downloader was cloned and executed
ln -rfs ../downloader/eventfiles
ln -rfs ../downloader/eventfiles .

mkdir -p tmp
mkdir -p userconfig
11 changes: 11 additions & 0 deletions locales/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ subscribe:
Viel Erfolg 😎
website-stalker:
help: >
Der website-stalker prüft regelmäßig auf Änderungen an relevanten Webseiten.
Hier wird beispielsweise StISys auf Änderungen betrachtet und wenn sich etwas ändert, kannst du direkt benachrichtigt werden.
Alternativ kannst du die Änderungen auch als RSS Feed mit deinem Feed Reader abonnieren.
Abonniere dazu folgende URL:
https://github.com/HAWHHCalendarBot/study-website-stalker/commits/main.atom
124 changes: 116 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@grammyjs/i18n": "^0.3.0",
"@grammyjs/stateless-question": "^3.0.0",
"@octokit/webhooks": "^9.15.0",
"array-filter-unique": "^2.1.0",
"got": "^11.5.2",
"grammy": "^1.3.3",
Expand All @@ -36,6 +37,7 @@
"telegram-format": "^2.0.1"
},
"devDependencies": {
"@octokit/webhooks-types": "^4.8.2",
"@sindresorhus/tsconfig": "^2.0.0",
"@types/json-stable-stringify": "^1.0.32",
"@types/node": "^16.9.6",
Expand Down
38 changes: 11 additions & 27 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {I18n} from '@grammyjs/i18n'
import {Bot, session} from 'grammy'

import {Chatconfig} from './lib/chatconfig.js'
import {hasStISysChanged} from './lib/has-stisys-changed.js'
import {MyContext, Session} from './lib/types.js'
import {startListenWebsiteStalkerWebhook} from './lib/study-website-stalker.js'

import {bot as migrateStuffBot} from './migrate-stuff.js'

Expand Down Expand Up @@ -81,29 +81,6 @@ bot.use(easterEggs.bot)

bot.use(menu)

async function checkStISysChangeAndNotify() {
try {
const hasChanged = await hasStISysChanged()
if (!hasChanged) {
return
}

const text = 'Es hat sich eine Änderung auf der [StISys Einstiegsseite](https://stisys.haw-hamburg.de) ergeben.'

await chatconfig.broadcast(
bot.api,
text,
{
parse_mode: 'Markdown',
reply_markup: {remove_keyboard: true},
},
user => Boolean(user.config.stisysUpdate),
)
} catch (error: unknown) {
console.error('checkStISysChangeAndNotify failed', error)
}
}

bot.catch((error: any) => {
// Should not occur as the error middleware is in place
console.error('grammY Error', error)
Expand All @@ -116,9 +93,16 @@ async function startup() {
{command: 'settings', description: 'setze Einstellungen des Bots'},
])

setInterval(checkStISysChangeAndNotify, 15 * 60 * 1000)
console.log(new Date(), 'Initial StISys check...')
await checkStISysChangeAndNotify()
startListenWebsiteStalkerWebhook(async text => {
await chatconfig.broadcast(
bot.api,
text,
{
reply_markup: {remove_keyboard: true},
},
user => Boolean(user.config.websiteStalkerUpdate) || Boolean(user.config.stisysUpdate),
)
})

await bot.start({
onStart: botInfo => {
Expand Down
52 changes: 0 additions & 52 deletions source/lib/has-stisys-changed.ts

This file was deleted.

Loading

0 comments on commit 6ca52ca

Please sign in to comment.