1
0
mirror of https://github.com/oceanprotocol/community-numbers.git synced 2024-11-21 09:17:00 +01:00

discord tinkering

This commit is contained in:
Matthias Kretschmann 2020-06-11 15:32:17 +02:00
parent 9fd113f424
commit 76d0f6b73b
Signed by: m
GPG Key ID: 606EEEF3C479A91F
8 changed files with 2318 additions and 17 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules
npm-debug.log
yarn.lock
package-lock.json
.vercel

View File

@ -1,3 +0,0 @@
media/
test/
package-lock.json

View File

@ -39,6 +39,9 @@ Endpoint: [`https://oceanprotocol-community.now.sh`](https://oceanprotocol-commu
"telegram": {
"community": 1000,
"news": 1000
},
"discord": {
"members": 1000
}
}
```

View File

@ -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
View 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

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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"
}