Reduced max messages and number of threads

This commit is contained in:
Luis Mayo Valbuena 2022-12-19 13:25:52 +01:00
parent 598986469c
commit 7664fbf281
2 changed files with 13 additions and 8 deletions

19
main.py
View File

@ -7,7 +7,7 @@ import threading
import time
import json
import yaml
import gc
sys.path.append("./objection_engine")
from deletion import Deletion
@ -64,7 +64,7 @@ def loadConfig():
if not loadConfig():
exit()
courtBot = commands.AutoShardedBot(command_prefix=prefix, Intents=intents)
courtBot = commands.AutoShardedBot(command_prefix=prefix, Intents=intents, max_messages=None)
# Default 'help' command is removed, we will make our own
courtBot.remove_command("help")
currentActivityText = f"{prefix}help"
@ -156,8 +156,8 @@ async def render(context, numberOfMessages: int, music: str = 'pwr'):
if (len(petitionsFromSameUser) > max_per_user):
raise Exception(f"Only up to {max_per_user} renders per user are allowed")
await feedbackMessage.edit(content="`Fetching messages...`")
if not (numberOfMessages in range(1, 151)):
raise Exception("Number of messages must be between 1 and 150")
if not (numberOfMessages in range(1, 101)):
raise Exception("Number of messages must be between 1 and 100")
# baseMessage is the message from which the specified number of messages will be fetch, not including itself
baseMessage = context.message.reference.resolved if context.message.reference else context.message
@ -191,6 +191,11 @@ async def render(context, numberOfMessages: int, music: str = 'pwr'):
await feedbackMessage.edit(content="", embed=exceptionEmbed)
addToDeletionQueue(feedbackMessage)
@tasks.loop(minutes=5)
async def garbageCollection():
gc.collect()
print("Garbage collected")
@tasks.loop(seconds=1)
async def deletionQueueLoop():
global deletionQueue
@ -349,9 +354,9 @@ backgroundThread = threading.Thread(target=renderThread, name="RenderThread")
backgroundThread.start()
# Even while threads in python are not concurrent in CPU, the rendering process may use a lot of disk I/O so having two threads
# May help speed up things
backgroundThread2 = threading.Thread(target=renderThread, name="RenderThread2")
backgroundThread2.start()
#backgroundThread2 = threading.Thread(target=renderThread, name="RenderThread2")
#backgroundThread2.start()
courtBot.run(token)
backgroundThread.join()
backgroundThread2.join()
#backgroundThread2.join()

View File

@ -1,4 +1,4 @@
discord.py
discord.py==1.7.3
emoji
pyyaml
objection_engine