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 matplotlib.pyplot as plt
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import aioftp
|
import aioftp
|
||||||
import sched
|
|
||||||
|
|
||||||
#config
|
#config
|
||||||
STABLE_DIFFUSION_URL = "http://127.0.0.1:7861"
|
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):
|
def edit_channel_config(channel_id, key, value):
|
||||||
config_file = "channels/config/" + str(channel_id) + ".json"
|
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:
|
with open(config_file, 'r') as f:
|
||||||
config_data = json.load(f)
|
config_data = json.load(f)
|
||||||
config_data[key] = value
|
config_data[key] = value
|
||||||
|
|
@ -288,7 +289,7 @@ async def chat_response(ctx, channel_vars, chat_history_string):
|
||||||
print(error)
|
print(error)
|
||||||
|
|
||||||
async def folder_setup():
|
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:
|
for folder_name in folder_names:
|
||||||
if not os.path.exists(folder_name):
|
if not os.path.exists(folder_name):
|
||||||
os.mkdir(folder_name)
|
os.mkdir(folder_name)
|
||||||
|
|
@ -304,30 +305,29 @@ async def delete_all_files(path):
|
||||||
async def task_loop():
|
async def task_loop():
|
||||||
current_time = time.localtime()
|
current_time = time.localtime()
|
||||||
bot_stuff = bot.get_channel(544408659174883328)
|
bot_stuff = bot.get_channel(544408659174883328)
|
||||||
last_daily_run = 0
|
|
||||||
|
|
||||||
#Run daily task
|
#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 = []
|
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!")
|
await bot_stuff.send("<@242018983241318410> The current time is 5pm. Running daily tasks!")
|
||||||
try:
|
try:
|
||||||
await blog(bot_stuff)
|
await blog(bot_stuff)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
failed_tasks.append("Blogpost failed!")
|
print(error)
|
||||||
|
failed_tasks.append("Blogpost")
|
||||||
try:
|
try:
|
||||||
await delete_all_files("tmp/")
|
await delete_all_files("tmp/")
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
failed_tasks.append("Delete tmp/ failed!")
|
failed_tasks.append("Delete tmp/")
|
||||||
if failed_tasks != []:
|
if failed_tasks != []:
|
||||||
for failed_task in 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:
|
else:
|
||||||
await bot_stuff.send("All daily tasks successfully ran!")
|
await bot_stuff.send("All daily tasks successfully ran!")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print('We have logged in as {0.user}'.format(bot))
|
print('We have logged in as {0.user}'.format(bot))
|
||||||
|
|
@ -650,13 +650,7 @@ async def rsgp(ctx, amount):
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def blog(ctx):
|
async def blog(ctx):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
# Check if a topic was provided
|
topic = ''
|
||||||
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.")
|
|
||||||
filename = "phixxy.com/ai-blog/index.html"
|
filename = "phixxy.com/ai-blog/index.html"
|
||||||
with open(filename, 'r', encoding="utf-8") as f:
|
with open(filename, 'r', encoding="utf-8") as f:
|
||||||
html_data = f.read()
|
html_data = f.read()
|
||||||
|
|
@ -666,6 +660,19 @@ async def blog(ctx):
|
||||||
if date in html_data:
|
if date in html_data:
|
||||||
await ctx.send("I already wrote a blog post today!")
|
await ctx.send("I already wrote a blog post today!")
|
||||||
return
|
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-->
|
post_div = '''<!--replace this with a post-->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue