mastodon bot fix

This commit is contained in:
lesion 2019-07-08 00:06:56 +02:00
parent cd44051a48
commit 506cf56e11
5 changed files with 26 additions and 32 deletions

View file

@ -28,6 +28,20 @@ import Calendar from '@/components/Calendar'
export default {
name: 'Home',
head () {
console.error(this.settings)
return {
title: this.settings.title,
meta: [
// hid is used as unique identifier. Do not use `vmid` for it as it will not work
{ hid: 'description', name: 'description', content: this.settings.description },
{ hid: 'og-description', name: 'og:description', content: this.settings.description },
{ hid: 'og-title', property: 'og:title', content: this.settings.title },
{ hid: 'og-url', property: 'og:url', content: this.settings.baseurl },
// { property: 'og:image', content: this.settings.baseurl }
]
}
},
data () {
return { }
},

View file

@ -37,6 +37,7 @@
span(slot='label') {{$t('common.when')}} <v-icon name='clock'/>
span {{event.multidate ? $t('event.dates_description') : $t('event.date_description')}}
el-switch.float-right(v-model='event.multidate' :active-text="$t('event.multidate_description')")
//- el-switch.float-right(v-model='event.recurrent' :active-text="$t('event.recurrent_description')")
v-date-picker.mb-3(
:mode='event.multidate ? "range" : "single"'

View file

@ -20,41 +20,21 @@ const botController = {
const listener = botController.bot.stream('/streaming/user')
listener.on('message', botController.message)
listener.on('error', botController.error)
// const botUsers = await User.findAll({ where: { mastodon_auth: { [Op.ne]: null } } })
// console.log(botUsers)
// botController.bots = botUsers.map(user => {
// console.log('initialize bot ', user.name)
// console.log('.. ', user.mastodon_auth)
// const { client_id, client_secret, access_token } = user.mastodon_auth
// const bot = new Mastodon({ access_token, api_url: `https://${user.mastodon_instance}/api/v1/` })
// const listener = bot.stream('streaming/direct')
// listener.on('message', botController.message)
// return { email: user.email, bot }
// })
// console.log(botController.bots)
// },
// add (user, token) {
// const bot = new Mastodon({ access_token: user.mastodon_auth.access_token, api_url: `https://${user.mastodon_instance}/api/v1/` })
// const listener = bot.stream('streaming/direct')
// listener.on('message', botController.message)
// listener.on('error', botController.error)
// botController.bots.push({ email: user.email, bot })
},
async post(instance, access_token, event) {
async post(event) {
const status = `${event.title} @${event.place.name} ${moment(event.start_datetime*1000).format('ddd, D MMMM HH:mm')} -
${event.description.length > 200 ? event.description.substr(0, 200) + '...' : event.description} - ${event.tags.map(t => '#' + t.tag).join(' ')} ${config.baseurl}/event/${event.id}`
let media
if (event.image_path) {
const file = path.join(config.upload_path, event.image_path)
const file = path.resolve(config.upload_path, event.image_path)
if (fs.statSync(file)) {
media = await botController.bot.post('media', { file: fs.createReadStream(file) })
media = await botController.bot.post('/media', { file: fs.createReadStream(file) })
}
}
return botController.bot.post('/statuses', { status, media_ids: media ? [media.data.id] : [] })
},
// TOFIX: enable message deletion
async message(msg) {
const type = msg.event
@ -66,7 +46,6 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
}
const activitypub_id = String(msg.data.status.in_reply_to_id)
console.error('il toot di reply ', activitypub_id)
if (!activitypub_id) return
let event = await Event.findOne({ where: { activitypub_id } })
if (!event) {

View file

@ -47,7 +47,9 @@ const settingsController = {
// get public settings and public configuration
const settings = {
...settingsController.settings,
baseurl: config.baseurl
baseurl: config.baseurl,
title: config.title,
description: config.description
}
res.json(settings)
},

View file

@ -10,8 +10,6 @@ const { event: Event, notification: Notification, event_notification: EventNoti
const notifier = {
async sendNotification(notification, event) {
const access_token = get(settingsController.secretSettings, 'mastodon_auth.access_token')
const instance = get(settingsController.settings, 'mastodon_instance')
const promises = []
switch (notification.type) {
case 'mail':
@ -19,11 +17,11 @@ const notifier = {
case 'admin_email':
return mail.send([config.smtp.auth.user, config.admin_email], 'event', { event, to_confirm: !event.is_visible, config, notification })
case 'mastodon':
console.error('mando le cose')
// instance publish
if (instance && access_token) {
const b = bot.post(instance, access_token, event).then(b => {
console.error(b)
event.activitypub_id = b.data.id
if (bot.bot) {
const b = bot.post(event).then(b => {
event.activitypub_id = String(b.data.id)
return event.save()
}).catch(e => {
console.error("ERRORE !! ", e)
@ -55,7 +53,7 @@ const notifier = {
await notifier.sendNotification(notification, event)
e.status = 'sent'
} catch (err) {
console.error(err)
// console.error(err)
e.status = 'error'
// e.error = err
}