Added basic error logging
This commit is contained in:
parent
d181eb03b4
commit
cb880ad94d
1 changed files with 44 additions and 23 deletions
|
|
@ -58,6 +58,14 @@ async def upload_ftp(local_filename, server_folder, server_filename):
|
||||||
await client.upload(local_filename, server_folder+server_filename, write_into=True)
|
await client.upload(local_filename, server_folder+server_filename, write_into=True)
|
||||||
await client.quit()
|
await client.quit()
|
||||||
|
|
||||||
|
async def handle_error(error):
|
||||||
|
print(error)
|
||||||
|
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
|
log_line = current_time + ': ' + error
|
||||||
|
with open("databases/error_log.txt", 'a') as f:
|
||||||
|
f.write(log_line)
|
||||||
|
return error
|
||||||
|
|
||||||
|
|
||||||
async def upload_ftp_ai_images(filename, prompt):
|
async def upload_ftp_ai_images(filename, prompt):
|
||||||
html_file = "phixxy.com/ai-images/index.html"
|
html_file = "phixxy.com/ai-images/index.html"
|
||||||
|
|
@ -135,7 +143,7 @@ async def answer_question(topic, model="gpt-3.5-turbo"):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
return error
|
return await handle_error(error)
|
||||||
|
|
||||||
def extract_key_value_pairs(input_str):
|
def extract_key_value_pairs(input_str):
|
||||||
output_str = input_str
|
output_str = input_str
|
||||||
|
|
@ -195,7 +203,8 @@ async def look_at(ctx, look=False):
|
||||||
description = r.get("caption")
|
description = r.get("caption")
|
||||||
description = description.split(',')[0]
|
description = description.split(',')[0]
|
||||||
metadata += f"<image:{description}>\n"
|
metadata += f"<image:{description}>\n"
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
return "ERROR: CLIP may not be running. Could not look at image."
|
return "ERROR: CLIP may not be running. Could not look at image."
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
@ -237,7 +246,7 @@ async def react_to_msg(ctx, react):
|
||||||
await ctx.add_reaction(reaction.strip())
|
await ctx.add_reaction(reaction.strip())
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print("Some error happened while trying to react to a message")
|
print("Some error happened while trying to react to a message")
|
||||||
print(str(error))
|
await handle_error(error)
|
||||||
|
|
||||||
async def log_chat_and_get_history(ctx, logfile, channel_vars):
|
async def log_chat_and_get_history(ctx, logfile, channel_vars):
|
||||||
metadata = await look_at(ctx, channel_vars["look_at_images"])
|
metadata = await look_at(ctx, channel_vars["look_at_images"])
|
||||||
|
|
@ -286,7 +295,7 @@ async def chat_response(ctx, channel_vars, chat_history_string):
|
||||||
await ctx.channel.send(message)
|
await ctx.channel.send(message)
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
|
|
||||||
async def folder_setup():
|
async def folder_setup():
|
||||||
folder_names = ["tmp", "channels", "users", "channels/config", "channels/logs", "databases", "databases/currency", "databases/currency/players"]
|
folder_names = ["tmp", "channels", "users", "channels/config", "channels/logs", "databases", "databases/currency", "databases/currency/players"]
|
||||||
|
|
@ -316,11 +325,12 @@ async def task_loop():
|
||||||
try:
|
try:
|
||||||
await blog(bot_stuff)
|
await blog(bot_stuff)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
failed_tasks.append("Blogpost")
|
failed_tasks.append("Blogpost")
|
||||||
try:
|
try:
|
||||||
await delete_all_files("tmp/")
|
await delete_all_files("tmp/")
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
failed_tasks.append("Delete tmp/")
|
failed_tasks.append("Delete tmp/")
|
||||||
if failed_tasks != []:
|
if failed_tasks != []:
|
||||||
for failed_task in failed_tasks:
|
for failed_task in failed_tasks:
|
||||||
|
|
@ -623,8 +633,9 @@ async def meme(ctx):
|
||||||
#Printing Whether Creating A meme was A success
|
#Printing Whether Creating A meme was A success
|
||||||
print(f"Generated Meme = {response['success']}\nImage Link = {response['data']['url']}\nPage Link = {response['data']['page_url']}")
|
print(f"Generated Meme = {response['success']}\nImage Link = {response['data']['url']}\nPage Link = {response['data']['page_url']}")
|
||||||
image_link = response['data']['url']
|
image_link = response['data']['url']
|
||||||
except:
|
except Exception as error:
|
||||||
print("\nAaaaah An error occured when requesting Data..")
|
print("\nAaaaah An error occured when requesting Data..")
|
||||||
|
await handle_error(error)
|
||||||
try:
|
try:
|
||||||
#------------------------------------Saving Image Using Requests---------------------------------#
|
#------------------------------------Saving Image Using Requests---------------------------------#
|
||||||
filename = memepics[id-1]['name']
|
filename = memepics[id-1]['name']
|
||||||
|
|
@ -636,7 +647,8 @@ async def meme(ctx):
|
||||||
file.write(response.content)
|
file.write(response.content)
|
||||||
file.close()
|
file.close()
|
||||||
print("Meme was Saved Successfuly")
|
print("Meme was Saved Successfuly")
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
print("Something's Wrong with the urllib So try again")
|
print("Something's Wrong with the urllib So try again")
|
||||||
return image_link, filename
|
return image_link, filename
|
||||||
|
|
||||||
|
|
@ -649,9 +661,10 @@ async def meme(ctx):
|
||||||
await update_meme_webpage(filepath)
|
await update_meme_webpage(filepath)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print("COULDN'T UPLOAD TO FTP!")
|
print("COULDN'T UPLOAD TO FTP!")
|
||||||
|
await handle_error(error)
|
||||||
await ctx.send(link)
|
await ctx.send(link)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
await ctx.send('Something went wrong try again. Usage: !meme (topic)')
|
await ctx.send('Something went wrong try again. Usage: !meme (topic)')
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
|
@ -777,8 +790,8 @@ async def highscores(ctx, limit=0):
|
||||||
user_message_counts[user] = 1
|
user_message_counts[user] = 1
|
||||||
else:
|
else:
|
||||||
user_message_counts[user] += 1
|
user_message_counts[user] += 1
|
||||||
except:
|
except Exception as error:
|
||||||
pass
|
await handle_error(error)
|
||||||
|
|
||||||
def remove_dict_keys_if_less_than_x(dictionary,x):
|
def remove_dict_keys_if_less_than_x(dictionary,x):
|
||||||
for key in dictionary:
|
for key in dictionary:
|
||||||
|
|
@ -833,8 +846,8 @@ async def highscores_server(ctx, limit=0):
|
||||||
user_message_counts[user] = 1
|
user_message_counts[user] = 1
|
||||||
else:
|
else:
|
||||||
user_message_counts[user] += 1
|
user_message_counts[user] += 1
|
||||||
except:
|
except Exception as error:
|
||||||
pass
|
await handle_error(error)
|
||||||
|
|
||||||
def remove_dict_keys_if_less_than_x(dictionary,x):
|
def remove_dict_keys_if_less_than_x(dictionary,x):
|
||||||
for key in dictionary:
|
for key in dictionary:
|
||||||
|
|
@ -976,7 +989,7 @@ async def website(ctx):
|
||||||
|
|
||||||
await ctx.send("Finished https://phixxy.com/ai-webpage/")
|
await ctx.send("Finished https://phixxy.com/ai-webpage/")
|
||||||
except openai.error.APIConnectionError as error:
|
except openai.error.APIConnectionError as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
await ctx.send("Failed, Try again.")
|
await ctx.send("Failed, Try again.")
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
|
@ -987,7 +1000,7 @@ async def feature(ctx):
|
||||||
f.writelines('\n' + feature)
|
f.writelines('\n' + feature)
|
||||||
await ctx.send("Added " + feature)
|
await ctx.send("Added " + feature)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
|
|
||||||
with open("features.txt",'r') as f:
|
with open("features.txt",'r') as f:
|
||||||
features = f.read()
|
features = f.read()
|
||||||
|
|
@ -1039,10 +1052,10 @@ async def draw(ctx):
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=f)
|
||||||
await ctx.send(prompt)
|
await ctx.send(prompt)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
await ctx.send("My image generation service may not be running.")
|
await ctx.send("My image generation service may not be running.")
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print(error)
|
await handle_error(error)
|
||||||
await ctx.send('Did you mean to use !imagine?. Usage: !draw (number)')
|
await ctx.send('Did you mean to use !imagine?. Usage: !draw (number)')
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
|
@ -1137,6 +1150,7 @@ async def python(ctx):
|
||||||
except subprocess.CalledProcessError as error:
|
except subprocess.CalledProcessError as error:
|
||||||
await ctx.send(error.stderr.decode('utf-8'))
|
await ctx.send(error.stderr.decode('utf-8'))
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
await ctx.send("Usage: !python (codeblock)")
|
await ctx.send("Usage: !python (codeblock)")
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1239,7 +1253,8 @@ async def imagine(ctx):
|
||||||
f = discord.File(fh, filename=my_filename)
|
f = discord.File(fh, filename=my_filename)
|
||||||
|
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=f)
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
await ctx.send("My image generation service may not be running.")
|
await ctx.send("My image generation service may not be running.")
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
|
@ -1252,7 +1267,8 @@ async def describe(ctx):
|
||||||
else:
|
else:
|
||||||
print("No image linked or attached.")
|
print("No image linked or attached.")
|
||||||
return
|
return
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
print("Couldn't find image.")
|
print("Couldn't find image.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -1274,7 +1290,8 @@ async def describe(ctx):
|
||||||
response = requests.post(url=f"{url}/sdapi/v1/interrogate", json=payload)
|
response = requests.post(url=f"{url}/sdapi/v1/interrogate", json=payload)
|
||||||
r = response.json()
|
r = response.json()
|
||||||
await ctx.send(r.get("caption"))
|
await ctx.send(r.get("caption"))
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
await ctx.send("My image generation service may not be running.")
|
await ctx.send("My image generation service may not be running.")
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
|
|
@ -1284,14 +1301,17 @@ async def reimagine(ctx):
|
||||||
try:
|
try:
|
||||||
file_url = ctx.message.content.split(" ", maxsplit=2)[1]
|
file_url = ctx.message.content.split(" ", maxsplit=2)[1]
|
||||||
prompt = ctx.message.content.split(" ", maxsplit=2)[2]
|
prompt = ctx.message.content.split(" ", maxsplit=2)[2]
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
print("no linked image")
|
print("no linked image")
|
||||||
try:
|
try:
|
||||||
file_url = ctx.message.attachments[0].url
|
file_url = ctx.message.attachments[0].url
|
||||||
prompt = ctx.message.content.split(" ", maxsplit=1)[1]
|
prompt = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
print("no attached image")
|
print("no attached image")
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
print("couldn't find image")
|
print("couldn't find image")
|
||||||
key_value_pairs, prompt = extract_key_value_pairs(prompt)
|
key_value_pairs, prompt = extract_key_value_pairs(prompt)
|
||||||
r = requests.get(file_url, stream=True)
|
r = requests.get(file_url, stream=True)
|
||||||
|
|
@ -1326,7 +1346,8 @@ async def reimagine(ctx):
|
||||||
with open(my_filename, "rb") as fh:
|
with open(my_filename, "rb") as fh:
|
||||||
f = discord.File(fh, filename=my_filename)
|
f = discord.File(fh, filename=my_filename)
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=f)
|
||||||
except:
|
except Exception as error:
|
||||||
|
await handle_error(error)
|
||||||
await ctx.send("My image generation service may not be running.")
|
await ctx.send("My image generation service may not be running.")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue