This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsend_announcement.js
73 lines (59 loc) · 2.92 KB
/
send_announcement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*jslint node: true */
"use strict";
var async = require('async');
var db = require('ocore/db.js');
var eventBus = require('ocore/event_bus.js');
var headlessWallet = require('headless-obyte');
//const announcement = "At Byteball, we're greatful for your contribution to science and healthcare. But did you know you could earn additional 10% of Bytes by joining the Byteball.org team? Join here https://www.worldcommunitygrid.org/team/viewTeamInfo.do?teamId=R1RD1XTFK92 and help us win the THOR Challenge by contributing more run time to the team, currently we are 2nd https://www.worldcommunitygrid.org/about_us/viewNewsArticle.do?articleId=574";
const announcement = `Dear WCG cruncher,
First of all we want to wish you Happy Holidays with your friends and family!
Last time we wrote you about diminishing returns for more than 40 connected devices. This measure alone has proven to be ineffective. Unfortunately we are going to have to change the rules a second time.
Again, WCG rewards are meant for new users to be able to discover Byteball by donating some spare CPU power to a good cause, not to make money.
For now we are going to reduce the reward to $1 per 1,000,000 WCG points earned, effective from Monday December 24 on. This way the method will still work like a faucet but it will be much harder to make a profit, which was never intended. We’ll monitor what this change does and make further changes when necessary.
Happy crunching :)
The Byteball Team
`;
//const optout_text = "\n\nIf you don't want to receive news here, [click here to opt out](command:optout).";
const message = announcement;// + optout_text;
headlessWallet.setupChatEventHandlers();
function sendAnnouncement(){
var device = require('ocore/device.js');
db.query(
"SELECT device_address FROM users",
rows => {
console.error(rows.length+" messages will be sent");
async.eachSeries(
rows,
(row, cb) => {
device.sendMessageToDevice(row.device_address, 'text', message, {
ifOk: function(){},
ifError: function(){},
onSaved: function(){
console.log("sent to "+row.device_address);
cb();
}
});
},
() => {
console.error("=== done");
}
);
}
);
}
eventBus.on('text', function(from_address, text){
var device = require('ocore/device.js');
console.log('text from '+from_address+': '+text);
text = text.trim().toLowerCase();
/*if (text === 'optout'){
db.query("INSERT "+db.getIgnore()+" INTO optouts (device_address) VALUES(?)", [from_address]);
return device.sendMessageToDevice(from_address, 'text', 'You are unsubscribed from future announcements.');
}
else */if (text.match(/thank/))
device.sendMessageToDevice(from_address, 'text', "You're welcome!");
else
device.sendMessageToDevice(from_address, 'text', "Usual operations are paused while sending announcements. Check again in a few minutes.");
});
eventBus.on('headless_wallet_ready', () => {
setTimeout(sendAnnouncement, 1000);
});