Skip to content

Commit e15a1e6

Browse files
author
Christian Maniewski
committed
Apply prettier fixes
1 parent 833b675 commit e15a1e6

10 files changed

+336
-296
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"start": "env-cmd .env yarn run hubot --name chewie -a slack",
99
"dev": "env-cmd .env yarn run hubot --name chewie",
10-
"fix": "prettier 'scripts/**/*.js' --write"
10+
"format": "prettier 'scripts/**/*.js' --write"
1111
},
1212
"dependencies": {
1313
"@colony/colony-contract-loader-network": "^1.0.1",

scripts/colony-stats.js

+54-43
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99

1010
const { providers, Wallet } = require('ethers')
1111
const { default: EthersAdapter } = require('@colony/colony-js-adapter-ethers')
12-
const { default: NetworkLoader } = require('@colony/colony-contract-loader-network')
12+
const {
13+
default: NetworkLoader
14+
} = require('@colony/colony-contract-loader-network')
1315
const { default: ColonyNetworkClient } = require('@colony/colony-js-client')
1416

15-
module.exports = async (robot) => {
17+
module.exports = async robot => {
1618
const network = 'rinkeby'
17-
const privateKey = process.env.HUBOT_ETHEREUM_PRIVATE_KEY || '0x0123456789012345678901234567890123456789012345678901234567890123'
19+
const privateKey =
20+
process.env.HUBOT_ETHEREUM_PRIVATE_KEY ||
21+
'0x0123456789012345678901234567890123456789012345678901234567890123'
1822

1923
const loader = new NetworkLoader({ network })
2024
const provider = new providers.EtherscanProvider(network)
@@ -23,7 +27,7 @@ module.exports = async (robot) => {
2327
const adapter = new EthersAdapter({
2428
loader,
2529
provider,
26-
wallet,
30+
wallet
2731
})
2832

2933
const networkClient = new ColonyNetworkClient({ adapter })
@@ -32,72 +36,79 @@ module.exports = async (robot) => {
3236
const metaColonyClient = await networkClient.getMetaColonyClient()
3337

3438
robot.hear(/!colony ([0-9]*)$/i, async msg => {
35-
msg.send('Gathering data...');
36-
const { address } = await networkClient.getColony.call({ id: parseInt(msg.match[1], 10) })
39+
msg.send('Gathering data...')
40+
const { address } = await networkClient.getColony.call({
41+
id: parseInt(msg.match[1], 10)
42+
})
3743
if (!address) {
38-
return msg.send("No such colony");
44+
return msg.send('No such colony')
3945
}
4046
const colonyClient = await networkClient.getColonyClientByAddress(address)
41-
const { count } = await colonyClient.getTaskCount.call();
42-
let res = await colonyClient.getToken.call();
43-
const tokenAddress = res.address;
44-
let tokenName;
45-
let tokenSymbol;
47+
const { count } = await colonyClient.getTaskCount.call()
48+
let res = await colonyClient.getToken.call()
49+
const tokenAddress = res.address
50+
let tokenName
51+
let tokenSymbol
4652
try {
47-
res = await colonyClient.token.getTokenInfo.call();
48-
tokenName = res.name;
49-
tokenSymbol = res.symbol;
50-
} catch (err){
53+
res = await colonyClient.token.getTokenInfo.call()
54+
tokenName = res.name
55+
tokenSymbol = res.symbol
56+
} catch (err) {
5157
// No such properties on the token - possible if not ERC20 compliant, as BYOT allows
5258
}
5359

54-
msg.send(`Address: ${address} \nTask count: ${count}\nToken Address: ${tokenAddress}\nToken Name: ${tokenName} (${tokenSymbol})`)
60+
msg.send(
61+
`Address: ${address} \nTask count: ${count}\nToken Address: ${tokenAddress}\nToken Name: ${tokenName} (${tokenSymbol})`
62+
)
5563
})
5664

57-
5865
robot.hear(/!colony ([0-9]*) task ([0-9]*)$/i, async msg => {
5966
msg.send('Gathering data...')
60-
const { address } = await networkClient.getColony.call({ id: parseInt(msg.match[1], 10) })
61-
const taskId = parseInt(msg.match[2], 10);
67+
const { address } = await networkClient.getColony.call({
68+
id: parseInt(msg.match[1], 10)
69+
})
70+
const taskId = parseInt(msg.match[2], 10)
6271
if (!address) {
63-
return msg.send("No such colony");
72+
return msg.send('No such colony')
6473
}
65-
const colonyClient = await networkClient.getColonyClientByAddress(address);
66-
const task = await colonyClient.getTask.call({taskId});
67-
let output = "";
68-
if (task.specificationHash){
69-
output += "Specification: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n"
74+
const colonyClient = await networkClient.getColonyClientByAddress(address)
75+
const task = await colonyClient.getTask.call({ taskId })
76+
let output = ''
77+
if (task.specificationHash) {
78+
output +=
79+
'Specification: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n'
7080
} else {
71-
output += "Specification: None\n"
81+
output += 'Specification: None\n'
7282
}
7383

74-
if (task.deliverableHash){
75-
output += "Deliverable: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n"
84+
if (task.deliverableHash) {
85+
output +=
86+
'Deliverable: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n'
7687
} else {
77-
output += "Deliverable: None\n"
88+
output += 'Deliverable: None\n'
7889
}
79-
output += `Finalized: ${task.finalized ? "Yes" : "No"}\n`
80-
output += `Cancelled: ${task.cancelled ? "Yes" : "No"}`
90+
output += `Finalized: ${task.finalized ? 'Yes' : 'No'}\n`
91+
output += `Cancelled: ${task.cancelled ? 'Yes' : 'No'}`
8192
output += `\nDue date: `
82-
if (task.dueDate){
93+
if (task.dueDate) {
8394
output += ` ${new Date(task.dueDate * 1000).toISOString()}`
8495
} else {
8596
output += ` none`
8697
}
87-
output += `\nDeliverable date: `;
88-
if (task.deliverableDate){
98+
output += `\nDeliverable date: `
99+
if (task.deliverableDate) {
89100
output += `${new Date(task.deliverableDate * 1000).toISOString()}`
90101
} else {
91-
output += ` none`;
102+
output += ` none`
92103
}
93104

94-
let res = await colonyClient.getTaskRole.call({taskId, role: 'MANAGER'} )
95-
output += `\nManager: ${ res.address }`
96-
res = await colonyClient.getTaskRole.call({taskId, role: 'EVALUATOR'} )
97-
output += `\nEvaluator: ${ res.address }`
98-
res = await colonyClient.getTaskRole.call({taskId, role: 'WORKER'} )
99-
output += `\nWorker: ${ res.address }`
105+
let res = await colonyClient.getTaskRole.call({ taskId, role: 'MANAGER' })
106+
output += `\nManager: ${res.address}`
107+
res = await colonyClient.getTaskRole.call({ taskId, role: 'EVALUATOR' })
108+
output += `\nEvaluator: ${res.address}`
109+
res = await colonyClient.getTaskRole.call({ taskId, role: 'WORKER' })
110+
output += `\nWorker: ${res.address}`
100111

101-
msg.send(output);
112+
msg.send(output)
102113
})
103114
}

scripts/countdown.js

+67-73
Original file line numberDiff line numberDiff line change
@@ -17,137 +17,131 @@
1717
// Author:
1818
// JamesLefrere
1919

20-
const CronJob = require('cron').CronJob;
20+
const CronJob = require('cron').CronJob
2121

22-
const getBrain = require('./utils/brain');
22+
const getBrain = require('./utils/brain')
2323

24-
const {
25-
getOffsetDate,
26-
parseNaturalDate,
27-
} = require('./utils/dates');
24+
const { getOffsetDate, parseNaturalDate } = require('./utils/dates')
2825

29-
const { isPrivateSlackMessage } = require('./utils/channels');
26+
const { isPrivateSlackMessage } = require('./utils/channels')
3027

31-
const BRAIN_PREFIX = 'countdown';
32-
const COUNTDOWNS = 'countdowns';
28+
const BRAIN_PREFIX = 'countdown'
29+
const COUNTDOWNS = 'countdowns'
3330

34-
const {
35-
addToMap,
36-
getFromMap,
37-
getMap,
38-
removeFromMap,
39-
} = getBrain(BRAIN_PREFIX);
31+
const { addToMap, getFromMap, getMap, removeFromMap } = getBrain(BRAIN_PREFIX)
4032

4133
const getSass = hours => {
42-
if (hours > 24 * 7 * 4) return 'An ocean of time.';
43-
if (hours > 24 * 7 * 3.5) return 'Ages, mate.';
44-
if (hours > 24 * 7 * 3) return `It's getting closer, but it'll be fine.`;
45-
if (hours > 24 * 7 * 2.5) return 'Watch out for this one.';
46-
if (hours > 24 * 7 * 2) return 'Did you try working faster?';
47-
if (hours > 24 * 7 * 1.5) return `That's concerning.`;
48-
if (hours > 24 * 7) return `That's quite soon if you think about it.`;
49-
if (hours > 24 * 6) return `Well that doesn't sound right...`;
50-
if (hours > 24 * 5) return 'A week?! A mere working week?!';
51-
if (hours > 24 * 4) return 'Shit, we can do it!';
52-
if (hours > 24 * 3) return 'A'.repeat(20);
53-
if (hours > 24 * 2) return `I'll give you 1 ETH if you finish it today.`;
54-
if (hours > 24) return `*${'A'.repeat(200)}*`;
55-
return '*PANIC MODE ENGAGE!!!* gogogogogogogogogogogogogo54321111111glhf';
56-
};
57-
58-
const getKey = title => title.replace(/\s/g, '');
34+
if (hours > 24 * 7 * 4) return 'An ocean of time.'
35+
if (hours > 24 * 7 * 3.5) return 'Ages, mate.'
36+
if (hours > 24 * 7 * 3) return `It's getting closer, but it'll be fine.`
37+
if (hours > 24 * 7 * 2.5) return 'Watch out for this one.'
38+
if (hours > 24 * 7 * 2) return 'Did you try working faster?'
39+
if (hours > 24 * 7 * 1.5) return `That's concerning.`
40+
if (hours > 24 * 7) return `That's quite soon if you think about it.`
41+
if (hours > 24 * 6) return `Well that doesn't sound right...`
42+
if (hours > 24 * 5) return 'A week?! A mere working week?!'
43+
if (hours > 24 * 4) return 'Shit, we can do it!'
44+
if (hours > 24 * 3) return 'A'.repeat(20)
45+
if (hours > 24 * 2) return `I'll give you 1 ETH if you finish it today.`
46+
if (hours > 24) return `*${'A'.repeat(200)}*`
47+
return '*PANIC MODE ENGAGE!!!* gogogogogogogogogogogogogo54321111111glhf'
48+
}
49+
50+
const getKey = title => title.replace(/\s/g, '')
5951

6052
const processCountdowns = robot => {
61-
const { brain } = robot;
62-
const currentDate = getOffsetDate(-11);
53+
const { brain } = robot
54+
const currentDate = getOffsetDate(-11)
6355

6456
Object.entries(getMap(COUNTDOWNS, brain)).forEach(
6557
([key, { title, dueDate, room }]) => {
66-
const diff = new Date(dueDate).getTime() - new Date(currentDate).getTime();
58+
const diff = new Date(dueDate).getTime() - new Date(currentDate).getTime()
6759

6860
if (diff < 0) {
69-
robot.messageRoom(room, `${title}: due date elapsed!`);
70-
return removeFromMap(COUNTDOWNS, key, brain);
61+
robot.messageRoom(room, `${title}: due date elapsed!`)
62+
return removeFromMap(COUNTDOWNS, key, brain)
7163
}
7264

73-
const hours = (diff / (1000 * 60 * 60)).toFixed(2);
65+
const hours = (diff / (1000 * 60 * 60)).toFixed(2)
7466

7567
robot.messageRoom(
7668
room,
7769
`${title}: ${hours} hours remaining. ${getSass(hours)}`
78-
);
79-
});
80-
};
70+
)
71+
}
72+
)
73+
}
8174

8275
const setupCronJob = robot => {
8376
const job = new CronJob({
8477
// Every weekday 23:45h
8578
cronTime: '00 45 23 * * *',
8679
onTick: () => {
87-
processCountdowns(robot);
80+
processCountdowns(robot)
8881
},
8982
start: false,
9083
// Last time zone of the day (UTC-11)
9184
timeZone: 'Pacific/Niue'
92-
});
93-
job.start();
94-
};
85+
})
86+
job.start()
87+
}
9588

