Skip to content

Commit

Permalink
Apply prettier fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Maniewski committed Sep 27, 2019
1 parent 833b675 commit 7a9e93e
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 295 deletions.
97 changes: 54 additions & 43 deletions scripts/colony-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

const { providers, Wallet } = require('ethers')
const { default: EthersAdapter } = require('@colony/colony-js-adapter-ethers')
const { default: NetworkLoader } = require('@colony/colony-contract-loader-network')
const {
default: NetworkLoader
} = require('@colony/colony-contract-loader-network')
const { default: ColonyNetworkClient } = require('@colony/colony-js-client')

module.exports = async (robot) => {
module.exports = async robot => {
const network = 'rinkeby'
const privateKey = process.env.HUBOT_ETHEREUM_PRIVATE_KEY || '0x0123456789012345678901234567890123456789012345678901234567890123'
const privateKey =
process.env.HUBOT_ETHEREUM_PRIVATE_KEY ||
'0x0123456789012345678901234567890123456789012345678901234567890123'

const loader = new NetworkLoader({ network })
const provider = new providers.EtherscanProvider(network)
Expand All @@ -23,7 +27,7 @@ module.exports = async (robot) => {
const adapter = new EthersAdapter({
loader,
provider,
wallet,
wallet
})

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

robot.hear(/!colony ([0-9]*)$/i, async msg => {
msg.send('Gathering data...');
const { address } = await networkClient.getColony.call({ id: parseInt(msg.match[1], 10) })
msg.send('Gathering data...')
const { address } = await networkClient.getColony.call({
id: parseInt(msg.match[1], 10)
})
if (!address) {
return msg.send("No such colony");
return msg.send('No such colony')
}
const colonyClient = await networkClient.getColonyClientByAddress(address)
const { count } = await colonyClient.getTaskCount.call();
let res = await colonyClient.getToken.call();
const tokenAddress = res.address;
let tokenName;
let tokenSymbol;
const { count } = await colonyClient.getTaskCount.call()
let res = await colonyClient.getToken.call()
const tokenAddress = res.address
let tokenName
let tokenSymbol
try {
res = await colonyClient.token.getTokenInfo.call();
tokenName = res.name;
tokenSymbol = res.symbol;
} catch (err){
res = await colonyClient.token.getTokenInfo.call()
tokenName = res.name
tokenSymbol = res.symbol
} catch (err) {
// No such properties on the token - possible if not ERC20 compliant, as BYOT allows
}

msg.send(`Address: ${address} \nTask count: ${count}\nToken Address: ${tokenAddress}\nToken Name: ${tokenName} (${tokenSymbol})`)
msg.send(
`Address: ${address} \nTask count: ${count}\nToken Address: ${tokenAddress}\nToken Name: ${tokenName} (${tokenSymbol})`
)
})


robot.hear(/!colony ([0-9]*) task ([0-9]*)$/i, async msg => {
msg.send('Gathering data...')
const { address } = await networkClient.getColony.call({ id: parseInt(msg.match[1], 10) })
const taskId = parseInt(msg.match[2], 10);
const { address } = await networkClient.getColony.call({
id: parseInt(msg.match[1], 10)
})
const taskId = parseInt(msg.match[2], 10)
if (!address) {
return msg.send("No such colony");
return msg.send('No such colony')
}
const colonyClient = await networkClient.getColonyClientByAddress(address);
const task = await colonyClient.getTask.call({taskId});
let output = "";
if (task.specificationHash){
output += "Specification: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n"
const colonyClient = await networkClient.getColonyClientByAddress(address)
const task = await colonyClient.getTask.call({ taskId })
let output = ''
if (task.specificationHash) {
output +=
'Specification: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n'
} else {
output += "Specification: None\n"
output += 'Specification: None\n'
}

if (task.deliverableHash){
output += "Deliverable: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n"
if (task.deliverableHash) {
output +=
'Deliverable: https://gateway.ipfs.io/ipfs/QmTDMoVqvyBkNMRhzvukTDznntByUNDwyNdSfV8dZ3VKRC/\n'
} else {
output += "Deliverable: None\n"
output += 'Deliverable: None\n'
}
output += `Finalized: ${task.finalized ? "Yes" : "No"}\n`
output += `Cancelled: ${task.cancelled ? "Yes" : "No"}`
output += `Finalized: ${task.finalized ? 'Yes' : 'No'}\n`
output += `Cancelled: ${task.cancelled ? 'Yes' : 'No'}`
output += `\nDue date: `
if (task.dueDate){
if (task.dueDate) {
output += ` ${new Date(task.dueDate * 1000).toISOString()}`
} else {
output += ` none`
}
output += `\nDeliverable date: `;
if (task.deliverableDate){
output += `\nDeliverable date: `
if (task.deliverableDate) {
output += `${new Date(task.deliverableDate * 1000).toISOString()}`
} else {
output += ` none`;
output += ` none`
}

let res = await colonyClient.getTaskRole.call({taskId, role: 'MANAGER'} )
output += `\nManager: ${ res.address }`
res = await colonyClient.getTaskRole.call({taskId, role: 'EVALUATOR'} )
output += `\nEvaluator: ${ res.address }`
res = await colonyClient.getTaskRole.call({taskId, role: 'WORKER'} )
output += `\nWorker: ${ res.address }`
let res = await colonyClient.getTaskRole.call({ taskId, role: 'MANAGER' })
output += `\nManager: ${res.address}`
res = await colonyClient.getTaskRole.call({ taskId, role: 'EVALUATOR' })
output += `\nEvaluator: ${res.address}`
res = await colonyClient.getTaskRole.call({ taskId, role: 'WORKER' })
output += `\nWorker: ${res.address}`

msg.send(output);
msg.send(output)
})
}
140 changes: 67 additions & 73 deletions scripts/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,137 +17,131 @@
// Author:
// JamesLefrere

const CronJob = require('cron').CronJob;
const CronJob = require('cron').CronJob

const getBrain = require('./utils/brain');
const getBrain = require('./utils/brain')

const {
getOffsetDate,
parseNaturalDate,
} = require('./utils/dates');
const { getOffsetDate, parseNaturalDate } = require('./utils/dates')

const { isPrivateSlackMessage } = require('./utils/channels');
const { isPrivateSlackMessage } = require('./utils/channels')

const BRAIN_PREFIX = 'countdown';
const COUNTDOWNS = 'countdowns';
const BRAIN_PREFIX = 'countdown'
const COUNTDOWNS = 'countdowns'

const {
addToMap,
getFromMap,
getMap,
removeFromMap,
} = getBrain(BRAIN_PREFIX);
const { addToMap, getFromMap, getMap, removeFromMap } = getBrain(BRAIN_PREFIX)

const getSass = hours => {
if (hours > 24 * 7 * 4) return 'An ocean of time.';
if (hours > 24 * 7 * 3.5) return 'Ages, mate.';
if (hours > 24 * 7 * 3) return `It's getting closer, but it'll be fine.`;
if (hours > 24 * 7 * 2.5) return 'Watch out for this one.';
if (hours > 24 * 7 * 2) return 'Did you try working faster?';
if (hours > 24 * 7 * 1.5) return `That's concerning.`;
if (hours > 24 * 7) return `That's quite soon if you think about it.`;
if (hours > 24 * 6) return `Well that doesn't sound right...`;
if (hours > 24 * 5) return 'A week?! A mere working week?!';
if (hours > 24 * 4) return 'Shit, we can do it!';
if (hours > 24 * 3) return 'A'.repeat(20);
if (hours > 24 * 2) return `I'll give you 1 ETH if you finish it today.`;
if (hours > 24) return `*${'A'.repeat(200)}*`;
return '*PANIC MODE ENGAGE!!!* gogogogogogogogogogogogogo54321111111glhf';
};

const getKey = title => title.replace(/\s/g, '');
if (hours > 24 * 7 * 4) return 'An ocean of time.'
if (hours > 24 * 7 * 3.5) return 'Ages, mate.'
if (hours > 24 * 7 * 3) return `It's getting closer, but it'll be fine.`
if (hours > 24 * 7 * 2.5) return 'Watch out for this one.'
if (hours > 24 * 7 * 2) return 'Did you try working faster?'
if (hours > 24 * 7 * 1.5) return `That's concerning.`
if (hours > 24 * 7) return `That's quite soon if you think about it.`
if (hours > 24 * 6) return `Well that doesn't sound right...`
if (hours > 24 * 5) return 'A week?! A mere working week?!'
if (hours > 24 * 4) return 'Shit, we can do it!'
if (hours > 24 * 3) return 'A'.repeat(20)
if (hours > 24 * 2) return `I'll give you 1 ETH if you finish it today.`
if (hours > 24) return `*${'A'.repeat(200)}*`
return '*PANIC MODE ENGAGE!!!* gogogogogogogogogogogogogo54321111111glhf'
}

const getKey = title => title.replace(/\s/g, '')

const processCountdowns = robot => {
const { brain } = robot;
const currentDate = getOffsetDate(-11);
const { brain } = robot
const currentDate = getOffsetDate(-11)

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

if (diff < 0) {
robot.messageRoom(room, `${title}: due date elapsed!`);
return removeFromMap(COUNTDOWNS, key, brain);
robot.messageRoom(room, `${title}: due date elapsed!`)
return removeFromMap(COUNTDOWNS, key, brain)
}

const hours = (diff / (1000 * 60 * 60)).toFixed(2);
const hours = (diff / (1000 * 60 * 60)).toFixed(2)

robot.messageRoom(
room,
`${title}: ${hours} hours remaining. ${getSass(hours)}`
);
});
};
)
}
)
}

