Made blog work differently
This commit is contained in:
parent
86fa1cd1cc
commit
82138c3023
1 changed files with 25 additions and 18 deletions
|
|
@ -21,7 +21,6 @@ import threading
|
|||
import matplotlib.pyplot as plt
|
||||
import aiohttp
|
||||
import aioftp
|
||||
import sched
|
||||
|
||||
#config
|
||||
STABLE_DIFFUSION_URL = "http://127.0.0.1:7861"
|
||||
|
|
@ -205,6 +204,8 @@ async def look_at(ctx, look=False):
|
|||
|
||||
def edit_channel_config(channel_id, key, value):
|
||||
config_file = "channels/config/" + str(channel_id) + ".json"
|
||||
#if not os.path.exists(config_file):
|
||||
# create_channel_config(config_file)
|
||||
with open(config_file, 'r') as f:
|
||||
config_data = json.load(f)
|
||||
config_data[key] = value
|
||||
|
|
@ -288,7 +289,7 @@ async def chat_response(ctx, channel_vars, chat_history_string):
|
|||
print(error)
|
||||
|
||||
async def folder_setup():
|
||||
folder_names = ["tmp", "channels", "users"]
|
||||
folder_names = ["tmp", "channels", "users", "channels/config", "channels/logs", "databases"]
|
||||
for folder_name in folder_names:
|
||||
if not os.path.exists(folder_name):
|
||||
os.mkdir(folder_name)
|
||||
|
|
@ -304,30 +305,29 @@ async def delete_all_files(path):
|
|||
async def task_loop():
|
||||
current_time = time.localtime()
|
||||
bot_stuff = bot.get_channel(544408659174883328)
|
||||
last_daily_run = 0
|
||||
|
||||
#Run daily task
|
||||
if current_time.tm_hour == 12 and current_time.tm_min == 0 and last_daily_run != current_time.tm_yday:
|
||||
if current_time.tm_hour == 17 and current_time.tm_min == 7 and current_time.tm_sec == 0:
|
||||
output = 'The following tasks failed:\n```'
|
||||
failed_tasks = []
|
||||
last_daily_run = current_time.tm_yday #Don't accidently run the task twice in a day.
|
||||
await bot_stuff.send("<@242018983241318410> The current time is 5pm. Running daily tasks!")
|
||||
try:
|
||||
await blog(bot_stuff)
|
||||
except Exception as error:
|
||||
failed_tasks.append("Blogpost failed!")
|
||||
print(error)
|
||||
failed_tasks.append("Blogpost")
|
||||
try:
|
||||
await delete_all_files("tmp/")
|
||||
except Exception as error:
|
||||
failed_tasks.append("Delete tmp/ failed!")
|
||||
failed_tasks.append("Delete tmp/")
|
||||
if failed_tasks != []:
|
||||
for failed_task in failed_tasks:
|
||||
await bot_stuff.send(failed_task)
|
||||
output += failed_task + '\n'
|
||||
output += '```'
|
||||
await bot_stuff.send(output)
|
||||
else:
|
||||
await bot_stuff.send("All daily tasks successfully ran!")
|
||||
|
||||
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print('We have logged in as {0.user}'.format(bot))
|
||||
|
|
@ -650,13 +650,7 @@ async def rsgp(ctx, amount):
|
|||
@bot.command()
|
||||
async def blog(ctx):
|
||||
start_time = time.time()
|
||||
# Check if a topic was provided
|
||||
if len(ctx.message.content.split(" ")) > 1:
|
||||
topic = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
await ctx.send("Writing blogpost")
|
||||
else:
|
||||
await ctx.send("No topic given for blogpost, generating one.")
|
||||
topic = answer_question("Give me one topic for an absurd blogpost.")
|
||||
topic = ''
|
||||
filename = "phixxy.com/ai-blog/index.html"
|
||||
with open(filename, 'r', encoding="utf-8") as f:
|
||||
html_data = f.read()
|
||||
|
|
@ -666,6 +660,19 @@ async def blog(ctx):
|
|||
if date in html_data:
|
||||
await ctx.send("I already wrote a blog post today!")
|
||||
return
|
||||
blogpost_file = "databases/blog_topics.txt"
|
||||
if os.path.isfile(blogpost_file):
|
||||
with open(blogpost_file, 'r') as f:
|
||||
blogpost_topics = f.read()
|
||||
topic = f.seek(0).readline()
|
||||
blogpost_topics = blogpost_topics.replace(topic, '')
|
||||
with open(blogpost_file, 'w') as f:
|
||||
f.write(blogpost_topics)
|
||||
if topic != '':
|
||||
await ctx.send("Writing blogpost")
|
||||
else:
|
||||
await ctx.send("No topic given for blogpost, generating one.")
|
||||
topic = answer_question("Give me one topic for an absurd blogpost.")
|
||||
|
||||
|
||||
post_div = '''<!--replace this with a post-->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue