Skip to content

Commit 4dbc278

Browse files
committed
Switch hubot provider to one with newer discord.js
1 parent 362cc84 commit 4dbc278

10 files changed

+1917
-924
lines changed

external-scripts.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[
22
"hubot-diagnostics",
33
"hubot-help",
4-
"hubot-github-status",
54
"hubot-redis-brain",
65
"hubot-slack-reaction"
76
]

package.json

+14-16
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,34 @@
66
"description": "A handy bot for doing Colony things",
77
"scripts": {
88
"start": "env-cmd .env yarn run hubot --name chewie -a slack",
9-
"start-discord": "env-cmd .env yarn run hubot --name chewie -a discord",
9+
"start-discord": "env-cmd .env yarn run hubot --name chewie -a discobot",
1010
"dev": "env-cmd .env yarn run hubot --name chewie"
1111
},
1212
"dependencies": {
1313
"@colony/colony-contract-loader-network": "^1.0.1",
14-
"@colony/colony-js-adapter-ethers": "^1.4.1",
15-
"@colony/colony-js-client": "^1.5.1",
16-
"@slack/client": "^4.3.1",
14+
"@colony/colony-js-adapter-ethers": "^1.14.3",
15+
"@colony/colony-js-client": "^1.14.8",
16+
"@slack/client": "^4.12.0",
1717
"await-exec": "^0.1.2",
18-
"chrono-node": "^1.3.5",
18+
"chrono-node": "^1.4.8",
1919
"coffee-script": "^1.12.7",
20-
"cron": "^1.3.0",
20+
"cron": "^1.8.2",
2121
"env-cmd": "^8.0.2",
22-
"ethers": "^3.0.21",
23-
"figma-js": "^1.3.4",
22+
"ethers": "^3.0.29",
23+
"figma-js": "^1.14.0",
2424
"githubot": "^1.0.1",
2525
"hubot": "^3.3.2",
2626
"hubot-diagnostics": "0.0.2",
27-
"hubot-discobot": "^1.0.2",
28-
"hubot-discord": "^2.1.0",
29-
"hubot-github-status": "^0.2.1",
27+
"hubot-discobot": "^1.0.4",
3028
"hubot-help": "^0.2.2",
3129
"hubot-redis-brain": "^0.0.4",
3230
"hubot-slack": "^4.5.3",
3331
"hubot-slack-reaction": "^0.0.4",
34-
"moment-timezone": "^0.5.31",
35-
"node-fetch": "^2.6.1",
36-
"promise.allsettled": "^1.0.4",
37-
"request": "^2.88.0",
38-
"request-promise-native": "^1.0.7",
32+
"moment-timezone": "^0.5.34",
33+
"node-fetch": "^2.6.6",
34+
"promise.allsettled": "^1.0.5",
35+
"request": "^2.88.2",
36+
"request-promise-native": "^1.0.9",
3937
"spacetime-informal": "^0.3.0"
4038
},
4139
"engines": {

scripts/bsg.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { isChannel, isPrivateDiscordMessage } = require('./utils/channels');
22

33
module.exports = function(robot) {
4-
robot.hear(/@Chewie, what do you hear\?/, async (res) => {
4+
robot.hear(/<@!720953382789185548>, what do you hear\?/, async (res) => {
55
if (res.message.user.id !='273398423787536384') return
6-
res.send('Nothing but the rain.');
6+
res.robot.adapter.send(res.envelope, 'Nothing but the rain.');
77
})
88
}

scripts/daily-standup.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const checkStandupsDone = robot => {
171171
const standuppers = Object.values(getMap('standuppers', brain))
172172

173173
if (nobodyHadToWorkToday(standuppers, day)) {
174-
return robot.messageRoom(
174+
return robot.messageChannel(
175175
HUBOT_STANDUP_CHANNEL,
176176
'Yesterday was a free day for everyone! Hope you enjoyed it 🏝'
177177
)
@@ -190,7 +190,7 @@ const checkStandupsDone = robot => {
190190
const praises = Object.values(getMap('praises', brain))
191191
const randomIdx = Math.floor(Math.random() * praises.length)
192192
const randomPraise = praises[randomIdx]
193-
robot.messageRoom(
193+
robot.messageChannel(
194194
HUBOT_STANDUP_CHANNEL,
195195
`Everyone did their standups yesterday! ${randomPraise ||
196196
'That makes me a very happy Wookiee!'}`
@@ -200,14 +200,14 @@ const checkStandupsDone = robot => {
200200
const randomIdx = Math.floor(Math.random() * phrases.length)
201201
const randomPhrase = phrases[randomIdx]
202202
if (usersToShame.length === 1) {
203-
robot.messageRoom(
203+
robot.messageChannel(
204204
HUBOT_STANDUP_CHANNEL,
205205
`Only <@${usersToShame[0].id}> forgot to do their standup yesterday. ${randomPhrase}`
206206
)
207207
} else {
208208
const displayUsers = usersToShame.slice()
209209
const lastUser = displayUsers.pop()
210-
robot.messageRoom(
210+
robot.messageChannel(
211211
HUBOT_STANDUP_CHANNEL,
212212
displayUsers.map(user => `<@${user.id}>`).join(', ') +
213213
` and <@${lastUser.id}> did not do their standups yesterday. ${randomPhrase}`
@@ -285,7 +285,7 @@ const setupCronJob = robot => {
285285
cronTime: '0 46 23 * * 0',
286286
onTick: () => {
287287
const leaderboard = getLeaderboard(true, robot.brain)
288-
robot.messageRoom(HUBOT_STANDUP_CHANNEL, leaderboard)
288+
robot.messageChannel(HUBOT_STANDUP_CHANNEL, leaderboard)
289289
},
290290
start: false,
291291
// Last time zone of the day (UTC-11)
@@ -295,7 +295,7 @@ const setupCronJob = robot => {
295295
}
296296

297297
module.exports = robot => {
298-
const { brain, messageRoom } = robot
298+
const { brain, messageChannel } = robot
299299
setupCronJob(robot)
300300

301301
// These lines are for debugging. Please leave in and commented for now
@@ -460,8 +460,8 @@ module.exports = robot => {
460460
}
461461

462462
addToMap(date, res.message.user.id, hour, brain)
463-
const channel = robot.client.channels.find(x => x.id == res.message.room)
464-
const message = await channel.fetchMessage(res.message.id)
463+
const channel = robot.client.channels.cache.find(x => x.id == res.message.room)
464+
const message = await channel.messages.fetch(res.message.id)
465465
message.react(":chewie:719957751316611172")
466466
})
467467

scripts/deleteTelegramCaptchas.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const { isChannel, isPrivateDiscordMessage } = require('./utils/channels');
22

33
module.exports = function(robot) {
44
robot.hear(/^[0-9]{4}$/, async (res) => {
5-
const channel = robot.client.channels.find(x => x.id == res.message.room)
6-
const message = await channel.fetchMessage(res.message.id)
5+
const channel = robot.client.channels.cache.find(x => x.id == res.message.room)
6+
const message = await channel.messages.fetch(res.message.id)
77
message.delete()
88
})
99
}

scripts/deployments.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = async function(robot) {
3535
await getDeploymentScripts()
3636

3737
// Get the devops channel ID. The topic will be used to determine what colour is staging / production when asked to deploy to either.
38-
const devopsChannel = robot.client.channels.find(channel => channel.name === "chewie-skunkworks");
38+
const devopsChannel = robot.client.channels.cache.find(channel => channel.name === "chewie-skunkworks");
3939

4040
async function getDeploymentScripts() {
4141
await exec(`rm -rf ./colony-deployment-scripts`);
@@ -120,8 +120,8 @@ module.exports = async function(robot) {
120120
// Can't @ users not in a chat with you, so this needs to be in public now
121121
// if (!isPrivateDiscordMessage(robot.client, res)) return
122122
if (!noAdmins(brain) && !isAdmin(user, brain)) return
123-
const channel = robot.client.channels.find(x => x.id == res.message.room)
124-
const message = await channel.fetchMessage(res.message.id)
123+
const channel = robot.client.channels.cache.find(x => x.id == res.message.room)
124+
const message = await channel.messages.fetch(res.message.id)
125125
const who = message.mentions.users.first().id;
126126

127127
if (addUserWithRole(who, 'admin', brain)) {
@@ -142,8 +142,8 @@ module.exports = async function(robot) {
142142
// if (!isPrivateDiscordMessage(robot.client, res)) return
143143
if (!noAdmins(brain) && !isAdmin(user, brain)) return
144144

145-
const channel = robot.client.channels.find(x => x.id == res.message.room)
146-
const message = await channel.fetchMessage(res.message.id)
145+
const channel = robot.client.channels.cache.find(x => x.id == res.message.room)
146+
const message = await channel.messages.fetch(res.message.id)
147147
const who = message.mentions.users.first().id;
148148

149149
if (removeUserWithRole(who, `admin`, brain)) {
@@ -172,8 +172,8 @@ module.exports = async function(robot) {
172172
const where = res.match[1].toLowerCase();
173173
if (where !== "qa" && where !== "staging" && where !== "production") { return }
174174

175-
const channel = robot.client.channels.find(x => x.id == res.message.room)
176-
const message = await channel.fetchMessage(res.message.id)
175+
const channel = robot.client.channels.cache.find(x => x.id == res.message.room)
176+
const message = await channel.messages.fetch(res.message.id)
177177
const who = message.mentions.users.first().id;
178178
if (!noAdmins(brain) && !isAdmin(user, brain)) return
179179

@@ -193,8 +193,8 @@ module.exports = async function(robot) {
193193
const { brain } = robot
194194
const where = res.match[1].toLowerCase();
195195
if (where !== "qa" && where !== "staging" && where !== "production") { return }
196-
const channel = robot.client.channels.find(x => x.id == res.message.room)
197-
const message = await channel.fetchMessage(res.message.id)
196+
const channel = robot.client.channels.cache.find(x => x.id == res.message.room)
197+
const message = await channel.messages.fetch(res.message.id)
198198
const who = message.mentions.users.first().id;
199199

200200
if (!noAdmins(brain) && !isAdmin(user, brain)) return

scripts/logDiscordErrors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Logs errors from the discord library, which bubble up by design
33

44
module.exports = async function(robot) {
5-
robot.adapter.client.on('error', function(err) {
5+
robot.client.on('error', function(err) {
66
console.log(err);
77
});
88
}

scripts/timezones.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const {
2121
module.exports = robot => {
2222
const { brain, messageRoom } = robot
2323

24-
robot.hear(/^Chewie: !timezone set (.+)$/, res => {
24+
robot.hear(/^!timezone set (.+)$/, res => {
2525
if (!isPrivateDiscordMessage(robot.client, res) ) return
2626
// Do they already have it set?
2727
const zone = getFromMap('users', res.message.user.id, brain);
@@ -34,7 +34,7 @@ module.exports = robot => {
3434
res.send(`You have set your timezone to \`${newZone}\`. If I've understood wrong, try again and try being more specific`);
3535
})
3636

37-
robot.hear(/^Chewie: !timezone$/, res => {
37+
robot.hear(/!timezone$/, res => {
3838
console.log(res);
3939
if (!isPrivateDiscordMessage(robot.client, res) ) return
4040
console.log('whee')

scripts/utils/channels.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const isPrivateSlackMessage = res => res.message.room.startsWith('D');
22
const isPrivateDiscordMessage = (client, res) => {
3+
console.log(client,res)
34
// Get user
4-
const user = client.users.get(res.message.user.id);
5+
const user = client.users.cache.get(res.message.user.id);
56
// Get their DM channel with the bot
67
const channel = user.dmChannel
78
// Is that where we saw the message?

0 commit comments

Comments
 (0)