This repository has been archived by the owner on Sep 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (61 loc) · 1.8 KB
/
index.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { existsSync, writeFileSync } = require('fs')
const path = require('path').resolve()
const dataRoot = path + '/extensions/Cycles/data/'
if (!existsSync(dataRoot + 'community.json')) writeFileSync(dataRoot + 'community.json', '[{"content":"Seoa is the best","author":""}]')
const official = require(dataRoot + 'official.json')
const community = require(dataRoot + 'community.json')
let client, cycle, officialCount, communityCount
class Cycler {
constructor (seoa) {
cycle = 0
officialCount = 0
client = seoa
}
active () {
setInterval(this.cycler, 5000)
}
cycler () {
cycle++
if (cycle % 2 < 1) {
officialCount++
if (officialCount >= official.length) officialCount = 0
let { content, type } = official[officialCount]
content = render(content)
client.user.setActivity(content, { type })
} else {
communityCount = Math.floor(Math.random() * community.length)
client.user.setActivity(community[communityCount].content)
}
}
add (content, author) {
community.push({ content, author })
this.save()
}
delete (num, author) {
const ii = []
const dd = community.filter((d, i) => {
if (d.author === author) {
ii.push(i)
return true
} else return false
})
if (!dd[num]) return false
community.splice(ii[num], 1)
this.save()
return true
}
get (author) {
if (!author) return community
else return community.filter((data) => data.author === author)
}
save () {
writeFileSync(dataRoot + 'community.json', JSON.stringify(community))
}
}
function render (string) {
return string
.replace('{prefix}', client.prefix)
.replace('{userCount}', client.users.cache.size)
.replace('{randomUser}', client.users.cache.random().username)
}
module.exports = Cycler