Skip to content

Commit

Permalink
feat: add meme slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev committed Mar 19, 2022
1 parent 81557e3 commit bd613bc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
44 changes: 44 additions & 0 deletions interactions/commands/meme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const Snoowrap = require('snoowrap');
const reddit = new Snoowrap({
userAgent: 'gasbot',
clientId: process.env.REDDIT_CLIENT_ID,
clientSecret: process.env.REDDIT_TOKEN,
refreshToken: process.env.REDDIT_REFRESH
});

module.exports = {
name: 'meme',

async execute(client, interaction) {
const subreddits = ['memes', 'dankmemes', 'comedynecrophilia', 'theletterh', 'okbuddyretard', '196', 'comedyheaven'];
const randomSubreddit = subreddits[Math.floor(Math.random() * subreddits.length)];

const listing = (await reddit.getHot(randomSubreddit)).filter(p => !p.over_18 && p.is_reddit_media_domain && !p.is_video);
const post = listing[Math.floor(Math.random() * listing.length)];

interaction.reply({
embeds: [{
title: post.title.replaceAll(/g/giu, 'q'),
url: `https://reddit.com${post.permalink}`,
image: post.preview.images[0].variants.gif?.source ?? post.preview.images[0].source,
author: {
name: post.subreddit_name_prefixed
},
footer: {
text: `u/${post.author.name}`
},
timestamp: post.created * 1000,
color: client.config.color
}],
components: [{
type: 'ACTION_ROW',
components: [{
type: 'BUTTON',
style: 'SECONDARY',
label: 'Refresh',
customId: `meme::${interaction.user.id}`
}]
}]
});
}
};
35 changes: 35 additions & 0 deletions interactions/components/meme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const Snoowrap = require('snoowrap');
const reddit = new Snoowrap({
userAgent: 'gasbot',
clientId: process.env.REDDIT_CLIENT_ID,
clientSecret: process.env.REDDIT_TOKEN,
refreshToken: process.env.REDDIT_REFRESH
});

module.exports = {
name: 'meme',

async execute(client, interaction) {
const subreddits = ['memes', 'dankmemes', 'comedynecrophilia', 'theletterh', 'okbuddyretard', '196', 'comedyheaven'];
const randomSubreddit = subreddits[Math.floor(Math.random() * subreddits.length)];

const listing = (await reddit.getHot(randomSubreddit)).filter(p => !p.over_18 && p.is_reddit_media_domain && !p.is_video);
const post = listing[Math.floor(Math.random() * listing.length)];

interaction.update({
embeds: [{
title: post.title.replaceAll(/g/giu, 'q'),
url: `https://reddit.com${post.permalink}`,
image: post.preview.images[0].variants.gif?.source ?? post.preview.images[0].source,
author: {
name: post.subreddit_name_prefixed
},
footer: {
text: `u/${post.author.name}`
},
timestamp: post.created * 1000,
color: client.config.color
}]
});
}
};

0 comments on commit bd613bc

Please sign in to comment.