Add support for CHAT_BYPASS_ROLES in Env

Jory Clements 2 years ago
parent eff4940d53
commit a20d8d2918

@ -523,13 +523,16 @@ class GPT3ComCon(discord.Cog, name="GPT3ComCon"):
and message.guild.id in Moderation.moderation_queues
and Moderation.moderation_queues[message.guild.id] is not None
):
# Create a timestamp that is 0.5 seconds from now
timestamp = (
datetime.datetime.now() + datetime.timedelta(seconds=0.5)
).timestamp()
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.
# Verify that the user is not in a role that can bypass moderation
if (CHAT_BYPASS_ROLES is not [None]
and message.author.roles is not in CHAT_BYPASS_ROLES):
# Create a timestamp that is 0.5 seconds from now
timestamp = (
datetime.datetime.now() + datetime.timedelta(seconds=0.5)
).timestamp()
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
if await TextService.process_conversation_message(

@ -158,7 +158,32 @@ class Moderation:
if warn_result:
return ModerationResult.WARN
return ModerationResult.NONE
@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
# This function will be called by the bot to process the message queue
@staticmethod
async def process_moderation_queue(

@ -10,6 +10,7 @@ from services.deletion_service import Deletion
from models.openai_model import Model
from models.user_model import EmbeddedConversationItem, RedoUser
CHAT_BYPASS_ROLES = EnvService.get_bypass_roles()
class TextService:
def __init__(self):

Loading…
Cancel
Save