Compare commits
5 Commits
anniversar
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f29abd9df4 | |||
| f55bd3d98a | |||
| e957444000 | |||
| a1c22295f6 | |||
| 4e1ec14272 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ node_modules/
|
|||||||
config.json
|
config.json
|
||||||
old/
|
old/
|
||||||
bot.log
|
bot.log
|
||||||
|
data/
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ module.exports = {
|
|||||||
|
|
||||||
collector.on('collect', m => {
|
collector.on('collect', m => {
|
||||||
m.stickers.forEach(sticker => {
|
m.stickers.forEach(sticker => {
|
||||||
stickers.push(`https://media.discordapp.net/stickers/${sticker.id}.png`);
|
stickers.push(`https://media.discordapp.net/stickers/${sticker.id}.png?size=1024`);
|
||||||
collector.stop();
|
collector.stop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -41,10 +41,6 @@ module.exports = {
|
|||||||
option.setName('songname')
|
option.setName('songname')
|
||||||
.setDescription('Override song name, otherwise uses name from Spotify')
|
.setDescription('Override song name, otherwise uses name from Spotify')
|
||||||
.setRequired(false))
|
.setRequired(false))
|
||||||
.addStringOption(option =>
|
|
||||||
option.setName('footer_override')
|
|
||||||
.setDescription('Custom footer')
|
|
||||||
.setRequired(false))
|
|
||||||
.addAttachmentOption(option =>
|
.addAttachmentOption(option =>
|
||||||
option.setName('cover_override')
|
option.setName('cover_override')
|
||||||
.setDescription('Uses this image instead of Spotofy metadata')
|
.setDescription('Uses this image instead of Spotofy metadata')
|
||||||
@@ -54,134 +50,146 @@ module.exports = {
|
|||||||
clientSecret: spotify.clientSecret,
|
clientSecret: spotify.clientSecret,
|
||||||
}),
|
}),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
let token = await this.spotifyAPI.clientCredentialsGrant().then(
|
try {
|
||||||
function(data) {
|
let token = await this.spotifyAPI.clientCredentialsGrant().then(
|
||||||
return data.body['access_token'];
|
function(data) {
|
||||||
});
|
return data.body['access_token'];
|
||||||
await this.spotifyAPI.setAccessToken(token);
|
});
|
||||||
|
await this.spotifyAPI.setAccessToken(token);
|
||||||
|
|
||||||
let urls = interaction.options.getString('links', true).split(" ");
|
let urls = interaction.options.getString('links', true).split(" ");
|
||||||
|
|
||||||
let title = ' ';
|
let title = ' ';
|
||||||
let description = ' ';
|
let description = ' ';
|
||||||
let spotifyID = null;
|
let spotifyID = null;
|
||||||
let artists = '';
|
let artists = '';
|
||||||
let songName = '';
|
let songName = '';
|
||||||
let mainArtist = '';
|
let mainArtist = '';
|
||||||
|
|
||||||
const trackEmbed = new EmbedBuilder()
|
const trackEmbed = new EmbedBuilder()
|
||||||
.setColor(Math.floor(Math.random() * 16777214) + 1)
|
.setColor(Math.floor(Math.random() * 16777214) + 1)
|
||||||
.setDescription(`asdasdasda`)
|
.setDescription(`asdasdasda`)
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
let links = [];
|
let links = [];
|
||||||
for (let index = 0; index < urls.length; index++) {
|
for (let index = 0; index < urls.length; index++) {
|
||||||
let url = urls[index];
|
let url = urls[index];
|
||||||
|
|
||||||
if (url.startsWith('https://listen.minzkraut.com/')) {
|
if (url.startsWith('https://listen.minzkraut.com/')) {
|
||||||
links.push(`[<:drmoe:1220702607836839956> Navidrome ](${url})`);
|
links.push(`[<:drmoe:1220702607836839956> Navidrome ](${url})`);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
if (url.startsWith('https://open.spotify.com/')) {
|
||||||
|
url = url.split('?')[0];
|
||||||
|
links.push(`[<:sptfy:1224677302109995078> Spotify ](${url})`);
|
||||||
|
//https://open.spotify.com/track/4FuOHRPC3ZIQ7VQd7KMbds?si=cadd634ea5a14689
|
||||||
|
spotifyID = url.split('/').pop();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (url.startsWith('https://listen.tidal.com/')) {
|
||||||
|
links.push(`[<:tidal:1221732946525032498> Tidal ](${url})`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (url.startsWith('https://www.youtube.com/')) {
|
||||||
|
links.push(`[<:ytbm:1224704771248750622> Youtube ](${url})`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (url.startsWith('https://jelly.')) {
|
||||||
|
links.push(`[<:jelly:1225931843279519905> Jellyfin (${url.split('.')[1]}) ](${url})`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (url.startsWith('https://soundcloud.com/') || url.startsWith('https://m.soundcloud.com/')) {
|
||||||
|
links.push(`[<:soundcld:1225702702135119902> Soundcloud ](${url})`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (url.startsWith('https://open.spotify.com/')) {
|
|
||||||
url = url.split('?')[0];
|
|
||||||
links.push(`[<:sptfy:1224677302109995078> Spotify ](${url})`);
|
if(spotifyID) {
|
||||||
//https://open.spotify.com/track/4FuOHRPC3ZIQ7VQd7KMbds?si=cadd634ea5a14689
|
let spotifyTrack = await this.spotifyAPI.getTrack(spotifyID);
|
||||||
spotifyID = url.split('/').pop();
|
trackEmbed.setThumbnail(spotifyTrack['body'].album.images[0].url);
|
||||||
continue;
|
songName = spotifyTrack['body'].name;
|
||||||
|
mainArtist = spotifyTrack['body'].artists[0].name;
|
||||||
|
artists = spotifyTrack['body'].artists.map(a => a.name).join(', ');
|
||||||
|
let releaseDate = new Date(spotifyTrack['body'].album.release_date).toDateString();
|
||||||
|
description = `From the album **${spotifyTrack['body'].album.name}**\nReleased **${releaseDate}**\n\n` + description;
|
||||||
}
|
}
|
||||||
if (url.startsWith('https://listen.tidal.com/')) {
|
|
||||||
links.push(`[<:tidal:1221732946525032498> Tidal ](${url})`);
|
if(interaction.options.getAttachment('cover_override')) {
|
||||||
continue;
|
trackEmbed.setThumbnail(interaction.options.getAttachment('cover_override').url);
|
||||||
}
|
}
|
||||||
if (url.startsWith('https://www.youtube.com/')) {
|
songName = interaction.options.getString('songname', false) ?? songName;
|
||||||
links.push(`[<:ytbm:1224704771248750622> Youtube ](${url})`);
|
artists = interaction.options.getString('artist', false) ?? artists;
|
||||||
continue;
|
mainArtist = interaction.options.getString('artist', false) ?? mainArtist;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
title = `${songName} - ${artists}`;
|
||||||
|
|
||||||
if(spotifyID) {
|
trackEmbed.setTitle(`${title}`);
|
||||||
let spotifyTrack = await this.spotifyAPI.getTrack(spotifyID);
|
|
||||||
trackEmbed.setImage(spotifyTrack['body'].album.images[0].url);
|
|
||||||
songName = spotifyTrack['body'].name;
|
|
||||||
mainArtist = spotifyTrack['body'].artists[0].name;
|
|
||||||
artists = spotifyTrack['body'].artists.map(a => a.name).join(', ');
|
|
||||||
let releaseDate = new Date(spotifyTrack['body'].album.release_date).toDateString();
|
|
||||||
description = `From the album **${spotifyTrack['body'].album.name}**\nReleased **${releaseDate}**\n\n` + description;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(interaction.options.getAttachment('cover_override')) {
|
let submitterName = interaction.member.displayName;
|
||||||
trackEmbed.setImage(interaction.options.getAttachment('cover_override').url);
|
let footer = `Submitted by ${submitterName} `;
|
||||||
}
|
|
||||||
songName = interaction.options.getString('songname', false) ?? songName;
|
|
||||||
artists = interaction.options.getString('artist', false) ?? artists;
|
|
||||||
mainArtist = interaction.options.getString('artist', false) ?? mainArtist;
|
|
||||||
|
|
||||||
title = `${songName} - ${artists}`;
|
if(interaction.options.getString('rating', false)) {
|
||||||
|
|
||||||
trackEmbed.setTitle(`${title}`);
|
|
||||||
|
|
||||||
let submitterName = interaction.member.displayName;
|
|
||||||
let footer = interaction.options.getString('footer_override', false) ?? `Submitted by ${submitterName}`;
|
|
||||||
trackEmbed.setFooter({text: footer });
|
|
||||||
|
|
||||||
if(interaction.options.getString('rating', false)) {
|
|
||||||
trackEmbed.addFields(
|
|
||||||
{ name: `${submitterName} rated this`, value: `${interaction.options.getString('rating', false)} out of 10`, inline: true },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
let db = await interaction.client.localDB;
|
|
||||||
let dbResult = await db.get(`SELECT * FROM lastfm WHERE discord_id = ?`,[interaction.member.id]);
|
|
||||||
let lfmUsername = dbResult?.['lastfm_name'];
|
|
||||||
let lfmData = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${lfmKey}&artist=${mainArtist}&track=${songName}&format=json&user=${lfmUsername}`);
|
|
||||||
|
|
||||||
if(interaction.options.getInteger('scrobbles', false) || lfmData.data['track']?.['userplaycount'] > 0) {
|
|
||||||
trackEmbed.addFields(
|
|
||||||
{ name: `${submitterName} scrobbled this`, value: `${interaction.options.getInteger('scrobbles', false) ?? lfmData.data['track']['userplaycount']} times so far`, inline: true },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lfmData.data['track']) {
|
|
||||||
links.push(`<:lfm:1225099203039203338> [View on LFM](${lfmData.data['track']['url']})`);
|
|
||||||
let tags = lfmData.data['track']['toptags']['tag'].map(a => a.name).filter(tag => tag.length >= 2);
|
|
||||||
console.log(tags);
|
|
||||||
let listeners = this.numToHumanReadable(lfmData.data['track']['listeners']);
|
|
||||||
let globalScrobbles = this.numToHumanReadable(lfmData.data['track']['playcount']);
|
|
||||||
|
|
||||||
trackEmbed.addFields(
|
|
||||||
{ name: `LFM Global`, value: `Listeners: ${listeners} • Scrobbles: ${globalScrobbles}\n`, inline: false },
|
|
||||||
)
|
|
||||||
|
|
||||||
let tagHeader = 'Tags';
|
|
||||||
if(tags.length === 0) {
|
|
||||||
//artist tag fallback
|
|
||||||
let lfmArtistTags = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=artist.getTopTags&api_key=${lfmKey}&artist=${mainArtist}&format=json`);
|
|
||||||
console.log(lfmArtistTags);
|
|
||||||
tags = lfmArtistTags.data['toptags']['tag'].map(a => a.name);
|
|
||||||
tagHeader = `Artist ${tagHeader}`;
|
|
||||||
}
|
|
||||||
if(tags) {
|
|
||||||
tags = this.joinLineBreak(tags, ', ', 4);
|
|
||||||
trackEmbed.addFields(
|
trackEmbed.addFields(
|
||||||
{ name: `${tagHeader}`, value: `${tags.substr(0,60)}${tags.length > 60 ? '...' : ''}`, inline: true },
|
{ name: `${submitterName} rated this`, value: `${interaction.options.getString('rating', false)} out of **10**`, inline: true },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let db = await interaction.client.localDB;
|
||||||
|
let dbResult = await db.get(`SELECT * FROM lastfm WHERE discord_id = ?`,[interaction.member.id]);
|
||||||
|
let lfmUsername = dbResult?.['lastfm_name'];
|
||||||
|
let lfmData = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${lfmKey}&artist=${mainArtist}&track=${songName}&format=json&user=${lfmUsername}`);
|
||||||
|
|
||||||
|
if(interaction.options.getInteger('scrobbles', false) || lfmData.data['track']?.['userplaycount'] > 0) {
|
||||||
|
trackEmbed.addFields(
|
||||||
|
{ name: `${submitterName} scrobbled this`, value: `**${interaction.options.getInteger('scrobbles', false) ?? lfmData.data['track']['userplaycount']}** times so far`, inline: true },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lfmData.data['track']) {
|
||||||
|
links.push(`<:lfm:1225099203039203338> [View on LFM](${lfmData.data['track']['url']})`);
|
||||||
|
let tags = lfmData.data['track']['toptags']['tag'].map(a => a.name).filter(tag => tag.length >= 2);
|
||||||
|
console.log(tags);
|
||||||
|
let listeners = this.numToHumanReadable(lfmData.data['track']['listeners']);
|
||||||
|
let globalScrobbles = this.numToHumanReadable(lfmData.data['track']['playcount']);
|
||||||
|
footer += `∘ Listeners: ${listeners} • Scrobbles: ${globalScrobbles}`;
|
||||||
|
|
||||||
|
let tagContent = '';
|
||||||
|
if(tags.length === 0) {
|
||||||
|
//artist tag fallback
|
||||||
|
let lfmArtistTags = await axios.get(`https://ws.audioscrobbler.com/2.0/?method=artist.getTopTags&api_key=${lfmKey}&artist=${mainArtist}&format=json`);
|
||||||
|
console.log(lfmArtistTags);
|
||||||
|
tags = lfmArtistTags.data['toptags']['tag'].map(a => a.name);
|
||||||
|
}
|
||||||
|
if(tags.length > 1) {
|
||||||
|
tags = this.joinLineBreak(tags, ', ', 3);
|
||||||
|
trackEmbed.addFields(
|
||||||
|
{ name: `Tags`, value: `${tags.substr(0,60)}${tags.length > 60 ? '...' : ''}`, inline: true },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!description) {
|
||||||
|
await interaction.reply({content: 'Sorry, no valid link has bee supplied.', ephemeral: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
trackEmbed.setDescription(description);
|
||||||
|
trackEmbed.addFields(
|
||||||
|
{ name: 'Links', value: `${this.joinLineBreak(links, ' ∘ ', 4)}` }
|
||||||
|
);
|
||||||
|
|
||||||
|
trackEmbed.setFooter({text: footer });
|
||||||
|
|
||||||
|
interaction.channel.send({ embeds: [trackEmbed] });
|
||||||
|
|
||||||
|
let response = await interaction.reply({content: 'done', ephemeral: true});
|
||||||
|
await response.delete();
|
||||||
|
} catch (error) {
|
||||||
|
await interaction.reply(`# FUCK \n ${JSON.stringify(error)}`.substring(0,200));
|
||||||
}
|
}
|
||||||
|
|
||||||
description = `${description}\n${this.joinLineBreak(links, ' ∘ ', 3)}`
|
|
||||||
|
|
||||||
if(!description) {
|
|
||||||
await interaction.reply({content: 'Sorry, no valid link has bee supplied.', ephemeral: true });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
trackEmbed.setDescription(description);
|
|
||||||
|
|
||||||
interaction.channel.send({ embeds: [trackEmbed] });
|
|
||||||
|
|
||||||
let response = await interaction.reply({content: 'done', ephemeral: true});
|
|
||||||
await response.delete();
|
|
||||||
},
|
},
|
||||||
numToHumanReadable: function(num) {
|
numToHumanReadable: function(num) {
|
||||||
if (num > 1000000 ) {
|
if (num > 1000000 ) {
|
||||||
|
|||||||
@@ -1,78 +0,0 @@
|
|||||||
const db = require("../core/db");
|
|
||||||
|
|
||||||
|
|
||||||
async function fetchAnniversary(id) {
|
|
||||||
console.log(await db);
|
|
||||||
let query = await db.prepare(`SELECT * FROM anniversaries WHERE discord_id = ?`)
|
|
||||||
return await query.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
function insertNewMember(member) {
|
|
||||||
db.run(
|
|
||||||
`INSERT INTO anniversaries (name, guild_id, discord_id, last_anniversary_notification) VALUES (?, ?, ?, ?)`,
|
|
||||||
[member.user.username, member.guild.id, member.id, Date.now()],
|
|
||||||
function (error) {
|
|
||||||
if (error) {
|
|
||||||
console.error(error.message);
|
|
||||||
}
|
|
||||||
console.log(`Inserted a row with the ID: ${this.lastID}`);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAnniversary(date) {
|
|
||||||
const now = new Date("Thu Nov 11 2024");// new Date();
|
|
||||||
console.log(`${date.getDate()} - ${now.getDate()}`);
|
|
||||||
return date.getDate() === now.getDate() && date.getMonth() === now.getMonth();
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTimeSince(date) {
|
|
||||||
const now = new Date();
|
|
||||||
const diff = now - date; // `date` is already a Date object
|
|
||||||
|
|
||||||
const seconds = Math.floor(diff / 1000);
|
|
||||||
const minutes = Math.floor(seconds / 60);
|
|
||||||
const hours = Math.floor(minutes / 60);
|
|
||||||
const days = Math.floor(hours / 24);
|
|
||||||
const weeks = Math.floor(days / 7);
|
|
||||||
const months = Math.floor(days / 30);
|
|
||||||
const years = Math.floor(days / 365);
|
|
||||||
|
|
||||||
if (years > 0) return `${years} years ago`;
|
|
||||||
if (months > 0) return `${months} months ago`;
|
|
||||||
if (weeks > 0) return `${weeks} weeks ago`;
|
|
||||||
if (days > 0) return `${days} days ago`;
|
|
||||||
if (hours > 0) return `${hours} hours ago`;
|
|
||||||
if (minutes > 0) return `${minutes} minutes ago`;
|
|
||||||
return `${seconds} seconds ago`;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
timeout: 60000,
|
|
||||||
immediate: true,
|
|
||||||
name: 'Daily member anniversary check',
|
|
||||||
|
|
||||||
async tick(client, timer) {
|
|
||||||
return;
|
|
||||||
console.log(`[TIMER] Anniversary Check`);
|
|
||||||
let debugChannel = await client.channels.fetch('1214134516247957504');
|
|
||||||
|
|
||||||
let subscribedChannels = [
|
|
||||||
{ guild: '442059309581336578', channel: '1214134516247957504' } //toho-test
|
|
||||||
]
|
|
||||||
|
|
||||||
for (let channelIndex = 0; channelIndex < subscribedChannels.length; channelIndex++) {
|
|
||||||
const guild = await client.guilds.fetch(subscribedChannels[channelIndex].guild);
|
|
||||||
const channel = await client.channels.fetch(subscribedChannels[channelIndex].channel);
|
|
||||||
let guildMembers = await guild.members.fetch();
|
|
||||||
guildMembers.forEach(member => {
|
|
||||||
if(isAnniversary(member.joinedAt)) {
|
|
||||||
//debugChannel.send(`Upcoming anniversary ${member.displayName} ${member.joinedAt} ${getTimeSince(member.joinedAt)}`);
|
|
||||||
console.log(`User anniversary ${member.displayName} ${member.joinedAt} ${getTimeSince(member.joinedAt)}`);
|
|
||||||
let dbEntry = fetchAnniversary(member.id);
|
|
||||||
console.log(dbEntry);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user