mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-13 16:26:50 +00:00
Add Telegram group members count to meetups
This commit is contained in:
@@ -8,7 +8,6 @@ const episodes = require('../generated/episodes.json')
|
||||
const spendenregister = require('../generated/spendenregister.json')
|
||||
const spendenuebersicht = require('../content/spendenuebersicht.json')
|
||||
const team = require('../content/team.json')
|
||||
const meetups = require('../content/meetups.json')
|
||||
const telegram = require('../content/telegram.json')
|
||||
const shops = require('../content/shops.json')
|
||||
const soundboard = require('../content/soundboard.json')
|
||||
@@ -27,7 +26,7 @@ const renderPage = (template, out, data = {}) => {
|
||||
}
|
||||
|
||||
const sortId = m => `${m.country === 'DE' ? '0' : m.country}-${m.name}`
|
||||
const meetupsSorted = meetups.sort((a, b) => {
|
||||
const meetupsSorted = site.meetups.sort((a, b) => {
|
||||
return sortId(a) > sortId(b) ? 1 : -1
|
||||
})
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ const meta = require('../content/meta.json')
|
||||
const meetups = require('../content/meetups.json')
|
||||
const soundboard = require('../content/soundboard.json')
|
||||
|
||||
const { TELEGRAM_BOT_TOKEN } = process.env
|
||||
|
||||
const dir = (...path) => resolve(__dirname, '..', ...path)
|
||||
const writeJSON = (file, data) => writeFileSync(file, JSON.stringify(data, null, 2))
|
||||
|
||||
@@ -20,18 +22,43 @@ try {
|
||||
const block = recentBlocks.length && recentBlocks[0].height
|
||||
const date = (new Date()).toJSON().split('T')[0]
|
||||
|
||||
writeJSON(dir('generated', 'site-data.json'), { date, block, meta })
|
||||
|
||||
// Meetups
|
||||
const meetup = meetups.map(m => {
|
||||
const copy = Object.assign({}, m)
|
||||
delete copy.top
|
||||
delete copy.left
|
||||
|
||||
if (TELEGRAM_BOT_TOKEN) {
|
||||
let { telegramId } = m
|
||||
if (!telegramId && m.url.startsWith('https://t.me/')) {
|
||||
[,, telegramId] = m.url.match(/:\/\/t\.me\/(?!(\+|joinchat))(.*)/) || []
|
||||
if (telegramId) {
|
||||
try {
|
||||
const jsonBody = request(
|
||||
'GET',
|
||||
`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/getChatMemberCount?chat_id=@${telegramId}`
|
||||
).getBody('utf8')
|
||||
const { ok, result } = JSON.parse(jsonBody)
|
||||
if (ok) {
|
||||
copy.telegramId = telegramId
|
||||
copy.members = result
|
||||
}
|
||||
} catch (err) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return copy
|
||||
})
|
||||
|
||||
writeJSON(dir('dist', 'meetups.json'), meetup)
|
||||
|
||||
writeJSON(dir('generated', 'site-data.json'), {
|
||||
date,
|
||||
block,
|
||||
meta,
|
||||
meetups: meetup,
|
||||
})
|
||||
|
||||
// Soundboard
|
||||
const sounds = soundboard.map(group => {
|
||||
group.sounds = group.sounds.map(sound => {
|
||||
|
||||
Reference in New Issue
Block a user