const setupCronJob = robot => {
const job = new CronJob({
// Every weekday 23:45h
cronTime: '00 45 23 * * *',
onTick: () => {
processCountdowns(robot);
processCountdowns(robot)
},
start: false,
// Last time zone of the day (UTC-11)
timeZone: 'Pacific/Niue'
});
job.start();
};
})
job.start()
}

module.exports = robot => {
const { brain } = robot;
setupCronJob(robot);
const { brain } = robot
setupCronJob(robot)

robot.hear(/^countdown add '(.+)' (.+)$/, res => {
const { message: { user, room }, match } = res;
const {
message: { user, room },
match
} = res

if (isPrivateSlackMessage(res)) {
return res.send('Countdowns can only be added in a channel.');
return res.send('Countdowns can only be added in a channel.')
}

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

const title = match[1];
const dueDate = parseNaturalDate(match[2], user);
const title = match[1]
const dueDate = parseNaturalDate(match[2], user)

const key = getKey(title);
const existing = getFromMap(COUNTDOWNS, key, brain);
const key = getKey(title)
const existing = getFromMap(COUNTDOWNS, key, brain)

if (existing) {
return res.send('Oops, a countdown with that title already exists');
return res.send('Oops, a countdown with that title already exists')
}

addToMap(
COUNTDOWNS,
key,
{ title, dueDate, room, userId: user.id },
brain
);
addToMap(COUNTDOWNS, key, { title, dueDate, room, userId: user.id }, brain)

return res.send('The countdown begins!');
});
return res.send('The countdown begins!')
})

