Skip to content
This repository was archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Added support for scheduled messages (#61)
Browse files Browse the repository at this point in the history
* Added support for scheduled messages
  • Loading branch information
FrederikBolding authored Jul 11, 2019
1 parent 109dc56 commit 6b4bd1b
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 1 deletion.
14 changes: 13 additions & 1 deletion chatbot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const ical = require('node-ical')
const markdown = require('markdown').markdown
var moment = require('moment-timezone')
var moment = require('moment')
require('moment-timezone')
require('moment-recur')
let privateRooms = {}

const {
Expand All @@ -11,8 +13,18 @@ const {
hashtagMappings,
calendarURL,
calendarUpperLimitInMonths,
scheduledMessages,
} = require('./constants')

exports.handleScheduledMessages = function(client) {
let now = moment.utc()
scheduledMessages.forEach(message => {
if (message.when.matches(now)) {
sendMessage(message.message, '', client, message.room)
}
})
}

exports.handleCalendar = function(event, room, toStartOfTimeline, client) {
if (event.getType() === 'm.room.message' && toStartOfTimeline === false) {
let message = event.getContent().body
Expand Down
104 changes: 104 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var moment = require('moment')
require('moment-recur')

// Allowed users that can dish out points
// module.exports.userList = [
// ]
Expand Down Expand Up @@ -56,6 +59,107 @@ module.exports.calendarUpperLimitInMonths = 2
module.exports.positiveResponses = ['yes', 'yup', 'yea']
module.exports.negativeResponses = ['no']

module.exports.scheduledMessages = [
// CONTRIBUTORS
{
room: '!OQTaDMKEJXLvTpYoCe:matrix.org',
message:
'# Hi Contributors!\
If you would like cash in hand (well, crypto in wallet) by the end of the month for work you\'ve done, **GET YOUR MILESTONES UP NOW**!\
- propose your milestones by the 10th\
- pester your campaign mgr to accept them swiftly! 😜\
- make sure that some Unicorns ( @geleeroyale , @krrisis , @loie , @danibelle , @griffgreen, @misterboyfriend @planski ) are aware of/amplifying your work. You are always welcome to message us. 🤗\
- hit disburse on "My Milestones" as soon as you\'re able\
## If you do all this, then you have the best shot of the funds being in your wallet 5 days after the third Monday of the month.\
\
Thank you so much for being here 💖Any questions, dm! -Loie',
when: moment
.recur()
.every(7)
.daysOfMonth(),
},

{
room: '!OQTaDMKEJXLvTpYoCe:matrix.org',
message:
'# Hi Contributors!\
If you would like cash in hand (well, crypto in wallet) by the end of the month for work you\'ve done, **GET YOUR MILESTONES UP NOW**!\
- propose your milestones by the 10th\
- pester your campaign mgr to accept them swiftly! 😜\
- make sure that some Unicorns ( @geleeroyale , @krrisis , @loie , @danibelle , @griffgreen, @misterboyfriend @planski ) are aware of/amplifying your work. You are always welcome to message us. 🤗\
- hit disburse on "My Milestones" as soon as you\'re able\
## If you do all this, then you have the best shot of the funds being in your wallet 5 days after the first Monday of next month..\
\
Thank you so much for being here 💖Any questions, dm! -Loie',
when: moment
.recur()
.every(22)
.daysOfMonth(),
},

// UNICORN ROOM
{
room: '!VUpIHOCgPdHvUrtwXq:matrix.org',
message:
'# Hi Givethers!\
If you would like cash in hand (well, crypto in wallet) by the end of the month for work you\'ve done, **GET YOUR MILESTONES UP NOW**!\
- propose your milestones by the 10th\
- pester your campaign mgr to accept them swiftly! 😜\
- make sure that some Unicorns ( @geleeroyale , @krrisis , @loie , @danibelle , @griffgreen, @misterboyfriend @planski ) are aware of/amplifying your work. You are always welcome to message us. 🤗\
- hit disburse on "My Milestones" as soon as you\'re able\
## If you do all this, then you have the best shot of the funds being in your wallet 5 days after the third Monday of the month.\
\
Thank you so much for being here 💖Any questions, dm! -Loie',
when: moment
.recur()
.every(7)
.daysOfMonth(),
},

{
room: '!VUpIHOCgPdHvUrtwXq:matrix.org',
message:
'# Hi Givethers!\
If you would like cash in hand (well, crypto in wallet) by the end of the month for work you\'ve done, **GET YOUR MILESTONES UP NOW**!\
- propose your milestones by the 10th\
- pester your campaign mgr to accept them swiftly! 😜\
- make sure that some Unicorns ( @geleeroyale , @krrisis , @loie , @danibelle , @griffgreen, @misterboyfriend @planski ) are aware of/amplifying your work. You are always welcome to message us. 🤗\
- hit disburse on "My Milestones" as soon as you\'re able\
## If you do all this, then you have the best shot of the funds being in your wallet 5 days after the first Monday of next month..\
\
Thank you so much for being here 💖Any questions, dm! -Loie',
when: moment
.recur()
.every(22)
.daysOfMonth(),
},

// UNICORN DAC ROOM
{
room: '!rhEMPQvVgOkuPQtRdq:matrix.org',
message:
'The milestones are up! The sheet is ready! # Time to CHOOSE THE MILESTONES you want to fund this round!\
As you know, I delegate on the first Monday of the month. So please make sure all your delegations (for any weeks between the third monday of last month and the first one of this month) are \
## in the sheet on Sunday💫🗓 💥',
when: moment
.recur()
.every(10)
.daysOfMonth(),
},
{
room: '!rhEMPQvVgOkuPQtRdq:matrix.org',
message:
'The milestones are up! The sheet is ready! \
# Time to CHOOSE THE MILESTONES you want to fund this round!\
As you know, I delegate on the third Monday of the month. So please make sure all your delegations (for weeks between the first monday and third monday of this month) are \
## in the sheet on Sunday💫🗓 💥',
when: moment
.recur()
.every(25)
.daysOfMonth(),
},
]

module.exports.messages = {
// SOCIAL CODING
'!kUeYRcrXObgGoJlFjn:matrix.org': {
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { google } = require('googleapis')
const sdk = require('matrix-js-sdk')
const pointsBot = require('./pointsbot.js')
const chatBot = require('./chatbot.js')
var cron = require('node-cron')
let privateRooms = {}

// If modifying these scopes, delete credentials.json.
Expand Down Expand Up @@ -132,6 +133,16 @@ function authenticated(auth) {
})

client.startClient(0)

cron.schedule(
'1 0 * * *',
() => {
chatBot.handleScheduledMessages(client)
},
{
timezone: 'Etc/UTC',
}
)
}
)
})
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"googleapis": "^30.0.0",
"markdown": "^0.5.0",
"matrix-js-sdk": "^0.10.2",
"moment": "^2.24.0",
"moment-recur": "^1.0.7",
"node-cron": "^2.0.3",
"node-ical": "^0.9.2"
},
"devDependencies": {
Expand Down

0 comments on commit 6b4bd1b

Please sign in to comment.