mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-07 06:45:31 +02:00
Remove Meme Poster Webhook
This commit is contained in:
@@ -10,16 +10,11 @@ const Font = require('./Font');
|
||||
const PhoneManager = require('./phone/PhoneManager');
|
||||
const TimerManager = require('./remind/TimerManager');
|
||||
const PokemonStore = require('./pokemon/PokemonStore');
|
||||
const MemePosterClient = require('./MemePoster');
|
||||
const activities = require('../assets/json/activity');
|
||||
const leaveMsgs = require('../assets/json/leave-messages');
|
||||
const subreddits = require('../assets/json/meme');
|
||||
const {
|
||||
XIAO_WEBHOOK_ID,
|
||||
XIAO_WEBHOOK_TOKEN,
|
||||
POSTER_ID,
|
||||
POSTER_TOKEN,
|
||||
POSTER_TIME,
|
||||
REPORT_CHANNEL_ID,
|
||||
JOIN_LEAVE_CHANNEL_ID
|
||||
} = process.env;
|
||||
@@ -41,12 +36,6 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
this.timers = new TimerManager(this);
|
||||
this.blacklist = { guild: [], user: [] };
|
||||
this.pokemon = new PokemonStore();
|
||||
this.memePoster = POSTER_ID && POSTER_TOKEN ? new MemePosterClient(POSTER_ID, POSTER_TOKEN, {
|
||||
subreddits,
|
||||
postTypes: ['image', 'rich:video'],
|
||||
postInterval: POSTER_TIME,
|
||||
disableMentions: 'everyone'
|
||||
}) : null;
|
||||
this.games = new Collection();
|
||||
this.dispatchers = new Map();
|
||||
this.phone = new PhoneManager(this);
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
const { WebhookClient } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { embedURL } = require('../util/Util');
|
||||
|
||||
module.exports = class MemePosterClient extends WebhookClient {
|
||||
constructor(id, token, options) {
|
||||
super(id, token, options);
|
||||
|
||||
this.subreddits = options.subreddits;
|
||||
this.postTypes = options.postTypes;
|
||||
this.postInterval = options.postInterval ? Number.parseFloat(options.postInterval) : 3.6e+6;
|
||||
}
|
||||
|
||||
post(post) {
|
||||
const url = embedURL(post.title, `<https://www.reddit.com${post.permalink}>`);
|
||||
return this.send(`**r/${post.subreddit}** ${url}\n${post.url}`);
|
||||
}
|
||||
|
||||
async fetchRandomPost(nsfw) {
|
||||
const subreddit = this.randomSubreddit();
|
||||
const post = await this.fetchPost(subreddit, nsfw);
|
||||
return {
|
||||
subreddit,
|
||||
title: post.title,
|
||||
url: post.url,
|
||||
permalink: post.permalink,
|
||||
type: post.post_hint,
|
||||
nsfw: post.over_18 || false
|
||||
};
|
||||
}
|
||||
|
||||
async fetchPost(subreddit, nsfw) {
|
||||
const { body } = await request
|
||||
.get(`https://www.reddit.com/r/${subreddit}/hot.json`)
|
||||
.query({ limit: 100 });
|
||||
const posts = body.data.children.filter(post => {
|
||||
if (!post.data) return false;
|
||||
return this.postTypes.includes(post.data.post_hint)
|
||||
&& post.data.url
|
||||
&& post.data.title
|
||||
&& nsfw ? true : !post.data.over_18;
|
||||
});
|
||||
if (!posts.length) return null;
|
||||
return posts[Math.floor(Math.random() * posts.length)].data;
|
||||
}
|
||||
|
||||
randomSubreddit() {
|
||||
return this.subreddits[Math.floor(Math.random() * this.subreddits.length)];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user