robot.hear(/^countdown status$/, () => {
processCountdowns(robot);
});
processCountdowns(robot)
})

robot.hear(/^countdown remove '(.*)'$/, res => {
const { message: { user }, match } = res;
const {
message: { user },
match
} = res

const key = getKey(match[1]);
const existing = getFromMap(COUNTDOWNS, key, brain);
const key = getKey(match[1])
const existing = getFromMap(COUNTDOWNS, key, brain)

if (!existing) {
return res.send(`That countdown doesn't exist`);
return res.send(`That countdown doesn't exist`)
}

if (user.id !== existing.userId) {
return res.send(`Only user ID ${userId} can remove that countdown`);
return res.send(`Only user ID ${userId} can remove that countdown`)
}

removeFromMap(COUNTDOWNS, key, brain);
removeFromMap(COUNTDOWNS, key, brain)

return res.send('Countdown removed');
});
};
return res.send('Countdown removed')
})
}
16 changes: 8 additions & 8 deletions scripts/daily-standup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ const {
getCurrentTimeForUser,
dateIsInRange,
dateIsOlderThan,
parseNaturalDate,
} = require('./utils/dates');
parseNaturalDate
} = require('./utils/dates')

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

const getBrain = require('./utils/brain');
const getBrain = require('./utils/brain')

const BRAIN_PREFIX = 'standup';
const BRAIN_PREFIX = 'standup'
// This is the daily-standup channel. This should be an env variable at some point
const HUBOT_STANDUP_CHANNEL = 'C0NFZA7T5';
const HUBOT_STANDUP_CHANNEL = 'C0NFZA7T5'
// #standup-testing channel
// const HUBOT_STANDUP_CHANNEL = 'CBX6J6MAA'

Expand All @@ -44,8 +44,8 @@ const {
removeFromMap,
removeMap,
setMap,
updateMap,
} = getBrain(BRAIN_PREFIX);
updateMap
} = getBrain(BRAIN_PREFIX)

/* User permission helpers */
const getUser = (userId, brain) => {
Expand Down
Loading

0 comments on commit 7a9e93e

Please sign in to comment.