Skip to content

Commit

Permalink
Push some files needed for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimShadyIAm committed Mar 31, 2022
1 parent eb484dc commit 5c56f13
Show file tree
Hide file tree
Showing 7 changed files with 344 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mongo_data/
37 changes: 37 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
BLOO_TOKEN="your token here"

MAIN_GUILD_ID=12345
OWNER_ID=12345 # The ID of the owner of the bot, grants all permissions
AARON_ID=123 # ID of whoever owns the server, needed for permissions

DB_HOST="host.docker.internal" # **Read the README to see what this should be set to!**
DB_PORT=27017 # Whatever port Mongo is running on. 27017 is the default.

# this is optional, set this to True to disable mod pings for reports
# if you don't want it or are running the bot in production,
# DELETE THE LINE, don't set it to False.
DEV=True

# this is optional, if you want ban appeal form support.
# delete this section if you don't want it.
BAN_APPEAL_URL="" # link to the ban appeal form
BAN_APPEAL_GUILD_ID=12345 # link to the ban appeals server
BAN_APPEAL_MOD_ROLE=12345 # role ID of the mod role in ban appeals server

# this is optional if you want logging and errors to be sent to a Discord webhook
LOGGING_WEBHOOK_URL=""

# this is optional, for /sabbath command.
# you probably don't need it. delete it if so.
AARON_ROLE=123

# optional, used for automatically uploading tweak lists to paste.ee
PASTEE_TOKEN="your API key here"

# optional, for /neural_net meme command.
# you need access to this. ask SlimShadyIAm for it.
RESNEXT_TOKEN="your token here"

# optional
# enable /memegen text and /memegen aipfp commands
# ENABLE_MARKOV=True
21 changes: 21 additions & 0 deletions Dockerfile.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# syntax=docker/dockerfile:1

FROM python:3.10.2-slim-bullseye
WORKDIR /usr/src/app

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# system dependencies
RUN apt-get update
RUN apt-get upgrade -y
RUN apt install -y git gcc python3-dev

# python dependencies
COPY ./requirements.txt .
COPY . .
RUN pip install --upgrade pip setuptools wheel
RUN pip install -r requirements.txt

