Karl Kennerley GPT3 Discord Issue#34
Kaveen Kumarasinghe 2 years ago committed by GitHub
commit d92f8761b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -67,6 +67,8 @@ You also need to add the allowed guilds that the bot can operate on, this is the
You also need to add the roles that can use the bot, this is the `ALLOWED_ROLES` field, enter role names here, separated by commas. Currently, there is no way to give everybody access to the bot, and you have to use roles, but it will be done soon. You also need to add the roles that can use the bot, this is the `ALLOWED_ROLES` field, enter role names here, separated by commas. Currently, there is no way to give everybody access to the bot, and you have to use roles, but it will be done soon.
You can optionally add a fallback welcomming message for the bot to use when new members join. If enabled, the bot will DM new members with a welcomming message generated by GPT3. If the call to GPT3 fails, the string used in the .env file is used. As further redundency, a hardcoded welcomming message is used.
``` ```
OPENAI_TOKEN="<openai_api_token>" OPENAI_TOKEN="<openai_api_token>"
DISCORD_TOKEN="<discord_bot_token>" DISCORD_TOKEN="<discord_bot_token>"
@ -74,6 +76,7 @@ DEBUG_GUILD="974519864045756446" #discord_server_id
DEBUG_CHANNEL="977697652147892304" #discord_chanel_id DEBUG_CHANNEL="977697652147892304" #discord_chanel_id
ALLOWED_GUILDS="971268468148166697,971268468148166697" ALLOWED_GUILDS="971268468148166697,971268468148166697"
ALLOWED_ROLES="Admin,gpt" ALLOWED_ROLES="Admin,gpt"
WELCOME_MESSAGE="Hi There! Welcome to our Discord server. We hope you'll enjoy our server and we look forward to engaging with you!" #Optional
``` ```
Optionally, you can include your own conversation starter text for the bot that's used with `!g converse`, with `CONVERSATION_STARTER_TEXT` Optionally, you can include your own conversation starter text for the bot that's used with `!g converse`, with `CONVERSATION_STARTER_TEXT`

@ -94,6 +94,17 @@ class GPT3ComCon(commands.Cog, name="GPT3ComCon"):
self.message_queue = message_queue self.message_queue = message_queue
self.conversation_threads = {} self.conversation_threads = {}
@commands.Cog.listener()
async def on_member_join(self, member):
if self.welcome_message_enabled():
query = f"Please generate a welcome message for {member.name} who has just joined the server."
welcome_message = self.model.send_request(query, tokens=self.usage_service.count_tokens(query))
if not welcome_message:
welcome_message = EnvService.get_welcome_message()
welcome_embed = discord.Embed(title=f"Welcome, {member.name}!", description=welcome_message)
welcome_embed.add_field(name="Just so you know...", value="> My commands are invoked with a forward slash ("/")\n> Use /help to see my help message(s).")
await member.send(content=None, embed=welcome_embded)
@commands.Cog.listener() @commands.Cog.listener()
async def on_member_remove(self, member): async def on_member_remove(self, member):
pass pass

@ -53,3 +53,14 @@ class EnvService:
allowed_roles.split(",") if "," in allowed_roles else [allowed_roles] allowed_roles.split(",") if "," in allowed_roles else [allowed_roles]
) )
return allowed_roles return allowed_roles
@staticmethod
def get_welcome_message():
# WELCOME_MESSAGE is a default string used to welcome new members to the server if GPT3 is not available.
#The string can be blank but this is not advised. If a string cannot be found in the .env file, the below string is used.
#The string is DMd to the new server member as part of an embed.
try:
welcome_message = os.getenv("WELCOME_MESSAGE")
except:
welcome_message = "Hi there! Welcome to our Discord server!"
return welcome_message

@ -53,6 +53,7 @@ class Model:
self._summarize_conversations = True self._summarize_conversations = True
self._summarize_threshold = 2500 self._summarize_threshold = 2500
self.model_max_tokens = 4024 self.model_max_tokens = 4024
self.send_welcome_message = False
try: try:
self.IMAGE_SAVE_PATH = os.environ["IMAGE_SAVE_PATH"] self.IMAGE_SAVE_PATH = os.environ["IMAGE_SAVE_PATH"]
@ -77,6 +78,21 @@ class Model:
self.openai_key = os.getenv("OPENAI_TOKEN") self.openai_key = os.getenv("OPENAI_TOKEN")
# Use the @property and @setter decorators for all the self fields to provide value checking # Use the @property and @setter decorators for all the self fields to provide value checking
@property
def welcome_message_enabled(self):
return self.send_welcome_message
@send_welcome_message.setter
def welcome_message_enabled(self, value):
if value.lower() == "true":
self.send_welcome_message = True
elif value.lower() == "false":
self.send_welcome_message = False
else:
raise ValueError("Value must be either true or false!")
@property @property
def summarize_threshold(self): def summarize_threshold(self):
return self._summarize_threshold return self._summarize_threshold

@ -4,3 +4,4 @@ DEBUG_GUILD="755420092027633774"
DEBUG_CHANNEL="907974109084942396" DEBUG_CHANNEL="907974109084942396"
ALLOWED_GUILDS="971268468148166697,971268468148166697" ALLOWED_GUILDS="971268468148166697,971268468148166697"
ALLOWED_ROLES="Admin,gpt" ALLOWED_ROLES="Admin,gpt"
WELCOME_MESSAGE="Hi There! Welcome to our Discord server. We hope you'll enjoy our server and we look forward to engaging with you!"

Loading…
Cancel
Save