-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added jam_info module where you can set and get the info about jams and events. Please create an issue if bugs are found
- Loading branch information
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description:'Module about jam info commands.', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const mongo = require('../../mongo') | ||
const jamShema = require('../../jamSchema') | ||
|
||
module.exports = { | ||
name:'jaminfo', | ||
description:'sends the time left for the jam', | ||
aliases:['jam', 'infojam', 'ji'], | ||
syntax:'!jam', | ||
|
||
async execute(client, message, args, Discord){ | ||
const guildId = message.guild.id | ||
await mongo().then(async mongoose => { | ||
try { | ||
const jamInfo = await jamShema.findOne({ | ||
guildId, | ||
}) | ||
if(jamInfo === null){ | ||
return message.channel.send("No jams are registered right now!") | ||
} | ||
|
||
const deadline = new Date(jamInfo.jam[0].timestamp) | ||
const topic = jamInfo.jam[0].topic | ||
const otherDetails = jamInfo.jam[0].other | ||
|
||
var date1, date2; | ||
|
||
date1 = new Date(deadline); | ||
var date3 = new Date() | ||
|
||
date2 = new Date(); | ||
|
||
var res = Math.abs(date1 - date2) / 1000; | ||
var days = Math.floor(res / 86400); | ||
var hours = Math.floor(res / 3600) % 24; | ||
var minutes = Math.floor(res / 60) % 60; | ||
var seconds = res % 60; | ||
const timeRem = `${days} days, ${hours} hrs, ${minutes} min, ${parseInt(seconds)} sec remaining` | ||
|
||
const embedMsg = new Discord.MessageEmbed() | ||
.setTitle('Jam info:') | ||
.setColor('#ddff00') | ||
.addFields( | ||
{name:'Topic', value:`${topic}`}, | ||
{name:'Time Remaining:', value:timeRem}, | ||
{name:'Other Details:', value:`${otherDetails}`},) | ||
message.channel.send({embeds:[embedMsg]}) | ||
} finally { | ||
mongoose.connection.close() | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const mongo = require('../../mongo') | ||
const jamShema = require('../../jamSchema') | ||
|
||
module.exports = { | ||
name:'setjam', | ||
description:'Sets the jam info with provided fields', | ||
aliases:['sj', 'setjam'], | ||
syntax:'!setjam <time(date-month-year)> <hours:minutes:seconds> <topic> <otherinfo>', | ||
permissions:['ADMINISTRATOR'], | ||
|
||
async execute(client, message, args, Discord){ | ||
const guildId = message.guild.id | ||
if(!args[0]){ | ||
|
||
return message.channel.send('Provide time period.') | ||
} | ||
const timePeriod = `${args[0]}`; | ||
myDate = timePeriod.split("-"); | ||
const time = `${args[1]}`; | ||
myTime = time.split(":"); | ||
var newDate = new Date( myDate[2], myDate[1] - 1, myDate[0], myTime[0], myTime[1], myTime[2]); | ||
var datum = Date.parse(newDate) | ||
|
||
const data = { | ||
topic:`${args[2]}`, | ||
timestamp:datum, | ||
other:`${args.splice(3).join(' ')}` | ||
} | ||
|
||
await mongo().then(async mongoose => { | ||
try { | ||
await jamShema.findOneAndUpdate({ | ||
guildId, | ||
}, { | ||
guildId, | ||
$push: { | ||
jam: data, | ||
} | ||
}, { | ||
upsert: true | ||
}) | ||
} finally { | ||
mongoose.connection.close() | ||
} | ||
}) | ||
|
||
const embedMsg = new Discord.MessageEmbed() | ||
.setTitle('Jam registered Successfully:') | ||
.setColor('#00ff00') | ||
.addFields( | ||
{name:'Topic:', value:`${data.topic}`}, | ||
{name:'Deadline:', value:`${new Date(data.timestamp)}`}, | ||
{name:'Other Details:', value:`${data.other?`${data.other}`:'no other challenges required'}`} | ||
) | ||
|
||
message.channel.send({embeds:[embedMsg]}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const mongo = require('../../mongo') | ||
const jamShema = require('../../jamSchema') | ||
|
||
module.exports = { | ||
name:'jaminfo', | ||
description:'sends the time left for the jam', | ||
aliases:['jam', 'infojam', 'ji'], | ||
syntax:'!jam', | ||
|
||
async execute(client, message, args, Discord){ | ||
const guildId = message.guild.id | ||
await mongo().then(async mongoose => { | ||
try { | ||
const jamInfo = await jamShema.findOne({ | ||
guildId, | ||
}) | ||
const deadline = new Date(jamInfo.jam[0].timestamp) | ||
const currentTime = new Date().getUTCSeconds() | ||
if(jamInfo === null){ | ||
return message.channel.send("No jams are registered right now!") | ||
} | ||
|
||
|
||
var date1, date2; | ||
|
||
date1 = new Date(deadline); | ||
var date3 = new Date() | ||
console.log(""+date1); | ||
|
||
date2 = new Date(); | ||
console.log(""+date2); | ||
|
||
var res = Math.abs(date1 - date2) / 1000; | ||
var days = Math.floor(res / 86400); | ||
var hours = Math.floor(res / 3600) % 24; | ||
var minutes = Math.floor(res / 60) % 60; | ||
var seconds = res % 60; | ||
|
||
const embedMsg = new Discord.MessageEmbed() | ||
.setTitle('Time remaining') | ||
.setColor('#ddff00') | ||
.setDescription(`${days} days, ${hours} hrs, ${minutes} min, ${parseInt(seconds)} sec remaining`) | ||
message.channel.send({embeds:[embedMsg]}) | ||
} finally { | ||
mongoose.connection.close() | ||
} | ||
}) | ||
} | ||
} |