Skip to content

Commit

Permalink
Added jam_info module
Browse files Browse the repository at this point in the history
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
CSP02 committed Aug 29, 2021
1 parent edc7f4f commit eb67e68
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
3 changes: 3 additions & 0 deletions commands/jam_info/description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description:'Module about jam info commands.',
}
52 changes: 52 additions & 0 deletions commands/jam_info/jamInfo.js
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()
}
})
}
}
58 changes: 58 additions & 0 deletions commands/jam_info/setJamInfo.js
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]})
}
}
49 changes: 49 additions & 0 deletions commands/jam_info/timeRemaining.js
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()
}
})
}
}

0 comments on commit eb67e68

Please sign in to comment.