9689
module.exports = robot => {
97-
const { brain } = robot;
98-
setupCronJob(robot);
90+
const { brain } = robot
91+
setupCronJob(robot)
9992

10093
robot.hear(/^countdown add '(.+)' (.+)$/, res => {
101-
const { message: { user, room }, match } = res;
94+
const {
95+
message: { user, room },
96+
match
97+
} = res
10298

10399
if (isPrivateSlackMessage(res)) {
104-
return res.send('Countdowns can only be added in a channel.');
100+
return res.send('Countdowns can only be added in a channel.')
105101
}
106102

107103
if (user.slack.tz_offset == null) {
108104
return res.send('Please set your time zone in slack first')
109105
}
110106

111-
const title = match[1];
112-
const dueDate = parseNaturalDate(match[2], user);
107+
const title = match[1]
108+
const dueDate = parseNaturalDate(match[2], user)
113109

114-
const key = getKey(title);
115-
const existing = getFromMap(COUNTDOWNS, key, brain);
110+
const key = getKey(title)
111+
const existing = getFromMap(COUNTDOWNS, key, brain)
116112

117113
if (existing) {
118-
return res.send('Oops, a countdown with that title already exists');
114+
return res.send('Oops, a countdown with that title already exists')
119115
}
120116

121-
addToMap(
122-
COUNTDOWNS,
123-
key,
124-
{ title, dueDate, room, userId: user.id },
125-
brain
126-
);
117+
addToMap(COUNTDOWNS, key, { title, dueDate, room, userId: user.id }, brain)
127118

128-
return res.send('The countdown begins!');
129-
});
119+
return res.send('The countdown begins!')
120+
})
130121

