Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send multiple JOIN commands if 512 bytes message length is violated #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions heisenbridge/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ async def _run(self):
last = loop.time()
penalty = 0

async def send_and_sleep(self, message):
super().send_raw(message)
# sleep is based on message length
sleep_time = max(len(message.encode()) / 512 * 6, 1.5)
if penalty > 5 or sleep_time > 1.5:
await asyncio.sleep(sleep_time)

while True:
try:
(priority, string, tag) = await self._queue.get()
Expand All @@ -199,13 +206,14 @@ async def _run(self):
if penalty < 0:
penalty = 0

super().send_raw(string)

# sleep is based on message length
sleep_time = max(len(string.encode()) / 512 * 6, 1.5)
if len(string) > 510 and string.split(" ")[0].lower() == "join":
n_splits = int(len(string) / 512) + (len(string) % 512 > 0)
channels = "".join(string.split(" ")[1:]).split(",")

if penalty > 5 or sleep_time > 1.5:
await asyncio.sleep(sleep_time)
for i in range(n_splits):
await send_and_sleep(self, "JOIN " + ",".join(channels[i::n_splits]))
else:
await send_and_sleep(self, string)

# this needs to be reset if we slept
last = loop.time()
Expand Down