Remove `fetch_message`, channel history is just better

pull/167/head
bobloy 4 years ago
parent c603e4b326
commit ce41c80c3b

@ -1,6 +1,6 @@
import logging import logging
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Dict, List, Union from typing import Dict, List, Optional, Union
import discord import discord
from apscheduler.triggers.base import BaseTrigger from apscheduler.triggers.base import BaseTrigger
@ -269,20 +269,23 @@ class Task:
) )
return False return False
actual_message: discord.Message = channel.last_message actual_message: Optional[discord.Message] = channel.last_message
# I'd like to present you my chain of increasingly desperate message fetching attempts # I'd like to present you my chain of increasingly desperate message fetching attempts
if actual_message is None: if actual_message is None:
# log.warning("No message found in channel cache yet, skipping execution") # Skip this one, never goes well
# return # try:
actual_message = await channel.fetch_message(channel.last_message_id) # actual_message = await channel.fetch_message(channel.last_message_id)
if actual_message is None: # last_message_id was an invalid message I guess # except discord.NotFound:
actual_message = await channel.history(limit=1).flatten() # actual_message = None
if not actual_message: # Basically only happens if the channel has no messages # if actual_message is None: # last_message_id was an invalid message I guess
actual_message = await author.history(limit=1).flatten()
if not actual_message: # Okay, the *author* has never sent a message? actual_message = await channel.history(limit=1).flatten()
log.warning("No message found in channel cache yet, skipping execution") if not actual_message: # Basically only happens if the channel has no messages
return False actual_message = await author.history(limit=1).flatten()
actual_message = actual_message[0] if not actual_message: # Okay, the *author* has never sent a message?
log.warning("No message found in channel cache yet, skipping execution")
return False
actual_message = actual_message[0]
message = FakeMessage(actual_message) message = FakeMessage(actual_message)
# message = FakeMessage2 # message = FakeMessage2

Loading…
Cancel
Save