Compare commits
7 Commits
anniversar
...
2e4147abec
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e4147abec | |||
| fbdcef7bca | |||
| f29abd9df4 | |||
| f55bd3d98a | |||
| e957444000 | |||
| a1c22295f6 | |||
| 4e1ec14272 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ node_modules/
|
||||
config.json
|
||||
old/
|
||||
bot.log
|
||||
data/
|
||||
|
||||
@@ -63,7 +63,7 @@ module.exports = {
|
||||
|
||||
collector.on('collect', m => {
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,10 +41,6 @@ module.exports = {
|
||||
option.setName('songname')
|
||||
.setDescription('Override song name, otherwise uses name from Spotify')
|
||||
.setRequired(false))
|
||||
.addStringOption(option =>
|
||||
option.setName('footer_override')
|
||||
.setDescription('Custom footer')
|
||||
.setRequired(false))
|
||||
.addAttachmentOption(option =>
|
||||
option.setName('cover_override')
|
||||
.setDescription('Uses this image instead of Spotofy metadata')
|
||||
@@ -54,6 +50,7 @@ module.exports = {
|
||||
clientSecret: spotify.clientSecret,
|
||||
}),
|
||||
async execute(interaction) {
|
||||
try {
|
||||
let token = await this.spotifyAPI.clientCredentialsGrant().then(
|
||||
function(data) {
|
||||
return data.body['access_token'];
|
||||
@@ -97,12 +94,20 @@ module.exports = {
|
||||
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(spotifyID) {
|
||||
let spotifyTrack = await this.spotifyAPI.getTrack(spotifyID);
|
||||
trackEmbed.setImage(spotifyTrack['body'].album.images[0].url);
|
||||
trackEmbed.setThumbnail(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(', ');
|
||||
@@ -111,7 +116,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if(interaction.options.getAttachment('cover_override')) {
|
||||
trackEmbed.setImage(interaction.options.getAttachment('cover_override').url);
|
||||
trackEmbed.setThumbnail(interaction.options.getAttachment('cover_override').url);
|
||||
}
|
||||
songName = interaction.options.getString('songname', false) ?? songName;
|
||||
artists = interaction.options.getString('artist', false) ?? artists;
|
||||
@@ -122,12 +127,11 @@ module.exports = {
|
||||
trackEmbed.setTitle(`${title}`);
|
||||
|
||||
let submitterName = interaction.member.displayName;
|
||||
let footer = interaction.options.getString('footer_override', false) ?? `Submitted by ${submitterName}`;
|
||||
trackEmbed.setFooter({text: footer });
|
||||
let footer = `Submitted by ${submitterName} `;
|
||||
|
||||
if(interaction.options.getString('rating', false)) {
|
||||
trackEmbed.addFields(
|
||||
{ name: `${submitterName} rated this`, value: `${interaction.options.getString('rating', false)} out of 10`, inline: true },
|
||||
{ name: `${submitterName} rated this`, value: `${interaction.options.getString('rating', false)} out of **10**`, inline: true },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -138,7 +142,7 @@ module.exports = {
|
||||
|
||||
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 },
|
||||
{ name: `${submitterName} scrobbled this`, value: `**${interaction.options.getInteger('scrobbles', false) ?? lfmData.data['track']['userplaycount']}** times so far`, inline: true },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -148,28 +152,23 @@ module.exports = {
|
||||
console.log(tags);
|
||||
let listeners = this.numToHumanReadable(lfmData.data['track']['listeners']);
|
||||
let globalScrobbles = this.numToHumanReadable(lfmData.data['track']['playcount']);
|
||||
footer += `∘ Listeners: ${listeners} • Scrobbles: ${globalScrobbles}`;
|
||||
|
||||
trackEmbed.addFields(
|
||||
{ name: `LFM Global`, value: `Listeners: ${listeners} • Scrobbles: ${globalScrobbles}\n`, inline: false },
|
||||
)
|
||||
|
||||
let tagHeader = 'Tags';
|
||||
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);
|
||||
tagHeader = `Artist ${tagHeader}`;
|
||||
}
|
||||
if(tags) {
|
||||
tags = this.joinLineBreak(tags, ', ', 4);
|
||||
if(tags.length > 1) {
|
||||
tags = this.joinLineBreak(tags, ', ', 3);
|
||||
trackEmbed.addFields(
|
||||
{ name: `${tagHeader}`, value: `${tags.substr(0,60)}${tags.length > 60 ? '...' : ''}`, inline: true },
|
||||
{ name: `Tags`, value: `${tags.substr(0,60)}${tags.length > 60 ? '...' : ''}`, inline: true },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
description = `${description}\n${this.joinLineBreak(links, ' ∘ ', 3)}`
|
||||
}
|
||||
|
||||
if(!description) {
|
||||
await interaction.reply({content: 'Sorry, no valid link has bee supplied.', ephemeral: true });
|
||||
@@ -177,11 +176,20 @@ module.exports = {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
},
|
||||
numToHumanReadable: function(num) {
|
||||
if (num > 1000000 ) {
|
||||
|
||||
50
timers/receiptTimer.js
Normal file
50
timers/receiptTimer.js
Normal file
@@ -0,0 +1,50 @@
|
||||
module.exports = {
|
||||
timeout: 1000,
|
||||
immediate: false,
|
||||
name: 'Receipt Day Announcements',
|
||||
data: {
|
||||
channelId: '1462060674766344370',
|
||||
targetHour: 0,
|
||||
targetMinute: 1
|
||||
},
|
||||
async tick(client, timer) {
|
||||
try {
|
||||
// 1. Send the message
|
||||
const currentDate = new Date().toLocaleDateString('en-GB', {
|
||||
weekday: 'long',
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric'
|
||||
});
|
||||
const channel = await client.channels.fetch(timer.data.channelId);
|
||||
if (channel) await channel.send(`Today is ${currentDate}`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('[TIMER] Error:', error);
|
||||
} finally {
|
||||
// 2. Schedule the NEXT tick manually
|
||||
this.scheduleNext(client, timer);
|
||||
}
|
||||
},
|
||||
|
||||
scheduleNext(client, timer) {
|
||||
const now = new Date();
|
||||
const next = new Date();
|
||||
|
||||
next.setHours(timer.data.targetHour, timer.data.targetMinute, 0, 0);
|
||||
|
||||
if (next <= now) {
|
||||
next.setDate(next.getDate() + 1);
|
||||
}
|
||||
|
||||
const delay = next.getTime() - now.getTime();
|
||||
|
||||
if (timer.instance) clearTimeout(timer.instance);
|
||||
|
||||
timer.instance = setTimeout(() => {
|
||||
this.tick(client, timer);
|
||||
}, delay);
|
||||
|
||||
console.log(`[TIMER] Next message scheduled for: ${next.toLocaleString()}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user