image change
This commit is contained in:
parent
108471edfd
commit
7b00e844fd
13
garfbot.py
13
garfbot.py
@ -26,7 +26,7 @@ file_handler = TimedRotatingFileHandler(
|
|||||||
when='midnight',
|
when='midnight',
|
||||||
interval=1,
|
interval=1,
|
||||||
backupCount=7,
|
backupCount=7,
|
||||||
delay=True # Counterintuitively, will flush output immediately
|
delay=True # Counter-intuitively, this will flush output immediately
|
||||||
)
|
)
|
||||||
console_handler = logging.StreamHandler()
|
console_handler = logging.StreamHandler()
|
||||||
formatter=logging.Formatter(
|
formatter=logging.Formatter(
|
||||||
@ -137,7 +137,6 @@ user_stats = json_load(stats_file, {})
|
|||||||
async def on_ready():
|
async def on_ready():
|
||||||
asyncio.create_task(process_image_requests()) # Important!
|
asyncio.create_task(process_image_requests()) # Important!
|
||||||
logger.info(f"Logged in as {garfbot.user.name} running {txtmodel} and {imgmodel}.")
|
logger.info(f"Logged in as {garfbot.user.name} running {txtmodel} and {imgmodel}.")
|
||||||
print(f"Logged in as {garfbot.user.name} running {txtmodel} and {imgmodel}.", flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
# GarfChats
|
# GarfChats
|
||||||
@ -201,13 +200,12 @@ async def process_image_requests():
|
|||||||
if resp.status == 200:
|
if resp.status == 200:
|
||||||
image_data = await resp.read()
|
image_data = await resp.read()
|
||||||
timestamp = message.created_at.strftime('%Y%m%d%H%M%S')
|
timestamp = message.created_at.strftime('%Y%m%d%H%M%S')
|
||||||
save_filename = f"images/{timestamp}_generated_image.png"
|
save_filename = f"{timestamp}_generated_image.png"
|
||||||
send_filename = f"{timestamp}_generated_image.png" # There is probably a better way to do this.
|
|
||||||
with open(save_filename, "wb") as f:
|
with open(save_filename, "wb") as f:
|
||||||
f.write(image_data)
|
f.write(image_data)
|
||||||
with open(save_filename, "rb") as f:
|
with open(save_filename, "rb") as f:
|
||||||
await message.channel.send(file=discord.File(f, send_filename))
|
await message.channel.send(file=discord.File(f, save_filename))
|
||||||
os.remove(send_filename)
|
os.remove(save_filename)
|
||||||
else:
|
else:
|
||||||
await message.channel.send("`GarfBot Error: Odie`")
|
await message.channel.send("`GarfBot Error: Odie`")
|
||||||
else:
|
else:
|
||||||
@ -402,6 +400,7 @@ async def send_gif(message, search_term):
|
|||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
top_50gifs = json.loads(r.content)
|
top_50gifs = json.loads(r.content)
|
||||||
gif_url = random.choice(top_50gifs["results"])["itemurl"]
|
gif_url = random.choice(top_50gifs["results"])["itemurl"]
|
||||||
|
logger.info(gif_url)
|
||||||
print(gif_url)
|
print(gif_url)
|
||||||
try:
|
try:
|
||||||
await message.channel.send(gif_url)
|
await message.channel.send(gif_url)
|
||||||
@ -427,7 +426,7 @@ async def garfbot_connect():
|
|||||||
e = str(e)
|
e = str(e)
|
||||||
logger.error(f"Garfbot couldn't connect! {e}")
|
logger.error(f"Garfbot couldn't connect! {e}")
|
||||||
print(f"Garfbot couldn't connect! {e}", flush=True)
|
print(f"Garfbot couldn't connect! {e}", flush=True)
|
||||||
await asyncio.sleep(300)
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
Loading…
Reference in New Issue
Block a user