This is (probably) a BREAKING CHANGE
moved functions out of essentials and into chatgpt
This commit is contained in:
parent
74c74d2330
commit
edd3bd5093
2 changed files with 89 additions and 94 deletions
|
|
@ -20,9 +20,40 @@ class ChatGPT(commands.Cog):
|
|||
os.mkdir(self.working_dir)
|
||||
if not os.path.exists(self.data_dir):
|
||||
os.mkdir(self.data_dir)
|
||||
if not os.path.exists(self.data_dir + "config"):
|
||||
os.mkdir(self.data_dir + "config")
|
||||
except:
|
||||
print("AsyncOpenAI failed to make directories")
|
||||
|
||||
def create_channel_config(self, filepath):
|
||||
config_dict = {
|
||||
"personality":"average",
|
||||
"channel_topic":"casual",
|
||||
"chat_enabled":False,
|
||||
"chat_history_len":5,
|
||||
"react_to_msgs":False,
|
||||
}
|
||||
|
||||
with open(filepath,"w") as f:
|
||||
json.dump(config_dict,f)
|
||||
print("Wrote ChatGPT config variables to file.")
|
||||
|
||||
async def get_channel_config(self, channel_id):
|
||||
filepath = f"{self.data_dir}config/{channel_id}.json"
|
||||
if not os.path.exists(filepath):
|
||||
self.create_channel_config(filepath)
|
||||
with open(filepath, "r") as f:
|
||||
config_dict = json.loads(f.readline())
|
||||
return config_dict
|
||||
|
||||
def edit_channel_config(self, channel_id, key, value):
|
||||
config_file = f"{self.data_dir}config/{channel_id}.json"
|
||||
with open(config_file, 'r') as f:
|
||||
config_data = json.load(f)
|
||||
config_data[key] = value
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config_data, f)
|
||||
|
||||
def read_db(self,filepath):
|
||||
with open(filepath,"r") as fileobj:
|
||||
db_content = json.load(fileobj)
|
||||
|
|
@ -66,6 +97,55 @@ class ChatGPT(commands.Cog):
|
|||
|
||||
except Exception as error:
|
||||
return await self.handle_error(error)
|
||||
|
||||
@commands.command(
|
||||
description="Personality",
|
||||
help="Set the personality of the bot. Usage: !personality (personality)",
|
||||
brief="Set the personality"
|
||||
)
|
||||
async def personality(self, ctx):
|
||||
personality_type = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
self.edit_channel_config(ctx.channel.id, "personality", personality_type)
|
||||
await ctx.send("Personality changed to " + personality_type)
|
||||
|
||||
@commands.command(
|
||||
description="Topic",
|
||||
help="Set the channel topic for the bot. Usage: !topic (topic)",
|
||||
brief="Set channel topic"
|
||||
)
|
||||
async def topic(self, ctx, channel_topic):
|
||||
self.edit_channel_config(ctx.channel.id, "channel_topic", channel_topic)
|
||||
await ctx.send("Topic changed to " + channel_topic)
|
||||
|
||||
@commands.command(
|
||||
description="Chat",
|
||||
help="Enable or disable bot chat in this channel. Usage !chat (enable|disable)",
|
||||
brief="Enable or disable bot chat"
|
||||
)
|
||||
async def chat(self, ctx, message):
|
||||
if "enable" in message:
|
||||
self.edit_channel_config(ctx.channel.id, "chat_enabled", True)
|
||||
await ctx.send("Chat Enabled")
|
||||
elif "disable" in message:
|
||||
self.edit_channel_config(ctx.channel.id, "chat_enabled", False)
|
||||
await ctx.send("Chat Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !chat (enable|disable)")
|
||||
|
||||
@commands.command(
|
||||
description="Reactions",
|
||||
help="Enable or disable bot reactions in this channel. Usage !reactions (enable|disable)",
|
||||
brief="Enable or disable bot reactions"
|
||||
)
|
||||
async def reactions(self, ctx, message):
|
||||
if "enable" in message:
|
||||
self.edit_channel_config(ctx.channel.id, "react_to_msgs", True)
|
||||
await ctx.send("Reactions Enabled")
|
||||
elif "disable" in message:
|
||||
self.edit_channel_config(ctx.channel.id, "react_to_msgs", False)
|
||||
await ctx.send("Reactions Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !reactions (enable|disable)")
|
||||
|
||||
@commands.command(
|
||||
description="Blog",
|
||||
|
|
|
|||
|
|
@ -13,38 +13,8 @@ async def handle_error(error):
|
|||
f.write(log_line)
|
||||
return error
|
||||
|
||||
def create_channel_config(filepath):
|
||||
config_dict = {
|
||||
"personality":"average",
|
||||
"channel_topic":"casual",
|
||||
"chat_enabled":False,
|
||||
"commands_enabled":True,
|
||||
"chat_history_len":5,
|
||||
"look_at_images":False,
|
||||
"react_to_msgs":False,
|
||||
"ftp_enabled":False
|
||||
}
|
||||
|
||||
with open(filepath,"w") as f:
|
||||
json.dump(config_dict,f)
|
||||
print("Wrote config variables to file.")
|
||||
|
||||
async def get_channel_config(channel_id):
|
||||
filepath = "channels/config/{0}.json".format(str(channel_id))
|
||||
if not os.path.exists(filepath):
|
||||
create_channel_config(filepath)
|
||||
with open(filepath, "r") as f:
|
||||
config_dict = json.loads(f.readline())
|
||||
return config_dict
|
||||
|
||||
def edit_channel_config(channel_id, key, value):
|
||||
config_file = "channels/config/" + str(channel_id) + ".json"
|
||||
with open(config_file, 'r') as f:
|
||||
config_data = json.load(f)
|
||||
config_data[key] = value
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config_data, f)
|
||||
|
||||
'''
|
||||
#stable diffusion command!!!
|
||||
@commands.command(
|
||||
description="View Images",
|
||||
help="Enable or disable bot viewing images in this channel. Usage !viewimages (enable|disable)",
|
||||
|
|
@ -58,18 +28,10 @@ async def view_images(ctx, message):
|
|||
edit_channel_config(ctx.channel.id, "look_at_images", False)
|
||||
await ctx.send("Viewing Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !viewimages (enable|disable)")
|
||||
await ctx.send("Usage: !viewimages (enable|disable)")'''
|
||||
|
||||
@commands.command(
|
||||
description="Personality",
|
||||
help="Set the personality of the bot. Usage: !personality (personality)",
|
||||
brief="Set the personality"
|
||||
)
|
||||
async def personality(ctx):
|
||||
personality_type = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
edit_channel_config(ctx.channel.id, "personality", personality_type)
|
||||
await ctx.send("Personality changed to " + personality_type)
|
||||
|
||||
'''
|
||||
@commands.command(
|
||||
description="Commands",
|
||||
help="Enable or disable bot commands in this channel. Usage !enable_commands (enable|disable)",
|
||||
|
|
@ -81,47 +43,10 @@ async def enable_commands(ctx, message):
|
|||
await ctx.send("Commands Disabled")
|
||||
else:
|
||||
edit_channel_config(ctx.channel.id, "commands_enabled", True)
|
||||
await ctx.send("Commands Enabled")
|
||||
await ctx.send("Commands Enabled")'''
|
||||
|
||||
@commands.command(
|
||||
description="Topic",
|
||||
help="Set the channel topic for the bot. Usage: !topic (topic)",
|
||||
brief="Set channel topic"
|
||||
)
|
||||
async def topic(ctx, channel_topic):
|
||||
edit_channel_config(ctx.channel.id, "channel_topic", channel_topic)
|
||||
await ctx.send("Topic changed to " + channel_topic)
|
||||
|
||||
@commands.command(
|
||||
description="Chat",
|
||||
help="Enable or disable bot chat in this channel. Usage !chat (enable|disable)",
|
||||
brief="Enable or disable bot chat"
|
||||
)
|
||||
async def chat(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "chat_enabled", True)
|
||||
await ctx.send("Chat Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "chat_enabled", False)
|
||||
await ctx.send("Chat Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !chat (enable|disable)")
|
||||
|
||||
@commands.command(
|
||||
description="Reactions",
|
||||
help="Enable or disable bot reactions in this channel. Usage !reactions (enable|disable)",
|
||||
brief="Enable or disable bot reactions"
|
||||
)
|
||||
async def reactions(ctx, message):
|
||||
if "enable" in message:
|
||||
edit_channel_config(ctx.channel.id, "react_to_msgs", True)
|
||||
await ctx.send("Reactions Enabled")
|
||||
elif "disable" in message:
|
||||
edit_channel_config(ctx.channel.id, "react_to_msgs", False)
|
||||
await ctx.send("Reactions Disabled")
|
||||
else:
|
||||
await ctx.send("Usage: !reactions (enable|disable)")
|
||||
|
||||
'''
|
||||
@commands.command(
|
||||
description="Feature",
|
||||
help="Suggest a feature. Usage: !feature (feature)",
|
||||
|
|
@ -138,9 +63,9 @@ async def feature(ctx):
|
|||
|
||||
with open("features.txt",'r') as f:
|
||||
features = f.read()
|
||||
await ctx.send(features)
|
||||
await ctx.send(features)'''
|
||||
|
||||
@commands.command(
|
||||
'''@commands.command(
|
||||
description="Errors",
|
||||
help="Shows the last errors that were logged.",
|
||||
brief="Display Errors"
|
||||
|
|
@ -154,15 +79,5 @@ async def errors(ctx, amount="5"):
|
|||
output += line
|
||||
await ctx.send(output)
|
||||
except Exception as error:
|
||||
await handle_error(error)
|
||||
await handle_error(error)'''
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
bot.add_command(feature)
|
||||
bot.add_command(reactions)
|
||||
bot.add_command(chat)
|
||||
bot.add_command(topic)
|
||||
bot.add_command(enable_commands)
|
||||
bot.add_command(personality)
|
||||
bot.add_command(view_images)
|
||||
bot.add_command(errors)
|
||||
Loading…
Add table
Add a link
Reference in a new issue