Put stuff into functions for lost messages

This commit is contained in:
Fierelier 2020-11-24 17:57:22 +01:00
parent 28bcba6cf2
commit 74fda1795b
1 changed files with 31 additions and 39 deletions

View File

@ -134,7 +134,7 @@ class dbfTextBrowser:
for text in texts:
processedText = ""
raw = False
print(str(text))
#print(str(text))
if "raw" in text: raw = text["raw"]
if raw:
processedText = text["text"]
@ -505,6 +505,34 @@ def discordClient(token):
channelFilter = (discord.DMChannel,discord.GroupChannel)
global loginPath
async def fetchLostMessages(channel):
newTime = None
async for msg in channel.history(limit=1):
newTime = msg.created_at
if not newTime: return
oldTime = getLastMessageTime(channel)
if not oldTime:
setLastMessageTime(channel,newTime)
return
async for message in channel.history(limit=100,before=newTime,after=oldTime):
guiLock.acquire()
for gui in openGuis:
if gui.type == "channel":
if message.channel != gui.channel: continue
addGuiTask(gui,gui.addMessage,(message,),{})
guiLock.release()
setLastMessageTime(channel,newTime)
async def fetchAllLostMessages():
print("fetching all lost messages...")
for channel in client.private_channels:
if not type(channel) in channelFilter: continue
await fetchLostMessages(channel)
print("done fetching.")
@client.event
async def on_ready():
print("on_ready")
@ -540,25 +568,7 @@ def discordClient(token):
ready = True
if config["messageTracking"]["trackMessages"] == "true" and config["messageTracking"]["recheckMessages"] == "true":
for channel in client.private_channels:
if not type(channel) in channelFilter: continue
newTime = None
async for msg in channel.history(limit=1):
newTime = msg.created_at
if not newTime: continue
oldTime = getLastMessageTime(channel)
if not oldTime:
setLastMessageTime(channel,newTime)
continue
async for message in channel.history(limit=100,before=newTime,after=oldTime):
guiLock.acquire()
for gui in openGuis:
if gui.type == "channel":
if message.channel != gui.channel: continue
addGuiTask(gui,gui.addMessage,(message,),{})
guiLock.release()
await fetchAllLostMessages()
if online == False:
online = True
@ -570,25 +580,7 @@ def discordClient(token):
global channelFilter
if config["messageTracking"]["trackMessages"] == "true" and config["messageTracking"]["recheckMessages"] == "true":
for channel in client.private_channels:
if not type(channel) in channelFilter: continue
newTime = None
async for msg in channel.history(limit=1):
newTime = msg.created_at
if not newTime: continue
oldTime = getLastMessageTime(channel)
if not oldTime:
setLastMessageTime(channel,newTime)
continue
async for message in channel.history(limit=100,before=newTime,after=oldTime):
guiLock.acquire()
for gui in openGuis:
if gui.type == "channel":
if message.channel != gui.channel: continue
addGuiTask(gui,gui.addMessage,(message,),{})
guiLock.release()
await fetchAllLostMessages()
if online == False:
online = True