-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nayan.js
165 lines (161 loc) · 5.47 KB
/
Nayan.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
module.exports = async ({ api, event }) => {
const logger = require('./Nayan/catalogs/Nayanc.js')
const configCustom = {
autosetbio: {
status: false,
bio: `prefix : ${global.config.PREFIX}`,
note: 'automatically change the bot bio.'
},
notification: {
status: false,
time: 39, // 39 minutes
note: 'bot will update you on his informations like all users, all groups, all operators, all admins every 30 minutes'
},
greetings: {
status: true,
morning: `goodmorning everyone, have a nice day.`,
afternoon: `goodafternoon everyone, don't forget to eat your lunch.`,
evening: `goodevening everyone, don't forget to eat.`,
sleep: `goodnight everyone, time to sleep.`,
note: 'greetings every morning, afternoon and evening. the timezone is located in Asia/Dhaka'
},
reminder: {
status: true,
time: 40, // 40 minutes
msg: 'reminder test',
note: 'this is a reminder for 40 minutes, you can disabled it by setting the status to false'
},
autoDeleteCache: {
status: true,
time: 10, // 10 minutes
note: 'auto delete caches, kindly set the status to true, if you dont want to delete caches, set the status to false.'
},
autoRestart: {
status: true,
time: 40, // 40 minutes
note: 'to avoid problems, enable periodic bot restarts, set the status to false if you want to disable auto restart function.'
},
accpetPending: {
status: true,
time: 10, // 10 minutes
note: 'approve waiting messages after a certain time, set the status to false if you want to disable auto accept message request.'
}
}
function autosetbio(config) {
if (config.status) {
try {
api.changeBio(config.bio, (err) => {
if (err) {
logger(`having some unexpected error : ${err}`, 'setbio')
}; return logger(`changed the bot bio into : ${config.bio}`, 'setbio')
})
} catch (error) {
logger(`having some unexpected error : ${error}`, 'setbio')
}
}
}
function notification(config) {
if (config.status) {
setInterval(async () => {
const operator = global.config.OPERATOR[0];
api.sendMessage(`bot information\n\nusers : ${global.data.allUserID.length}\ngroups : ${global.data.allThreadID.length}\noperators : ${global.config.OPERATOR.length}\nadmins : ${global.config.ADMINBOT.length}`, operator)
}, config.time * 60 * 1000)
}
}
function greetings(config) {
if (config.status) {
try {
const nam = [
{
timer: '6:00:00 AM',
message: [`${config.morning}`]
},
{
timer: '12:00:00 AM',
message: [`${config.afternoon}`]
},
{
timer: '6:00:00 PM',
message: [`${config.evening}`]
},
{
timer: '10:00:00 PM',
message: [`${config.sleep}`]
}
];
setInterval(() => {
const r = a => a[Math.floor(Math.random()*a.length)];
if (á = nam.find(i => i.timer == new Date(Date.now()+25200000).toLocaleString().split(/,/).pop().trim())) global.data.allThreadID.forEach(i => api.sendMessage(r(á.message), i));
}, 1000);
} catch (error) {
logger(`having some unexpected error : ${error}`, 'greetings')
}
}
}
function reminder(config) {
if (config.status) {
setInterval(async () => {
let allThread = global.data.allThreadID || [];
await new Promise(resolve => {
allThread.forEach((each) => {
try {
api.sendMessage(config.msg, each, (err, info) => {
if (err) {
logger(`having some unexpected error : ${err}`, 'reminder')
}
})
} catch (error) {
logger(`having some unexpected error : ${error}`, 'reminder')
}
})
})
}, config.time * 60 * 1000)
}
}
function autoDeleteCache(config) {
if(config.status) {
setInterval(async () => {
const { exec } = require('child_process');
exec('rm -rf ../../scripts/commands/cache && mkdir -p ../../scripts/commands/cache && rm -rf ../../scripts/events/cache && mkdir -p ../../scripts/events/cache', (error, stdout, stderr) => {
if (error) {
logger(`error : ${error}`, "cache")
return;
}
if (stderr) {
logger(`stderr : ${stderr}`, "cache")
return;
}
return logger(`successfully deleted caches`, "cache")
})
}, config.time * 60 * 1000)
}
}
function autoRestart(config) {
if(config.status) {
setInterval(async () => {
logger(`auto restart is processing, please wait.`, "Nayan")
process.exit(1)
}, config.time * 60 * 1000)
}
}
function accpetPending(config) {
if(config.status) {
setInterval(async () => {
const list = [
...(await api.getThreadList(1, null, ['PENDING'])),
...(await api.getThreadList(1, null, ['OTHER']))
];
if (list[0]) {
api.sendMessage('this thread is automatically approved by our system.', list[0].threadID);
}
}, config.time * 60 * 1000)
}
}
autosetbio(configCustom.autosetbio)
notification(configCustom.notification)
greetings(configCustom.greetings)
reminder(configCustom.reminder)
autoDeleteCache(configCustom.autoDeleteCache)
autoRestart(configCustom.autoRestart)
accpetPending(configCustom.accpetPending)
};