mirror of
https://github.com/oceanprotocol/community-numbers.git
synced 2024-11-24 19:10:17 +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
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn.lock
|
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": {
|
"telegram": {
|
||||||
"community": 1000,
|
"community": 1000,
|
||||||
"news": 1000
|
"news": 1000
|
||||||
|
},
|
||||||
|
"discord": {
|
||||||
|
"members": 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
29
index.js
29
index.js
@ -6,12 +6,14 @@ const fetchBounties = require('./networks/bounties')
|
|||||||
const fetchMedium = require('./networks/medium')
|
const fetchMedium = require('./networks/medium')
|
||||||
const fetchTwitter = require('./networks/twitter')
|
const fetchTwitter = require('./networks/twitter')
|
||||||
const fetchTelegram = require('./networks/telegram')
|
const fetchTelegram = require('./networks/telegram')
|
||||||
|
const fetchDiscord = require('./networks/discord')
|
||||||
|
|
||||||
let cacheGithub = null
|
let cacheGithub = null
|
||||||
let cacheBounties = null
|
let cacheBounties = null
|
||||||
let cacheMedium = null
|
let cacheMedium = null
|
||||||
let cacheTwitter = null
|
let cacheTwitter = null
|
||||||
let cacheTelegram = null
|
let cacheTelegram = null
|
||||||
|
let cacheDiscord = null
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create the response
|
// Create the response
|
||||||
@ -23,23 +25,47 @@ module.exports = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
/* eslint-disable require-atomic-updates */
|
/* eslint-disable require-atomic-updates */
|
||||||
if (!cacheGithub || Date.now() - cacheGithub.lastUpdate > ms('5m')) {
|
if (!cacheGithub || Date.now() - cacheGithub.lastUpdate > ms('5m')) {
|
||||||
|
try {
|
||||||
cacheGithub = await fetchGitHubRepos()
|
cacheGithub = await fetchGitHubRepos()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cacheBounties || Date.now() - cacheBounties.lastUpdate > ms('5m')) {
|
if (!cacheBounties || Date.now() - cacheBounties.lastUpdate > ms('5m')) {
|
||||||
|
try {
|
||||||
cacheBounties = await fetchBounties()
|
cacheBounties = await fetchBounties()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) {
|
if (!cacheMedium || Date.now() - cacheMedium.lastUpdate > ms('5m')) {
|
||||||
|
try {
|
||||||
cacheMedium = await fetchMedium()
|
cacheMedium = await fetchMedium()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cacheTwitter || Date.now() - cacheTwitter.lastUpdate > ms('5m')) {
|
if (!cacheTwitter || Date.now() - cacheTwitter.lastUpdate > ms('5m')) {
|
||||||
|
try {
|
||||||
cacheTwitter = await fetchTwitter()
|
cacheTwitter = await fetchTwitter()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cacheTelegram || Date.now() - cacheTelegram.lastUpdate > ms('5m')) {
|
if (!cacheTelegram || Date.now() - cacheTelegram.lastUpdate > ms('5m')) {
|
||||||
|
try {
|
||||||
cacheTelegram = await fetchTelegram()
|
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 */
|
/* eslint-enable require-atomic-updates */
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -51,6 +77,7 @@ module.exports = async (req, res) => {
|
|||||||
bounties: cacheBounties,
|
bounties: cacheBounties,
|
||||||
medium: cacheMedium,
|
medium: cacheMedium,
|
||||||
twitter: cacheTwitter,
|
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,
|
"version": 2,
|
||||||
"name": "oceanprotocol-community",
|
|
||||||
"alias": "oceanprotocol-community.now.sh",
|
|
||||||
"env": {
|
|
||||||
"NODE_ENV": "production"
|
|
||||||
},
|
|
||||||
"builds": [
|
"builds": [
|
||||||
{
|
{
|
||||||
"src": "index.js",
|
"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",
|
"name": "@oceanprotocol/community-numbers",
|
||||||
"private": true,
|
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -10,11 +9,12 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "4.1.0",
|
"chalk": "4.1.0",
|
||||||
"cheerio": "^1.0.0-rc.3",
|
"cheerio": "^1.0.0-rc.3",
|
||||||
|
"discord.js": "^12.2.0",
|
||||||
"ms": "^2.1.1",
|
"ms": "^2.1.1",
|
||||||
"node-fetch": "2.6.0"
|
"node-fetch": "2.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.0.0",
|
"eslint": "^7.2.0",
|
||||||
"eslint-config-oceanprotocol": "^1.5.0",
|
"eslint-config-oceanprotocol": "^1.5.0",
|
||||||
"eslint-plugin-node": "^11.1.0"
|
"eslint-plugin-node": "^11.1.0"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user