Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
lol
Browse files Browse the repository at this point in the history
  • Loading branch information
Malachi authored and Malachi committed Jun 5, 2021
1 parent a5d677d commit 12d9c24
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 57 deletions.
34 changes: 10 additions & 24 deletions commands/util/dpod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const { Command } = require('discord.js-commando')
const config = require('$root/config.json')
const mission = require('$root/mission.json')
const count = require('$util/count')
const dpod = require('$root/dpod.json')
const fs = require('fs')

module.exports = class Invite extends Command {
constructor(client) {
Expand Down Expand Up @@ -35,9 +33,9 @@ module.exports = class Invite extends Command {
}

async run(message, { channel, action }) {
count.cmdRun(this.name, this.group, message)
let guildChannel = dpod.find(channel => channel.guild === message.guild.id)
let dpodInfo = dpod
count.cmdCount++

let guildChannel = this.client.provider.get(message.guild, 'dpod')

function msg(description) {
message.embed({
Expand All @@ -57,33 +55,21 @@ module.exports = class Invite extends Command {
}

if (!guildChannel) {
dpodInfo.push({ guild: message.guild.id, channel: channel.id })

let json = JSON.stringify(dpodInfo)
fs.writeFile('dpod.json', json, function (err) {
if (err) throw err
})
this.client.provider.set(message.guild, 'dpod', channel.id)

return msg(`Set Your DPOD Channel to <#${channel.id}>\nTo reset it use: ${message.anyUsage('dpod reset')}`)
}

msg(
`Your already have a DPOD\nThe Current DPOD Channel is <#${
guildChannel.channel
}>\nTo reset it use:\n${message.anyUsage('dpod reset')}`
`Your already have a DPOD\nThe Current DPOD Channel is <#${guildChannel}>\nTo reset it use:\n${message.anyUsage(
'dpod reset'
)}`
)
}

if (action == 'reset') {
if (guildChannel) {
let dpodInfoFiltered = await dpodInfo.filter(array => {
array.guild != message.guild.id
})

let json = JSON.stringify(dpodInfoFiltered)
fs.writeFile('dpod.json', json, function (err) {
if (err) throw err
})
this.client.provider.remove(message.guild, 'dpod')

msg(`The DPOD Channel has been reset\nTo set a new one use: ${message.anyUsage('dpod set <channel>')}`)
return
Expand All @@ -93,9 +79,9 @@ module.exports = class Invite extends Command {
}

if (action == 'info') {
if (dpod.find(channel => channel.guild === message.guild.id)) {
if (this.client.provider.get(message.guild, 'dpod', false)) {
msg(
`The Current DPOD Channel is <#${guildChannel.channel}>\nTo reset it use:\n${message.anyUsage(
`The Current DPOD Channel is <#${guildChannel}>\nTo reset it use:\n${message.anyUsage(
'dpod reset'
)}\nDPOD runs every day at [12PM UTC± 0](https://www.google.com/search?q=12pm+utc+time+zone+converter)`
)
Expand Down
1 change: 1 addition & 0 deletions dpod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
78 changes: 45 additions & 33 deletions util/dpod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,49 @@ const axios = require('axios')
const schedule = require('node-schedule')
const chalk = require('chalk')
const config = require('$root/config.json')
const dpod = require('$root/dpod.json')
let img = ''
const count = require('$util/count')

let delay = 1000
let i

const dpod = async function () {
let img = ''
await axios
.get(`https://api.nasa.gov/planetary/apod?api_key=${config.api_key}`)
.then(async res => {
if (res.data.hdurl) {
img = res.data.hdurl
} else {
img = res.data.url
}

let embed = {
title: res.data.title,
url: img,
description: res.data.explanation,
color: config.embed_color,
image: { url: img },
timestamp: res.data.date,
footer: { text: `Photo Credit: ${res.data.copyright}` }
}

let channels = []
this.guilds.cache.each(guild => {
if (this.provider.get(guild, 'dpod', false)) channels.push(this.provider.get(guild, 'dpod'))
})

for (let channel of channels) {
this.channels.cache
.get(channel)
.send({ embed })
.catch(() => {})

await count.sleep(delay)
}
})
.catch(function (error) {
console.log(error.stack)
})
}

module.exports = {
async execute(client) {
Expand All @@ -17,34 +56,7 @@ module.exports = {
rule.tz = 'Etc/UTC'

/*eslint-disable */
const job = schedule.scheduleJob(rule, async function () {
/*eslint-enable */
await axios
.get(`https://api.nasa.gov/planetary/apod?api_key=${config.api_key}`)
.then(async res => {
if (res.data.hdurl) {
img = res.data.hdurl
} else {
img = res.data.url
}

let embed = {
title: res.data.title,
url: img,
description: res.data.explanation,
color: config.embed_color,
image: { url: img },
timestamp: res.data.date,
footer: { text: `Photo Credit: ${res.data.copyright}` }
}

for (i = 0; i < dpod.length; i++) {
client.channels.cache.get(dpod[i].channel).send({ embed })
}
})
.catch(function (error) {
console.log(error.stack)
})
})
}
const job = schedule.scheduleJob(rule, dpod.bind(client))
},
dpod
}

0 comments on commit 12d9c24

Please sign in to comment.