CMD ["python", "-u", "main.py"]
131 changes: 130 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,130 @@
Bloo2
# Bloo
Bloo is a sophisticated moderation and miscellaneous utilities Discord bot created for the [r/Jailbreak Discord server](https://reddit.com/r/jailbreak). It features:

- Completely based on Discord's Slash Commands, written in the [Discord.py library](https://github.com/Rapptz/discord.py)
- Standard moderation commands such as warn, mute, kick, ban, ...
- XP and role-based permissions system
- An advanced filter and anti-raid system
- A logging and message mirroring system
- Self-assignable roles
- Miscellaneous utilities like `/canijailbreak`
- And much more!

Bloo is custom made for the r/Jailbreak server and therefore there is no publicly running bot you can invite to your own server. However, you can self-host it as is or fork the code and modify it to your own requirements!

---

## Pre-setup instructions
These instructions *should* work on macOS, Windows and Linux.

### Setting up the `.env` file
1. Copy the `.env.example` to a file called `.env`
2. Start filling in the values as you want it set up. Follow the comments for hints.
3. For the `DB_HOST` variable:
- If running the bot without Docker (not recommended), you can change `DB_HOST` to `localhost` instead.
- If running Mongo without Docker, `host.docker.internal` works on macOS and Windows, on Linux you can use `172.17.0.1`.
- If running Mongo in Docker, set `DB_HOST` to `mongo`

> **NOT RECOMMENDED FOR PRODUCTION DUE TO POOR PERFORMANCE**
Optionally, you can use [MongoDB Atlas](https://www.mongodb.com/atlas/database) instead of a local Mongo server, or you can ask SlimShadyIAm on Discord for access to the shared test database. In that case, you use:
`DB_CONNECTION_STRING=mongodb+srv://.....` instead of `DB_HOST` and `DB_PORT`.

## Setting up the bot

### Production setup
This setup uses Docker for deployment. You will need the following:
- Docker
- `docker-compose`
- Mongo installation (optional, but recommended because it makes the setup easier. Advanced uses can also run Mongo in Docker, follow the instructions in `docker-compose.yml`).

> Alternatively, you could set up the bot without Docker using PM2 but I won't provide instructions for that.
#### Steps
1. Set up the `.env`. file. Keep in mind whether or not you want to use Mongo in Docker or not.
2. Set up the database.
3. Skip this step if running Mongo without Docker. If you want to run Mongo in Docker, you will need to edit `docker-compose.yml` slightly. Open it and follow the comments.
4. Run the bot using `docker-compose up -d --build`.

If everything is successful, the bot should be online in a few seconds. Otherwise, check the container's logs: `docker-compose logs bloo`.

The bot can be updated in the future by running: `git pull && docker-compose up -d --build --force-recreate`

---

### Development setup: with Docker (recommended!)
You will need the following installed:
- Docker
- Visual Studio Code to run the development container
- MongoDB running on the host machine or [MongoDB Atlas](https://www.mongodb.com/atlas/database).

#### Steps
1. Clone the repository and open the folder in Visual Studio Code
2. Install the [Microsoft Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) plugin
3. Make sure that Docker is running
4. Open the Command Palette (`CMD+Shift+P` or `CTRL+Shift+P`) and run "Remote-Containers: Reopen In Container"
5. VSCode should build the Docker image and open it automatically; this may take a couple of minutes as it has to install some extensions as well.
6. Set up the `.env` file as shown [here](#env-file).
7. Make sure the database is set up (see below).
8. Open the integrated terminal in VSCode and run the `bloo` command to start the bot with hot reload!

> Note that if you make changes to the `Dockerfile`, `.devcontainer.json`, or need to install a new requirement, you need to rebuild the Docker image. You can do this through the Command Palette again, run "Remote-Containers: Rebuild Container".
---

### Development setup: without Docker (not recommended)
You will need the following installed:
- `python3.9+`
- `venv` (Python's virtualenv module)
- MongoDB running on the host machine or [MongoDB Atlas](https://www.mongodb.com/atlas/database).

#### Steps
1. Inside the root folder of the project, run `python3 -m venv venv/`
2. `source venv/bin/activate`
3. `pip3 install -r requirements.txt`
4. Set up the .env file as shown [here](#env-file).
5. Make sure the database is set up (see below).
6. `python3 main.py`

---

### Database setup
If you have an existing dump of the database, make sure Mongo is running, then you can run `mongorestore <dump foldername>`. This can also be done if running Mongo in Docker by first copying the dump to the Mongo container with `docker cp`.

If setting up the database from scratch, follow these instructions:
1. Make sure you filled out the right values for the `.env` file as explained above.
2. Open up `setup.py` and fill in **ALL** the values. The bot's permissions, and as a result the bot itself, will not work without them.
3. Run `setup.py`:
- If running the bot without Docker, follow the first few setup instructions until you need to set up the database, activate the `virtualenv` and then run `python3 setup.py`. Then you can proceed with the rest of the setup instructions.
- If running the bot with Docker in production, start the container then run: `docker exec -it <Bloo container name> python3 setup.py` (if you get an error about the container restarting, restart the container and try to run the command again immediately). You can find the container name by running `docker container ls` in the project folder. After it's setup, restart the container. **Note:** changes to `setup.py` won't be transferred until you rebuild the container. So build the container AFTER `setup.py` is set up how you want.
- If running the bot with Docker in development, you can just run `python3 setup.py` in the integrated bash shell.

If you want to inspect or change database values:
- If running MongoDB locally, you can install Robo3T.
- If running MongoDB in Docker, you can use the web GUI at http://127.0.0.1:8081

---

## Contributors

<table>
<tr>
<td align="center"><a href="https://aamirfarooq.dev"><img src="https://avatars.githubusercontent.com/u/10660846?v=4" width="100px;" alt=""/><br /><sub><b>SlimShadyIAm</b></sub></a></td>
<td align="center"><a href="https://github.com/stekc"><img src="https://avatars.githubusercontent.com/u/57512084?v=4" width="100px;" alt=""/><br /><sub><b>stekc</b></sub></a></td>
<td align="center"><a href="https://github.com/Ultra03"><img src="https://avatars.githubusercontent.com/u/20672260?v=4" width="100px;" alt=""/><br /><sub><b>Ultra03</b></sub></a></td>
<td align="center"><a href="https://github.com/ja1dan"><img src="https://avatars.githubusercontent.com/u/37126748?v=4" width="100px;" alt=""/><br /><sub><b>ja1dan</b></sub></a></td>
<td align="center"><a href="https://github.com/donato-fiore"><img src="https://avatars.githubusercontent.com/u/50346119?v=4" width="100px;" alt=""/><br /><sub><b>donato-fiore</b></sub></a></td>
</tr>
<tr>
<td align="center"><a href="https://m1sta.xyz/"><img src="https://avatars.githubusercontent.com/u/37033149?v=4" width="100px;" alt=""/><br /><sub><b>m1stadev</b></sub></a></td>
<td align="center"><a href="https://saadat.dev/"><img src="https://avatars.githubusercontent.com/u/41216857?v=4" width="100px;" alt=""/><br /><sub><b>mass1ve-err0r</b></sub></a></td>
<td align="center"><a href="https://github.com/sqlstatement"><img src="https://avatars.githubusercontent.com/u/27446425?v=4" width="100px;" alt=""/><br /><sub><b>sqlstatement</b></sub></a></td>
<td align="center"><a href="https://github.com/beerpiss"><img src="https://avatars.githubusercontent.com/u/92439990?v=4" width="100px;" alt=""/><br /><sub><b>beerpsi</b></sub></a></td>
</tr>
</table>

### Special thanks
Special thanks to the following people for ideas, testing, or help:
- [Jack LaFond](https://www.jack.link/) --- creator of [tunes.ninja](https://tunes.ninja/), the bot that the Songs cog is inspired by
- Cameren from r/jb, who has given a lot of ideas and helped with testing on many occasions
- [Lillie](https://github.com/LillieWeeb001/) --- creator of the [fake jailbreak and iCloud bypass list](https://github.com/LillieWeeb001/Anti-Scam-Json-List) used by Bloo's filter
- [Emma](https://github.com/emiyl) and the https://ios.cfw.guide team --- their API is used for miscellaneous commands such as `/canijailbreak`, `/deviceinfo`, `/devices add`, `/bypass` and more.
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3.4'

services:
bloo:
container_name: bloo
build:
context: .
dockerfile: Dockerfile.production
network: host # comment this out if you want to use dockerized mongo
restart: always
network_mode: host # comment this out if you want to use dockerized mongo
# also, if you want to use dockerized Mongo you need to change DB_HOST to "mongo" in .env

#####
##### uncomment the following to use dockerized mongo
# depends_on:
# - mongo
# mongo:
# image: mongo
# restart: unless-stopped
# environment:
# - MONGO_DATA_DIR=/data/db
# - MONGO_LOG_DIR=/dev/null
# volumes:
# - ./mongo_data:/data/db


# #### This is optional if you want a GUI to manage your database
# #### Only applicable with Dockerized mongo
# #### If you run this, USE A FIREWALL or the database will be accessible from the internet
# ### The database is running in unauthenticated mode.

# mongo-express:
# image: mongo-express
# restart: unless-stopped
# depends_on:
# - mongo
# ports:
# - 8081:8081
# environment:
# ME_CONFIG_MONGODB_URL: mongodb://mongo:27017/
34 changes: 34 additions & 0 deletions scrape_emojis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import aiohttp
from bs4 import BeautifulSoup
import asyncio
import json

async def emoji_thing():
emojis = None
async with aiohttp.ClientSession() as client:
async with client.get('https://unicode.org/emoji/charts/full-emoji-list.html') as resp:
assert resp.status == 200
soup = BeautifulSoup(await resp.text(), 'html.parser')
tables = [
[
[td.find('img')['src'] if td.find('img') is not None else td.get_text(strip=False) for td in tr.find_all('td')]
for tr in table.find_all('tr')
]
for table in soup.find_all('table')
]
emojis = {}
for table in tables:
for row in table:
if len(row) > 4:
moji = row[3].replace('…', '').strip()
emojis[row[2]] = moji.replace('data:image/png;base64,', '')

if emojis:
with open('emojis.json', 'w') as f:
f.write(json.dumps(emojis))

if __name__ == "__main__":
loop = asyncio.new_event_loop();
asyncio.set_event_loop(loop)
loop.run_until_complete(emoji_thing())
loop.close()
80 changes: 80 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import asyncio
import os

import mongoengine
from dotenv import find_dotenv, load_dotenv

from data.model.guild import Guild

load_dotenv(find_dotenv())

async def setup():
print("STARTING SETUP...")
guild = Guild()

# you should have this setup in the .env file beforehand
guild._id = int(os.environ.get("MAIN_GUILD_ID"))

# If you're re-running this script to update a value, set case_id
# to the last unused case ID or else it will start over from 1!
guild.case_id = 1

# required for permissions framework!
guild.role_administrator = 123 # put in the role IDs for your server here
guild.role_moderator = 123 # put in the role IDs for your server here
guild.role_birthday = 123 # put in the role IDs for your server here
guild.role_sub_mod = 123 # put in the role IDs for your server here
guild.role_genius = 123 # put in the role IDs for your server here
guild.role_dev = 123 # put in the role IDs for your server here
guild.role_memberone = 123 # put in the role IDs for your server here
guild.role_memberedition = 123 # put in the role IDs for your server here
guild.role_memberpro = 123 # put in the role IDs for your server here
guild.role_memberplus = 123 # put in the role IDs for your server here

# not required if you don't want the /subnews command
guild.role_sub_news = 123 # put in the role IDs for your server here

guild.channel_reports = 123 # put in the channel IDs for your server here
# channel where reactions will be logged
guild.channel_emoji_log = 123 # put in the channel IDs for your server here
# channel for private mod logs
guild.channel_private = 123 # put in the channel IDs for your server here
# channel where self-assignable roles will be posted
guild.channel_reaction_roles = 123 # put in the channel IDs for your server here
# rules-and-info channel
guild.channel_rules = 123 # put in the channel IDs for your server here
# not required
guild.channel_applenews = 123 # put in the channel IDs for your server here
# channel for public mod logs
guild.channel_public = 123 # put in the channel IDs for your server here
# optional, used for /subnrews command or something
guild.channel_subnews = 123 # put in the channel IDs for your server here
# optional, required for /issue command
guild.channel_common_issues = 123 # put in the channel IDs for your server here
# #general, required for permissions
guild.channel_general = 123 # put in the channel IDs for your server here
# required for filter
guild.channel_development = 123 # put in the channel IDs for your server here
# required, #bot-commands channel
guild.channel_botspam = 123 # put in the channel IDs for your server here
# optional, needed for booster #emote-suggestions channel
guild.channel_booster_emoji = 123 # put in the channel IDs for your server here

# you can fill these in if you want with IDs, or you ca use commands later
guild.logging_excluded_channels = [] # put in a channel if you want (ignored in logging)
guild.filter_excluded_channels = [] # put in a channel if you want (ignored in filter)
guild.filter_excluded_guilds = [] # put guild ID to whitelist in invite filter if you want

guild.nsa_guild_id = 123 # you can leave this as is if you don't want Blootooth (message mirroring system)

guild.save()
print("DONE")

if __name__ == "__main__":
if os.environ.get("DB_CONNECTION_STRING") is None:
mongoengine.register_connection(
host=os.environ.get("DB_HOST"), port=int(os.environ.get("DB_PORT")), alias="default", name="botty")
else:
mongoengine.register_connection(
host=os.environ.get("DB_CONNECTION_STRING"), alias="default", name="botty")
res = asyncio.get_event_loop().run_until_complete( setup() )

0 comments on commit 5c56f13

Please sign in to comment.