Giter Club home page Giter Club logo

girrewrite's Introduction

GIR Rewrite

GIR banner

GIR is a sophisticated moderation and miscellaneous utilities Discord bot created for the r/Jailbreak Discord server. It features:

  • Completely based on Discord's Slash Commands, written in the Discord.py library
  • 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!

GIR 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!

See also: Bloo and GIR


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 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 gir.

IMPORTANT: slash commands are not synced automatically. Instead, the bot owner can DM the bot !sync to sync slash commands with Discord. This only needs to be done once when the bot is set up, or when you change any of the command data (such adding a new command, changing a command's name or description, etc.)

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.

Steps

  1. Clone the repository and open the folder in Visual Studio Code
  2. Install the Microsoft Remote Development 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.
  7. Make sure the database is set up (see below).
  8. Open the integrated terminal in VSCode and run the gir 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.

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.
  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 <GIR 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


SlimShadyIAm

stkc

Ultra03

ja1dan

donato-fiore

m1stadev

mass1ve-err0r

sqlstatement

beerpsi

Special thanks

Special thanks to the following people for ideas, testing, or help:

girrewrite's People

Contributors

bbaovanc avatar bomberfish avatar bytenekos avatar captinc avatar elihwyma avatar emiyl avatar itsnebulalol avatar ja1dan avatar leanwastaken avatar qtlunya avatar r00tfs avatar slimshadyiam avatar stekc avatar tale avatar therealketo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

girrewrite's Issues

`/transferprofile` not working as expected

According to a report:

I attempted a transfer and gir claimed to have successfully completed it but

  • Successfully wiped cases from the original user, and did not apply them to the new one
  • did not transfer roles
  • did not transfer XP (I think)

gir restart as always

gir  | [*] Ban appeals monitoring is DISABLED!
gir  | [*] Discord webhook logging is ENABLED!
gir  | [?] (m:'config', l:55) `/memegen aitext` will not be enabled.
gir  | [?] (m:'config', l:60) Markov is DISABLED! `/memegen text` features will not be enabled.
gir  | [*] GIR will be running in: 861497413298946070 in PRODUCTION mode
gir  | [*] Bot owned by: 163496482748628992
gir  | [*] Starting database...
gir  | [*] Database connected and loaded successfully!
gir  | Traceback (most recent call last):
gir  |   File "/usr/src/app/main.py", line 9, in <module>
gir  |     from utils import cfg, db, logger, GIRContext, BanCache, IssueCache, Tasks, RuleCache, init_client_session, scam_cache
gir  |   File "/usr/src/app/utils/__init__.py", line 3, in <module>
gir  |     from .database import *
gir  |   File "/usr/src/app/utils/database.py", line 22, in <module>
gir  |     db = Database()
gir  |   File "/usr/src/app/utils/database.py", line 18, in __init__
gir  |     if not Guild.objects(_id=cfg.guild_id):
gir  |   File "/opt/venv/lib/python3.10/site-packages/mongoengine/queryset/manager.py", line 38, in __get__
gir  |     queryset = queryset_class(owner, owner._get_collection())
gir  |   File "/opt/venv/lib/python3.10/site-packages/mongoengine/document.py", line 223, in _get_collection
gir  |     if cls._meta.get("auto_create_index", True) and db.client.is_primary:
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1088, in is_primary
gir  |     return self._server_property('is_writable')
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 889, in _server_property
gir  |     server = self._topology.select_server(
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 244, in select_server
gir  |     return random.choice(self.select_servers(selector,
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 202, in select_servers
gir  |     server_descriptions = self._select_servers_loop(
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 218, in _select_servers_loop
gir  |     raise ServerSelectionTimeoutError(
gir  | pymongo.errors.ServerSelectionTimeoutError: host.docker.internal
gir  | :27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 62a21e6ad2753e0af9abd918, topology_type: Single, servers: [<ServerDescription ('host.docker.internal\n', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('host.docker.internal\n:27017: [Errno -2] Name or service not known')>]>
gir  | [*] Ban appeals monitoring is DISABLED!
gir  | [*] Discord webhook logging is ENABLED!
gir  | [?] (m:'config', l:55) `/memegen aitext` will not be enabled.
gir  | [?] (m:'config', l:60) Markov is DISABLED! `/memegen text` features will not be enabled.
gir  | [*] GIR will be running in: 861497413298946070 in PRODUCTION mode
gir  | [*] Bot owned by: 163496482748628992
gir  | [*] Starting database...
gir  | [*] Database connected and loaded successfully!
gir  | Traceback (most recent call last):
gir  |   File "/usr/src/app/main.py", line 9, in <module>
gir  |     from utils import cfg, db, logger, GIRContext, BanCache, IssueCache, Tasks, RuleCache, init_client_session, scam_cache
gir  |   File "/usr/src/app/utils/__init__.py", line 3, in <module>
gir  |     from .database import *
gir  |   File "/usr/src/app/utils/database.py", line 22, in <module>
gir  |     db = Database()
gir  |   File "/usr/src/app/utils/database.py", line 18, in __init__
gir  |     if not Guild.objects(_id=cfg.guild_id):
gir  |   File "/opt/venv/lib/python3.10/site-packages/mongoengine/queryset/manager.py", line 38, in __get__
gir  |     queryset = queryset_class(owner, owner._get_collection())
gir  |   File "/opt/venv/lib/python3.10/site-packages/mongoengine/document.py", line 223, in _get_collection
gir  |     if cls._meta.get("auto_create_index", True) and db.client.is_primary:
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1088, in is_primary
gir  |     return self._server_property('is_writable')
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 889, in _server_property
gir  |     server = self._topology.select_server(
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 244, in select_server
gir  |     return random.choice(self.select_servers(selector,
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 202, in select_servers
gir  |     server_descriptions = self._select_servers_loop(
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 218, in _select_servers_loop
gir  |     raise ServerSelectionTimeoutError(
gir  | pymongo.errors.ServerSelectionTimeoutError: host.docker.internal
gir  | :27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 62a21e8993069b0f0f4b9710, topology_type: Single, servers: [<ServerDescription ('host.docker.internal\n', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('host.docker.internal\n:27017: [Errno -2] Name or service not known')>]>
gir  | [*] Ban appeals monitoring is DISABLED!
gir  | [*] Discord webhook logging is ENABLED!
gir  | [?] (m:'config', l:55) `/memegen aitext` will not be enabled.
gir  | [?] (m:'config', l:60) Markov is DISABLED! `/memegen text` features will not be enabled.
gir  | [*] GIR will be running in: 861497413298946070 in PRODUCTION mode
gir  | [*] Bot owned by: 163496482748628992
gir  | [*] Starting database...
gir  | [*] Database connected and loaded successfully!
gir  | Traceback (most recent call last):
gir  |   File "/usr/src/app/main.py", line 9, in <module>
gir  |     from utils import cfg, db, logger, GIRContext, BanCache, IssueCache, Tasks, RuleCache, init_client_session, scam_cache
gir  |   File "/usr/src/app/utils/__init__.py", line 3, in <module>
gir  |     from .database import *
gir  |   File "/usr/src/app/utils/database.py", line 22, in <module>
gir  |     db = Database()
gir  |   File "/usr/src/app/utils/database.py", line 18, in __init__
gir  |     if not Guild.objects(_id=cfg.guild_id):
gir  |   File "/opt/venv/lib/python3.10/site-packages/mongoengine/queryset/manager.py", line 38, in __get__
gir  |     queryset = queryset_class(owner, owner._get_collection())
gir  |   File "/opt/venv/lib/python3.10/site-packages/mongoengine/document.py", line 223, in _get_collection
gir  |     if cls._meta.get("auto_create_index", True) and db.client.is_primary:
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 1088, in is_primary
gir  |     return self._server_property('is_writable')
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/mongo_client.py", line 889, in _server_property
gir  |     server = self._topology.select_server(
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 244, in select_server
gir  |     return random.choice(self.select_servers(selector,
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 202, in select_servers
gir  |     server_descriptions = self._select_servers_loop(
gir  |   File "/opt/venv/lib/python3.10/site-packages/pymongo/topology.py", line 218, in _select_servers_loop
gir  |     raise ServerSelectionTimeoutError(
gir  | pymongo.errors.ServerSelectionTimeoutError: host.docker.internal
gir  | :27017: [Errno -2] Name or service not known, Timeout: 30s, Topology Description: <TopologyDescription id: 62a21ea818ca940d7ad7b4da, topology_type: Single, servers: [<ServerDescription ('host.docker.internal\n', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('host.docker.internal\n:27017: [Errno -2] Name or service not known')>]>```

restart loop

gir | discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.

gir | [?] (m:'config', l:69) .env file does not have key AARON_ROLE. Some features may not function as intended.

gir | [*] Ban appeals monitoring is DISABLED!

gir | [*] Discord webhook logging is DISABLED!

gir | [?] (m:'config', l:55) /memegen aitext will not be enabled.

gir | [?] (m:'config', l:60) Markov is DISABLED! /memegen text features will not be enabled.

gir | [*] GIR will be running in: 861497413298946070 in PRODUCTION mode

gir | [*] Bot owned by: 163496482748628992

gir | [*] Starting database...

gir | [*] Database connected and loaded successfully!

gir | [?] (m:'client', l:246) PyNaCl is not installed, voice will NOT be supported

gir | [*] Presetup phase completed! Connecting to Discord...

gir | [*] logging in using static token

gir | [?] (m:'sabbath', l:44) Aaron's ID or role not set, disabling the Sabbath cog! If you want this, refer to README.md.

gir | [?] (m:'jailbreak_monitors', l:161) Pastee token not set, not loading the TweakList cog! If you want this, refer to README.md.

gir | [*] Scheduler started

gir | [*] Shard ID None has sent the IDENTIFY payload.

gir | [*] Shard ID None session has been invalidated.

gir | [*] Got a request to IDENTIFY the websocket.

gir | [*] Shard ID None has sent the IDENTIFY payload.

gir | [*] Websocket closed with 4014, cannot reconnect.

gir | Unclosed client session

gir | client_session: <aiohttp.client.ClientSession object at 0x7f53470a3550>

gir | Traceback (most recent call last):

gir | File "/usr/src/app/main.py", line 169, in

gir | asyncio.run(main())

gir | File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run

gir | return loop.run_until_complete(main)

gir | File "/usr/local/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete

gir | return future.result()

gir | File "/usr/src/app/main.py", line 167, in main

gir | await bot.start(os.environ.get("GIR_TOKEN"), reconnect=True)

gir | File "/opt/venv/lib/python3.10/site-packages/discord/client.py", line 682, in start

gir | await self.connect(reconnect=reconnect)

gir | File "/opt/venv/lib/python3.10/site-packages/discord/client.py", line 619, in connect

Support silent filters

We want to be able to detect when certain keywords are mentioned and notify moderators without removing the message.

This requires an extension to the FilterWord model with an optional silent_filter flag, as well as an optional flag in the /filter add command or a way to update an existing word to toggle the flag on.

We also need to update places using the filter word to not delete the message when this is set to true.

Suggest to loosen the dependency on mongoengine

Hi, your project GIRRewrite(commit id: 158733c) requires "mongoengine==0.23.1" in its dependency. After analyzing the source code, we found that the following versions of mongoengine can also be suitable, i.e., mongoengine 0.22.0, 0.22.1, 0.23.0, since all functions that you directly (12 APIs: mongoengine.document.EmbeddedDocument.init, mongoengine.connection.register_connection, mongoengine.fields.ListField.init, mongoengine.fields.IntField.init, mongoengine.document.Document.init, mongoengine.fields.StringField.init, mongoengine.fields.EmbeddedDocumentListField.init, mongoengine.fields.DictField.init, mongoengine.fields.DateField.init, mongoengine.fields.BooleanField.init, mongoengine.fields.FileField.init, mongoengine.fields.DateTimeField.init) or indirectly (propagate to 13 mongoengine's internal APIs and 5 outsider APIs) used from the package have not been changed in these versions, thus not affecting your usage.

Therefore, we believe that it is quite safe to loose your dependency on mongoengine from "mongoengine==0.23.1" to "mongoengine>=0.22.0,<=0.23.1". This will improve the applicability of GIRRewrite and reduce the possibility of any further dependency conflict with other projects.

May I pull a request to further loosen the dependency on mongoengine?

By the way, could you please tell us whether such an automatic tool for dependency analysis may be potentially helpful for maintaining dependencies easier during your development?

README.md missing documention and stuck at `gir | Exception: The database has not been set up for guild 861497413298946070! Please refer to README.md.`

gir  | [*] Ban appeals monitoring is DISABLED!
gir  | [*] Discord webhook logging is ENABLED!
gir  | [?] (m:'config', l:55) `/memegen aitext` will not be enabled.
gir  | [?] (m:'config', l:60) Markov is DISABLED! `/memegen text` features will not be enabled.
gir  | [*] GIR will be running in: 861497413298946070 in PRODUCTION mode
gir  | [*] Bot owned by: 163496482748628992
gir  | [*] Starting database...
gir  | [*] Database connected and loaded successfully!
gir  | Traceback (most recent call last):
gir  |   File "/usr/src/app/main.py", line 9, in <module>
gir  |     from utils import cfg, db, logger, GIRContext, BanCache, IssueCache, Tasks, RuleCache, init_client_session, scam_cache
gir  |   File "/usr/src/app/utils/__init__.py", line 3, in <module>
gir  |     from .database import *
gir  |   File "/usr/src/app/utils/database.py", line 22, in <module>
gir  |     db = Database()
gir  |   File "/usr/src/app/utils/database.py", line 19, in __init__
gir  |     raise Exception(f"The database has not been set up for guild {cfg.guild_id}! Please refer to README.md.")
gir  | Exception: The database has not been set up for guild 861497413298946070! Please refer to README.md.```
then loop

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.