Update file garfbot.py
This commit is contained in:
parent
8e9a09b5b0
commit
2eeb746616
31
garfbot.py
31
garfbot.py
@ -29,26 +29,24 @@ 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 gpt-3.5-turbo.", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# MeowCounts File
|
# Json Handling
|
||||||
counts_file = "meow_counts.json"
|
meows_file = "meow_counts.json"
|
||||||
meow_counts = defaultdict(int)
|
stats_file = "user_stats.json"
|
||||||
if os.path.isfile(counts_file):
|
|
||||||
with open(counts_file, "r") as f:
|
|
||||||
meow_counts.update(json.load(f))
|
|
||||||
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 = {}
|
|
||||||
|
|
||||||
|
def json_load(file_path, default):
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
return json.load(f)
|
||||||
|
else:
|
||||||
|
return default
|
||||||
|
|
||||||
|
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