mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 15:07:42 +02:00
Integrate meme-poster into Xiao
This commit is contained in:
@@ -6,6 +6,9 @@ XIAO_PREFIX=
|
||||
INVITE=
|
||||
XIAO_WEBHOOK_ID=
|
||||
XIAO_WEBHOOK_TOKEN=
|
||||
POSTER_ID=
|
||||
POSTER_TOKEN=
|
||||
POSTER_TIME=
|
||||
|
||||
# Emoji IDs
|
||||
GOLD_FISH_EMOJI_ID=
|
||||
|
||||
@@ -55,7 +55,6 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
|
||||
* [Rando Cardrissian](https://github.com/dragonfire535/rando-cardrissian) is a Cards Against Humanity bot, whose features were originally built into Xiao.
|
||||
* [Storyteller](https://github.com/dragonfire535/storyteller) is a Mafia bot made for Discord's 2019 Hack Week, whose features were originally built into Xiao.
|
||||
* [Meme Poster](https://github.com/dragonfire535/meme-poster) is a meme-posting webhook, inspired by an idea that started as part of Xiao.
|
||||
|
||||
## Commands (348)
|
||||
### Utility:
|
||||
|
||||
@@ -46,6 +46,7 @@ client.on('ready', () => {
|
||||
const activity = activities[Math.floor(Math.random() * activities.length)];
|
||||
client.user.setActivity(activity.text, { type: activity.type });
|
||||
}, 60000);
|
||||
client.setInterval(() => client.memePoster.post(), client.memePoster.time);
|
||||
});
|
||||
|
||||
client.on('guildMemberRemove', async member => {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "107.7.5",
|
||||
"version": "107.8.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -2,6 +2,7 @@ const { CommandoClient } = require('discord.js-commando');
|
||||
const { WebhookClient } = require('discord.js');
|
||||
const winston = require('winston');
|
||||
const PokemonStore = require('./pokemon/PokemonStore');
|
||||
const MemePoster = require('./MemePoster');
|
||||
const { XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN } = process.env;
|
||||
|
||||
module.exports = class XiaoClient extends CommandoClient {
|
||||
@@ -17,6 +18,7 @@ module.exports = class XiaoClient extends CommandoClient {
|
||||
});
|
||||
this.webhook = new WebhookClient(XIAO_WEBHOOK_ID, XIAO_WEBHOOK_TOKEN, { disableEveryone: true });
|
||||
this.pokemon = new PokemonStore();
|
||||
this.memePoster = new MemePoster(this);
|
||||
this.games = new Map();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
const { POSTER_ID, POSTER_TOKEN, POSTER_TIME } = process.env;
|
||||
const request = require('node-superfetch');
|
||||
const subreddits = require('../assets/json/meme');
|
||||
const types = ['image', 'rich:video'];
|
||||
|
||||
module.exports = class MemePoster {
|
||||
constructor(client) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
this.id = POSTER_ID;
|
||||
this.token = POSTER_TOKEN;
|
||||
this.time = Number.parseFloat(POSTER_TIME) || 3.6e+6;
|
||||
}
|
||||
|
||||
async post() {
|
||||
try {
|
||||
const subreddit = subreddits[Math.floor(Math.random() * subreddits.length)];
|
||||
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 types.includes(post.data.post_hint) && post.data.url && post.data.title && !post.data.over_18;
|
||||
});
|
||||
if (!posts.length) return;
|
||||
const post = posts[Math.floor(Math.random() * posts.length)].data;
|
||||
await request
|
||||
.post(`https://discordapp.com/api/webhooks/${this.id}/${this.token}`)
|
||||
.send({
|
||||
content: `**r/${subreddit}** [${post.title}](<https://www.reddit.com${post.permalink}>)\n${post.url}`
|
||||
});
|
||||
} catch (err) {
|
||||
this.client.logger.error(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user