Merge branch 'refactor2' into 'main'
Refactor2 See merge request crate3/garfbot!1
This commit is contained in:
commit
889e84c99e
33
garfbot.py
33
garfbot.py
@ -27,28 +27,26 @@ intents.messages = True
|
|||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
asyncio.create_task(process_image_requests())
|
asyncio.create_task(process_image_requests()) # Important!
|
||||||
print(f"Logged in as {client.user.name} running gpt-3.5-turbo.", flush=True)
|
print(f"Logged in as {client.user.name} running {txtmodel} {imgmodel}.", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
# Json Handling
|
||||||
|
meows_file = "meow_counts.json"
|
||||||
|
stats_file = "user_stats.json"
|
||||||
|
|
||||||
# MeowCounts File
|
def json_load(file_path, default):
|
||||||
counts_file = "meow_counts.json"
|
if os.path.isfile(file_path):
|
||||||
meow_counts = defaultdict(int)
|
with open(file_path, "r") as f:
|
||||||
if os.path.isfile(counts_file):
|
return json.load(f)
|
||||||
with open(counts_file, "r") as f:
|
else:
|
||||||
meow_counts.update(json.load(f))
|
return default
|
||||||
elif os.path.exists(counts_file):
|
|
||||||
with open(counts_file, "r") as f:
|
|
||||||
meow_counts = json.load(f)
|
|
||||||
try:
|
|
||||||
with open("user_stats.json", "r") as f:
|
|
||||||
user_stats = json.load(f)
|
|
||||||
except FileNotFoundError:
|
|
||||||
user_stats = {}
|
|
||||||
|
|
||||||
|
meow_counts = defaultdict(int, json_load(meows_file, {}))
|
||||||
|
user_stats = json_load(stats_file, {})
|
||||||
|
|
||||||
|
|
||||||
# GarfChats
|
# GarfChats
|
||||||
@ -75,7 +73,6 @@ async def generate_chat_response(question):
|
|||||||
return f"`GarfBot Error: Lasagna`"
|
return f"`GarfBot Error: Lasagna`"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# GarfPics
|
# GarfPics
|
||||||
async def generate_image(prompt):
|
async def generate_image(prompt):
|
||||||
try:
|
try:
|
||||||
@ -163,7 +160,7 @@ async def on_message(message):
|
|||||||
|
|
||||||
meow_counts[str(message.author.id)] += 1
|
meow_counts[str(message.author.id)] += 1
|
||||||
|
|
||||||
with open(counts_file, "w") as f:
|
with open(meows_file, "w") as f:
|
||||||
json.dump(dict(meow_counts), f)
|
json.dump(dict(meow_counts), f)
|
||||||
|
|
||||||
if message.content.lower() == "meowcount":
|
if message.content.lower() == "meowcount":
|
||||||
|
Loading…
Reference in New Issue
Block a user