Skip to content

Commit

Permalink
wait until existence
Browse files Browse the repository at this point in the history
  • Loading branch information
greeeen-dev committed Sep 24, 2024
1 parent 440b622 commit f8e715f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions cogs/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,18 +978,23 @@ async def find_thread(self,thread_id):
return {thread: self.__bot.db['threads'][thread]}
return None

async def fetch_message(self,message_id,prehook=False,not_prehook=False):
async def fetch_message(self,message_id,prehook=False,not_prehook=False,can_wait=False):
if prehook and not_prehook:
raise ValueError('Conflicting arguments')
for message in self.bridged:
if (str(message.id)==str(message_id) or str(message_id) in str(message.copies) or
str(message_id) in str(message.external_copies) or str(message.prehook)==str(message_id)):
if prehook and str(message.prehook)==str(message_id) and not str(message.id) == str(message_id):
return message
elif not_prehook and not str(message.prehook) == str(message_id):
return message
elif not prehook:
return message
waiting = self.__bot.config['existence_wait']
if waiting <= 0 or not can_wait:
waiting = 1
for waited in range(waiting):
for message in self.bridged:
if (str(message.id)==str(message_id) or str(message_id) in str(message.copies) or
str(message_id) in str(message.external_copies) or str(message.prehook)==str(message_id)):
if prehook and str(message.prehook)==str(message_id) and not str(message.id) == str(message_id):
return message
elif not_prehook and not str(message.prehook) == str(message_id):
return message
elif not prehook:
return message
await asyncio.sleep(1)
raise ValueError("No message found")

async def delete_message(self,message):
Expand Down Expand Up @@ -1332,7 +1337,8 @@ async def make_friendly(self, text, source):
return text

async def edit(self, message, content):
msg: UnifierBridge.UnifierMessage = await self.fetch_message(message)
msg: UnifierBridge.UnifierMessage = await self.fetch_message(message, can_wait=True)

threads = []

async def edit_discord(msgs,friendly=False):
Expand Down
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ debug = false
package = "unifier"
language = "english"
skip_status_check = false
encrypted_env = false
encrypted_env_salt = 10

[roles]
Expand Down Expand Up @@ -52,6 +51,7 @@ use_multicore = true
allow_posts = false
enable_exp = false
exp_cooldown = 30
existence_wait = 0
enable_emoji_tags = false
enable_ctx_commands = true
enable_rotating_status = true
Expand Down

0 comments on commit f8e715f

Please sign in to comment.