File size: 1,157 Bytes
7e79d67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const request = require('request-promise')
const colors = require('irc').colors
module.exports = {
  commands: {
    govuk: {
      help: 'Returns a random GOV.UK page',
      fireMessageEvent: true,
      command: async function () {
        const res = await request({
          followRedirect: false,
          resolveWithFullResponse: true,
          simple: false,
          url: 'https://www.gov.uk/random'
        })
        return res.headers.location
      }
    },
    govorg: {
      help: 'Returns a random UK Government organisation',
      command: async (bot) => {
        const data = await request({
          json: true,
          url: 'https://government-organisation.register.gov.uk/records.json?page-size=5000'
        })
        const orgs = []
        for (const prop in data) {
          if (Object.prototype.hasOwnProperty.call(data, prop)) {
            orgs.push(data[prop])
          }
        }
        console.log(orgs)
        const rand = Math.floor(Math.random() * orgs.length)
        const org = orgs[rand].item[0]
        return `${colors.wrap('white', org.name)} ${colors.wrap('gray', org.website)}`
      }
    }
  }
}