Merge pull request #110 from joryclements/chat-bypass

Add support for CHAT_BYPASS_ROLES in Env
Kaveen Kumarasinghe 2 years ago committed by GitHub
commit 77e6167fc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -143,6 +143,8 @@ There are two thresholds for the bot, there are instances in which the bot will
If you'd like to help us test and fine tune our thresholds for the moderation service, please join this test server: https://discord.gg/CWhsSgNdrP. You can let off some steam in a controlled environment ;) If you'd like to help us test and fine tune our thresholds for the moderation service, please join this test server: https://discord.gg/CWhsSgNdrP. You can let off some steam in a controlled environment ;)
To set a certain role immune to moderations, add the line `CHAT_BYPASS_ROLES="Role1,Role2,etc"` to your `.env file.
**The above server is NOT for support or discussions about GPT3Discord** **The above server is NOT for support or discussions about GPT3Discord**
# Permanent Memory and Conversations # Permanent Memory and Conversations

@ -31,6 +31,7 @@ else:
# #
USER_INPUT_API_KEYS = EnvService.get_user_input_api_keys() USER_INPUT_API_KEYS = EnvService.get_user_input_api_keys()
USER_KEY_DB = EnvService.get_api_db() USER_KEY_DB = EnvService.get_api_db()
CHAT_BYPASS_ROLES = EnvService.get_bypass_roles()
# #
# Obtain the Moderation table and the General table, these are two SQLite tables that contain # Obtain the Moderation table and the General table, these are two SQLite tables that contain
@ -523,13 +524,15 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
and message.guild.id in Moderation.moderation_queues and message.guild.id in Moderation.moderation_queues
and Moderation.moderation_queues[message.guild.id] is not None and Moderation.moderation_queues[message.guild.id] is not None
): ):
# Create a timestamp that is 0.5 seconds from now # Verify that the user is not in a role that can bypass moderation
timestamp = ( if CHAT_BYPASS_ROLES is [None] or not any(role.name.lower() in CHAT_BYPASS_ROLES for role in message.author.roles):
datetime.datetime.now() + datetime.timedelta(seconds=0.5) # Create a timestamp that is 0.5 seconds from now
).timestamp() timestamp = (
await Moderation.moderation_queues[message.guild.id].put( datetime.datetime.now() + datetime.timedelta(seconds=0.5)
Moderation(message, timestamp) ).timestamp()
) # TODO Don't proceed to conversation processing if the message is deleted by moderations. await Moderation.moderation_queues[message.guild.id].put(
Moderation(message, timestamp)
) # TODO Don't proceed to conversation processing if the message is deleted by moderations.
# Process the message if the user is in a conversation # Process the message if the user is in a conversation
if await TextService.process_conversation_message( if await TextService.process_conversation_message(

@ -27,7 +27,7 @@ from services.environment_service import EnvService
from models.openai_model import Model from models.openai_model import Model
__version__ = "8.1.3" __version__ = "8.2"
if sys.platform == "win32": if sys.platform == "win32":

@ -268,6 +268,32 @@ class EnvService:
return user_key_db return user_key_db
return user_key_db return user_key_db
@staticmethod
def get_bypass_roles():
# GPT_ROLES is a comma separated list of string roles
# It can also just be one role
# Read these allowed roles and return as a list of strings
try:
bypass_roles = os.getenv("CHAT_BYPASS_ROLES")
except Exception:
bypass_roles = None
if bypass_roles is None:
print(
"CHAT_BYPASS_ROLES is not defined properly in the environment file!"
"Please copy your server's role and put it into CHAT_BYPASS_ROLES in the .env file."
'For example a line should look like: `CHAT_BYPASS_ROLES="bypass"`'
)
print("Defaulting to allowing NO ONE to bypass chat moderation")
return [None]
bypass_roles = (
bypass_roles.lower().strip().split(",")
if "," in bypass_roles
else [bypass_roles.lower()]
)
return bypass_roles
@staticmethod @staticmethod
def get_deepl_token(): def get_deepl_token():
try: try:

@ -9,8 +9,6 @@ from discord.ext import pages
from services.deletion_service import Deletion from services.deletion_service import Deletion
from models.openai_model import Model from models.openai_model import Model
from models.user_model import EmbeddedConversationItem, RedoUser from models.user_model import EmbeddedConversationItem, RedoUser
class TextService: class TextService:
def __init__(self): def __init__(self):
pass pass

Loading…
Cancel
Save