Skip to content

Commit

Permalink
feat(data): split up into 3 sections
Browse files Browse the repository at this point in the history
allows for more data until the message is too long
  • Loading branch information
EdJoPaTo committed Mar 6, 2023
1 parent 3d6e5c7 commit e44e0fb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
12 changes: 12 additions & 0 deletions locales/de.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ website-stalker-help =
Alternativ kannst du die Änderungen auch als RSS-Feed mit deinem Feedreader abonnieren. Abonniere dazu folgende URL: https://github.com/HAWHHCalendarBot/study-website-stalker/commits/main.atom
privacy-overview =
Auf dem Server wird geloggt, wenn Aktionen von Nutzern zu einem neu Bauen von Kalendern oder ungewollten Fehlern führen. Diese Logs werden nicht persistent gespeichert und sind nur bis zum Neustart des Servers verfügbar.
Der Quellcode dieses Bots ist auf <a href="https://github.com/HAWHHCalendarBot">GitHub</a> verfügbar.
privacy-telegram =
Jeder Telegram Bot kann diese User Infos abrufen, wenn du mit ihm interagierst. Um dies zu verhindern, blockiere den Bot.
privacy-persistent =
Damit dein Kalender generiert oder deine Mensa Einstellungen gespeichert werden können, werden einige Daten persistent auf dem Server hinterlegt. Wenn du alle Daten über dich löschen lassen möchtest, wähle "Alles löschen".
privacy-tmp =
Diese Daten werden nur temporär gehalten und sind nur bis zum Neustart des Servers im RAM hinterlegt.
subscribe-overview =
<b>Kalender abonnieren</b>
Expand Down
1 change: 1 addition & 0 deletions source/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Session = {
eventfilter?: string;
generateChange?: Partial<Change>;
page?: number;
privacySection?: 'telegram' | 'persistent' | 'tmp';
mensa?: {
mensa?: string;
date?: number;
Expand Down
63 changes: 32 additions & 31 deletions source/menu/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,38 @@ async function getActualUserconfigContent(
return userconfig?.config
}

async function menuBody(context: MyContext): Promise<Body> {
const github = format.url('GitHub', 'https://github.com/HAWHHCalendarBot')

let text = ''
const PRIVACY_SECTIONS = {
telegram: 'Telegram',
persistent: 'Persistent',
tmp: 'Temporär',
}
type PrivacySection = keyof typeof PRIVACY_SECTIONS

text += '\nAuf dem Server wird geloggt, wenn Aktionen von Nutzern zu einem neu Bauen von Kalendern oder ungewollten Fehlern führen. Diese Logs werden nicht persistent gespeichert und sind nur bis zum Neustart des Servers verfügbar.'
text += `\nDer Quellcode dieses Bots ist auf ${github} verfügbar.`
text += '\n'
text += '\nDie folgenden Daten werden auf dem Server über dich gespeichert. Wenn du alle Daten über dich löschen lassen möchtest, wähle "Alles löschen".'
async function menuBody(context: MyContext): Promise<Body> {
const part = privacyInfoPart(context, context.session.privacySection ?? 'persistent')

let text = context.t('privacy-overview')
text += '\n\n'
text += format.bold('Telegram User Info')
text += format.bold(part.title)
text += '\n'
text += 'Jeder Telegram Bot kann diese User Infos abrufen, wenn du mit ihm interagierst.'
text += ' Um dies zu verhindern, blockiere den Bot.'
text += part.text
text += '\n'
text += format.monospaceBlock(JSON.stringify(context.from, null, 2), 'json')
text += format.monospaceBlock(JSON.stringify(part.data, null, 1), 'json')

text += '\n\n'
text += format.bold('Persistente Einstellungen im Bot')
text += '\n'
text += 'Damit dein Kalender generiert oder deine Mensa Einstellungen gespeichert werden können, werden einige Daten persistent auf dem Server hinterlegt.'
text += '\n'
text += format.monospaceBlock(
JSON.stringify(context.userconfig.mine, null, 2),
'json',
)
return {text, parse_mode: format.parse_mode, disable_web_page_preview: true}
}

text += '\n\n'
text += format.bold('Temporäre Daten des Bots')
text += '\n'
text += 'Diese Daten werden nur temporär gehalten und sind nur bis zum Neustart des Servers im RAM hinterlegt.'
text += '\n'
text += format.monospaceBlock(
JSON.stringify(context.session, null, 2),
'json',
)
function privacyInfoPart(ctx: MyContext, section: PrivacySection) {
const text = ctx.t('privacy-' + section)
if (section === 'telegram') {
return {text, title: 'Telegram User Info', data: ctx.from}
}

return {text, parse_mode: format.parse_mode}
if (section === 'persistent') {
return {text, title: 'Persistente Einstellungen im Bot', data: ctx.userconfig.mine}
}

return {text, title: 'Temporäre Daten des Bots', data: ctx.session}
}

const deleteConfirmString = 'Ja, ich will!'
Expand All @@ -64,6 +57,14 @@ const deleteQuestion = `Bist du dir sicher, das du deinen Kalender und alle Eins
export const bot = new Composer<MyContext>()
export const menu = new MenuTemplate<MyContext>(menuBody)

menu.select('section', PRIVACY_SECTIONS, {
isSet: (ctx, key) => (ctx.session.privacySection ?? 'persistent') === key,
set(ctx, key) {
ctx.session.privacySection = key as PrivacySection
return true
},
})

menu.url('🦑 Quellcode', 'https://github.com/HAWHHCalendarBot')

const deleteAllQuestion = new StatelessQuestion<MyContext>('delete-everything', async (context, path) => {
Expand Down

0 comments on commit e44e0fb

Please sign in to comment.