-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
110 lines (92 loc) · 3.7 KB
/
server.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
require("dotenv").config()
const {DISCORD_TOKEN, CHANNEL_ID} = require("./important")
const {Client} = require("discord.js")
const client = new Client()
const {sendIntervalNotification, checkByDetails, getFirstTenObjects, getFirstNObjects} = require("./functions")
const checkContinously = () => {
const functionToBeExecuted = (arrayOfElements) => {
console.log(`Sending message`)
var channel1 = client.channels.cache.get(CHANNEL_ID)
let arrayToBeSent = []
for(let element in arrayOfElements){
if (element < 5){
arrayToBeSent.push(arrayOfElements[element])
}
}
arrayToBeSent.forEach(object =>{
const sentence = {
title:`***${object.date} ${object.month} ${object.year}***`,
url:`${object.link}`,
description:"```" + object.notification +"```"
}
channel1.send({embed:sentence})
})
}
sendIntervalNotification(functionToBeExecuted)
}
const prefix = "n!"
client.login(DISCORD_TOKEN)
client.on('ready', () => {
console.log(`Logged in as ${client.user.username}`);
})
checkContinously()
client.on('message', (message) => {
if(message.content === `${prefix}status`){
message.channel.send(`Servers name is ${message.guild.name} and BOT ${client.user.username} is active`)
}
})
client.on('message', (message) => {
if(message.content === `${prefix}help`){
const content = "```" + `My Commands are: \n 1. n!notification \n 2. n!notification calender <month> <year>\n 3. n!notification number <number of notifications you want>\n 4. n!status\n 5. n!help` + "```"
message.channel.send(content)
}
})
client.on('message', (message) => {
if(message.content === `${prefix}notification`){
const functionToBeExecuted = (arrayOfElements) => {
console.log(arrayOfElements.length)
arrayOfElements.forEach(object => {
const sentence = {
title:`***${object.date} ${object.month} ${object.year}***`,
url:`https://ktu.edu.in/${object.link}`,
description:"```" + object.notification +"```"
}
message.channel.send({embed:sentence})
// console.log(sentence);
})
}
getFirstTenObjects(functionToBeExecuted)
// message.channel.send(`Servers name is ${message.guild.name}`)
}
})
client.on('message', (message) => {
if(!message.content.startsWith(prefix) || message.author.bot) return ;
const args = message.content.slice(prefix.length).trim().split(' ')
const command = args.shift().toLowerCase()
if(args[0] == "number"){
var numberOfNotification = parseInt(args[1], 10)
const functionToBeExecuted = (arrayOfElements) => {
console.log(arrayOfElements.length)
arrayOfElements.forEach(object => {
const sentence = {
title:`***${object.date} ${object.month} ${object.year}***`,
url:`https://ktu.edu.in/${object.link}`,
description:"```" + object.notification +"```"
}
message.channel.send({embed:sentence})
// console.log(sentence);
})
}
getFirstNObjects(numberOfNotification, functionToBeExecuted)
} else if(args[0] == "calender"){
const functionToBeExecuted = (obj) => {
obj.forEach(object => {
console.log(object)
message.channel.send({embed:object})
})
}
const month = args[1]
const year = args[2]
checkByDetails(month, year, functionToBeExecuted)
}
})