131122
robot.hear(/^countdown status$/, () => {
132-
processCountdowns(robot);
133-
});
123+
processCountdowns(robot)
124+
})
134125

135126
robot.hear(/^countdown remove '(.*)'$/, res => {
136-
const { message: { user }, match } = res;
127+
const {
128+
message: { user },
129+
match
130+
} = res
137131

138-
const key = getKey(match[1]);
139-
const existing = getFromMap(COUNTDOWNS, key, brain);
132+
const key = getKey(match[1])
133+
const existing = getFromMap(COUNTDOWNS, key, brain)
140134

141135
if (!existing) {
142-
return res.send(`That countdown doesn't exist`);
136+
return res.send(`That countdown doesn't exist`)
143137
}
144138

145139
if (user.id !== existing.userId) {
146-
return res.send(`Only user ID ${userId} can remove that countdown`);
140+
return res.send(`Only user ID ${userId} can remove that countdown`)
147141
}
148142

149-
removeFromMap(COUNTDOWNS, key, brain);
143+
removeFromMap(COUNTDOWNS, key, brain)
150144

151-
return res.send('Countdown removed');
152-
});
153-
};
145+
return res.send('Countdown removed')
146+
})
147+
}

scripts/daily-standup.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ const {
2424
getCurrentTimeForUser,
2525
dateIsInRange,
2626
dateIsOlderThan,
27-
parseNaturalDate,
28-
} = require('./utils/dates');
27+
parseNaturalDate
28+
} = require('./utils/dates')
2929

30-
const { isChannel, isPrivateSlackMessage } = require('./utils/channels');
30+
const { isChannel, isPrivateSlackMessage } = require('./utils/channels')
3131

32-
const getBrain = require('./utils/brain');
32+
const getBrain = require('./utils/brain')
3333

34-
const BRAIN_PREFIX = 'standup';
34+
const BRAIN_PREFIX = 'standup'
3535
// This is the daily-standup channel. This should be an env variable at some point
36-
const HUBOT_STANDUP_CHANNEL = 'C0NFZA7T5';
36+
const HUBOT_STANDUP_CHANNEL = 'C0NFZA7T5'
3737
// #standup-testing channel
3838
// const HUBOT_STANDUP_CHANNEL = 'CBX6J6MAA'
3939

@@ -44,8 +44,8 @@ const {
4444
removeFromMap,
4545
removeMap,
4646
setMap,
47-
updateMap,
48-
} = getBrain(BRAIN_PREFIX);
47+
updateMap
48+
} = getBrain(BRAIN_PREFIX)
4949

5050
/* User permission helpers */
5151
const getUser = (userId, brain) => {

0 commit comments

Comments
 (0)