Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Add story command #42

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SpookyBot
🎃 *A spooky Discord bot*

🎃 _A spooky Discord bot_

[![release](https://img.shields.io/github/release/LucasCtrl/spookyBot.svg?style=flat-square&logo=github&logoColor=fafafa&colorA=191b25&colorB=32cb8b)](https://github.com/LucasCtrl/spookyBot/releases/latest)
[![issues](https://img.shields.io/github/issues/LucasCtrl/spookyBot.svg?style=flat-square&colorA=191b25)](https://github.com/LucasCtrl/spookyBot/issues)
Expand All @@ -8,11 +9,11 @@

This project is convenient for people who want to get into open source and contribute to different projects especially during the Hacktoberfest.

*Don't hesitate to ask me for help on my [Discord server](https://discord.gg/nEDcagb), I would help you with great pleasure!*
_Don't hesitate to ask me for help on my [Discord server](https://discord.gg/nEDcagb), I would help you with great pleasure!_

## 🤖 Add the bot on your server

You just need to click on [this link](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141124160) and validate the form without changing any permission.
You just need to click on [this link](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141140544) and validate the form without changing any permission.

## 🌐 Adding a language

Expand All @@ -33,29 +34,41 @@ To react to a word, you need two elements in the translation file: the word and
You can see that the `emoji` element is an emoji, but you can also use a custom emoji. For that, I strongly advise you to [read this guide](https://discordjs.guide/popular-topics/reactions.html#custom-emojis).

## 💻 Testing locally

1. Create a bot [on the Discord developer portal](https://discord.com/developers/applications),
2. Create a webhook on your own discord server [by following this tutorial](https://docs.gitlab.com/ee/user/project/integrations/discord_notifications.html),
3. Copy the `./app/config/config.example.json` from the project to `./app/config/config.json` and fill in the gaps with the information from the bot and the webhook. The first token is on the bot page accessed from the side of the Discord Developer Portal, and the webook information is found on the page when you navigate to the webhook url,
4. Invite your dev bot to your server by [following this url](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141124160), replacing the client id with your bot's client id (found on it's general information page), and the permissions with the Permission Integer created in the Developer Portal as you select permissions for your bot,
3. Copy the `./app/config/config.example.json` from the project to `./app/config/config.json` and fill in the gaps with the information from the bot and the webhook. The first token is on the bot page accessed from the side of the Discord Developer Portal, and the webhook information is found on the page when you navigate to the webhook url,
4. Invite your dev bot to your server by [following this url](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141140544), replacing the client id with your bot's client id (found on it's general information page), and the permissions with the Permission Integer created in the Developer Portal as you select permissions for your bot,
5. Once these steps are setup, simply run `make startup_dev` from the terminal in the root directory of the repo,
5.1 If you want to install node modules you could just add it into your local package.json and run the `make build_dev_image` after that you need to recreate the container.
5.1 If you want to install node modules you could just add it into your local package.json and run the `make build_dev_image` after that you need to recreate the container.
6. Test the bot is connected by running `<your-prefix>help` to get a list of commands, and then initialize the DB by running `<your-prefix>emitgc`. It should then respond with "Join <your-server> with <#> users,
7. Test that the bot reacts to comments by typing one of the words in `lang/<your-lang>.js`. The bot should respond with an emoji!

### Optional: testing boo!story

1. Create a Reddit app [at for Reddit Authorized Applications](https://www.reddit.com/prefs/apps) and use the following settings:
- type: web-app
- redirect uri: `http://localhost:65010/authorize_callback`
- free choice for other fields
2. Use the [reddit-oauth-helper](https://github.com/not-an-aardvark/reddit-oauth-helper) to generate a permanent token.
3. Fill in the gaps for the `reddit` config in `./app/config/config.json`. Values can be found in the Reddit App and the generated token.

## 👤 Author

**LucasAlt**
* Website: https://www.lucasalt.fr
* Twitter: [@LucasCtrlAlt](https://twitter.com/LucasCtrlAlt)
* GitHub: [@LucasCtrl](https://github.com/LucasCtrl)

- Website: https://www.lucasalt.fr
- Twitter: [@LucasCtrlAlt](https://twitter.com/LucasCtrlAlt)
- GitHub: [@LucasCtrl](https://github.com/LucasCtrl)

## 🙏 Thanks
* [**@ALMerrill**](https://github.com/ALMerrill) - Translation (es, de), code, documentation
* [**@marc2332**](https://github.com/marc2332) - Translation (es, ca)
* [**@tmetten**](https://github.com/tmetten) - Translation (nl)
* [**@dragonDScript**](https://github.com/dragonDScript) - Translation (ca)
* [**@Pervolarakis**](https://github.com/Pervolarakis) - Translation (gr)
* [And many more!](https://github.com/LucasCtrl/spookyBot/graphs/contributors)

- [**@ALMerrill**](https://github.com/ALMerrill) - Translation (es, de), code, documentation
- [**@marc2332**](https://github.com/marc2332) - Translation (es, ca)
- [**@tmetten**](https://github.com/tmetten) - Translation (nl)
- [**@dragonDScript**](https://github.com/dragonDScript) - Translation (ca)
- [**@Pervolarakis**](https://github.com/Pervolarakis) - Translation (gr)
- [And many more!](https://github.com/LucasCtrl/spookyBot/graphs/contributors)

## 🤝 Contributing

Expand Down
2 changes: 1 addition & 1 deletion app/commands/Info/invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
.setColor(colors.primary)
.setAuthor('Invitation link', bot.user.avatarURL())
.setDescription(
'You can click on the following link for adding the bot on your server: [https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141124160](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141124160)'
'You can click on the following link for adding the bot on your server: [https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141140544](https://discord.com/oauth2/authorize?client_id=761568927188123669&scope=bot&permissions=1141124160)'
)

message.channel.send(embed)
Expand Down
51 changes: 51 additions & 0 deletions app/commands/Text/story.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const snoowrap = require('snoowrap')
const { MessageEmbed } = require('discord.js')
const { prefix, reddit } = require('../../config.json')

let antiSpam = {}

module.exports = {
config: {
name: 'Scary story',
usage: `${prefix}story`,
description: 'Tell a scary story (from reddit.com/r/scarystories)',
command: 'story',
aliases: ['ghoststory', 'tale'],
displayHelp: false,
},

run: async (bot, message, args) => {
if (!reddit || !reddit.userAgent || !reddit.clientId || !reddit.clientSecret || !reddit.refreshToken) {
message.author.send("I can't tell you a story, no Reddit config provided.")
} else {
const retriever = new snoowrap({
userAgent: reddit.userAgent,
clientId: reddit.clientId,
clientSecret: reddit.clientSecret,
refreshToken: reddit.refreshToken,
})

const stories = await retriever.getSubreddit('scarystories').getHot()
const story = stories[[Math.floor(Math.random() * stories.length)]]
const isSpamProtected = antiSpam[message.channel.id] && new Date() - antiSpam[message.channel.id] < 2 * 60000

story.selftext.match(/(.|[\r\n]){1,2048}/g).forEach((storyPart, partIndex, parts) => {
let embed = new MessageEmbed()
.setColor('881EE4')
.setTitle(`${story.title} (${partIndex + 1}/${parts.length})`)
.setDescription(storyPart)
.setFooter(`Author: ${story.author.name}`)

isSpamProtected ? message.author.send(embed) : message.channel.send(embed)
})

if (isSpamProtected) {
message.author.send(
':warning: Due to spam protection I sent you this story as a DM. I only write stories in channels every 2 minutes.'
)
} else {
antiSpam[message.channel.id] = new Date()
}
}
},
}
8 changes: 7 additions & 1 deletion app/config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
"success": "#2ECC71",
"error": "#E74C3C",
"info": "#7C5398"
},
"reddit": {
"userAgent": "SpookyBot, a Discord bot to celebrate Halloween",
"clientId": "",
"clientSecret": "",
"refreshToken": ""
}
}
}
Loading