mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-12-22 01:03:26 +01:00
discord tinkering
This commit is contained in:
parent
9fd113f424
commit
76d0f6b73b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
.vercel
|
||||
|
@ -1,3 +0,0 @@
|
||||
media/
|
||||
test/
|
||||
package-lock.json
|
@ -39,6 +39,9 @@ Endpoint: [`https://oceanprotocol-community.now.sh`](https://oceanprotocol-commu
|
||||
"telegram": {
|
||||
"community": 1000,
|
||||
"news": 1000
|
||||
},
|
||||
"discord": {
|
||||
"members": 1000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
39
index.js
39
index.js
@ -6,12 +6,14 @@ const fetchBounties = require('./networks/bounties')
|
||||
const fetchMedium = require('./networks/medium')
|
||||
const fetchTwitter = require('./networks/twitter')
|
||||
const fetchTelegram = require('./networks/telegram')
|
||||
const fetchDiscord = require('./networks/discord')
|
||||
|
||||
let cacheGithub = null
|
||||
let cacheBounties = null
|
||||
let cacheMedium = null
|
||||
let cacheTwitter = null
|
||||
let cacheTelegram = null
|
||||
let cacheDiscord = null
|
||||
|
||||
//
|
||||
// Create the response
|
||||
@ -23,23 +25,47 @@ module.exports = async (req, res) => {
|
||||
try {
|
||||
/* eslint-disable require-atomic-updates */
|
||||
if (!cacheGithub || Date.now() - cacheGithub.lastUpdate > ms('5m')) {
|
||||
cacheGithub = await fetchGitHubRepos()
|
||||
try {
|
||||
cacheGithub = await fetchGitHubRepos()
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cacheBounties || Date.now() - cacheBounties.lastUpdate > ms('5m')) {
|
||||
cacheBounties = await fetchBounties()
|
||||
try {
|
||||
cacheBounties = await fetchBounties()
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) {
|
||||
cacheMedium = await fetchMedium()
|
||||
try {
|
||||
cacheMedium = await fetchMedium()
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cacheTwitter || Date.now() - cacheTwitter.lastUpdate > ms('5m')) {
|
||||
cacheTwitter = await fetchTwitter()
|
||||
try {
|
||||
cacheTwitter = await fetchTwitter()
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cacheTelegram || Date.now() - cacheTelegram.lastUpdate > ms('5m')) {
|
||||
cacheTelegram = await fetchTelegram()
|
||||
try {
|
||||
cacheTelegram = await fetchTelegram()
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
if (!cacheDiscord || Date.now() - cacheDiscord.lastUpdate > ms('5m')) {
|
||||
cacheDiscord = await fetchDiscord()
|
||||
}
|
||||
/* eslint-enable require-atomic-updates */
|
||||
} catch (error) {
|
||||
@ -51,6 +77,7 @@ module.exports = async (req, res) => {
|
||||
bounties: cacheBounties,
|
||||
medium: cacheMedium,
|
||||
twitter: cacheTwitter,
|
||||
telegram: cacheTelegram
|
||||
telegram: cacheTelegram,
|
||||
discord: cacheDiscord
|
||||
})
|
||||
}
|
||||
|
21
networks/discord.js
Normal file
21
networks/discord.js
Normal file
@ -0,0 +1,21 @@
|
||||
const { log, logError } = require('../utils')
|
||||
const Discord = require('discord.js')
|
||||
const client = new Discord.Client()
|
||||
|
||||
const fetchDiscord = async () => {
|
||||
const url = 'https://discord.com/invite/TnXjkR5'
|
||||
const start = Date.now()
|
||||
|
||||
const myGuild = client.guilds.cache.get('703315963583528991')
|
||||
const members = myGuild.members.cache.filter(member => !member.user.bot).size
|
||||
|
||||
log(
|
||||
'Re-built Discord cache. ' +
|
||||
`Total: ${members} members. ` +
|
||||
`Elapsed: ${new Date() - start}ms`
|
||||
)
|
||||
|
||||
return { members }
|
||||
}
|
||||
|
||||
module.exports = fetchDiscord
|
5
now.json
5
now.json
@ -1,10 +1,5 @@
|
||||
{
|
||||
"version": 2,
|
||||
"name": "oceanprotocol-community",
|
||||
"alias": "oceanprotocol-community.now.sh",
|
||||
"env": {
|
||||
"NODE_ENV": "production"
|
||||
},
|
||||
"builds": [
|
||||
{
|
||||
"src": "index.js",
|
||||
|
2258
package-lock.json
generated
Normal file
2258
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,5 @@
|
||||
{
|
||||
"name": "@oceanprotocol/community-numbers",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@ -10,11 +9,12 @@
|
||||
"dependencies": {
|
||||
"chalk": "4.1.0",
|
||||
"cheerio": "^1.0.0-rc.3",
|
||||
"discord.js": "^12.2.0",
|
||||
"ms": "^2.1.1",
|
||||
"node-fetch": "2.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.0.0",
|
||||
"eslint": "^7.2.0",
|
||||
"eslint-config-oceanprotocol": "^1.5.0",
|
||||
"eslint-plugin-node": "^11.1.0"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user