Skip to content

Commit 427723d

Browse files
authored
Merge pull request #115 from davidhozic/develop
V1.9
2 parents 3018068 + ddd88b2 commit 427723d

File tree

7 files changed

+230
-126
lines changed

7 files changed

+230
-126
lines changed

documentation_src/er_diagram.png

-813 Bytes
Loading

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
__metadata__ = \
1414
{
15-
"version" : "1.9.rc2",
15+
"version" : "1.9",
1616
"requirements" : req,
1717
"minimum_py_version" : "3.8",
1818
}

src/framework/const.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
C_VC_CONNECT_TIMEOUT = 3 # Timeout of voice channels
1414

1515
# RATE LIMIT CONSTANTS
16-
C_USER_WAIT_TIME = 1.5 # Initial rate limit avoidance time for user accounts (0 for bot accounts)
17-
C_RATE_LIMIT_SAFETY_FACTOR = 1.10 # In case of a rate limit, wait times this more
16+
RLIM_USER_WAIT_TIME = 1.5 # Initial rate limit avoidance time for user accounts (0 for bot accounts)
17+
RLIM_SAFETY_FACTOR = 1.10 # In case of a rate limit, wait times this more
1818

1919
# SQL CONFIGURATION
20-
C_FAIL_RETRIES = 10
21-
C_RECOVERY_TIME = 0.25
22-
C_RECONNECT_TIME = 5 * C_MINUTE_TO_SECOND
23-
C_RECONNECT_ATTEMPTS = 3
24-
C_CONNECTOR_TIMEOUT = 3
20+
SQL_MAX_SAVE_ATTEMPTS = 10
21+
SQL_MAX_EHANDLE_ATTEMPTS = 3
22+
SQL_RECOVERY_TIME = 0.5
23+
SQL_RECONNECT_TIME = 5 #* C_MINUTE_TO_SECOND
24+
SQL_RECONNECT_ATTEMPTS = 3
25+
SQL_CONNECTOR_TIMEOUT = 6
2526

2627
# OTHER CONSTANTS
2728
C_FILE_NAME_FORBIDDEN_CHAR = ('<','>','"','/','\\','|','?','*',":")

src/framework/guild.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from . import sql
1515
import time
1616
import json
17-
import pathlib
17+
import pathlib
1818

1919
__all__ = (
2020
"GUILD",
@@ -99,8 +99,8 @@ async def advertise(self,
9999
"""
100100
raise NotImplementedError
101101

102-
def generate_log(self,
103-
message_context: dict) -> None:
102+
async def generate_log(self,
103+
message_context: dict) -> None:
104104
"""
105105
Name: generate_log
106106
Param:
@@ -117,8 +117,8 @@ def generate_log(self,
117117
try:
118118
manager = sql.get_sql_manager()
119119
if (
120-
manager is None or # Short circuit evaluation
121-
not manager.save_log(guild_context, message_context)
120+
manager is None or # Short circuit evaluation
121+
not await manager.save_log(guild_context, message_context)
122122
):
123123
timestruct = time.localtime()
124124
timestamp = "{:02d}.{:02d}.{:04d} {:02d}:{:02d}:{:02d}".format(timestruct.tm_mday,
@@ -272,7 +272,7 @@ async def advertise(self,
272272
if len(message.channels) == 0:
273273
marked_del.append(message) # All channels were removed (either not found or forbidden) -> remove message from send list
274274
if self._generate_log and message_ret is not None:
275-
self.generate_log(message_ret)
275+
await self.generate_log(message_ret)
276276

277277
# Cleanup messages marked for removal
278278
for message in marked_del:
@@ -364,7 +364,7 @@ async def advertise(self,
364364
message.reset_timer()
365365
message_ret = await message.send()
366366
if self._generate_log and message_ret is not None:
367-
self.generate_log(message_ret)
367+
await self.generate_log(message_ret)
368368

369369
if message.dm_channel is None:
370370
self.t_messages.clear() # Remove all messages since that they all share the same user and will fail

src/framework/message.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ async def handle_error(self, channel: Union[discord.TextChannel, discord.Thread]
561561
handled = False
562562
if isinstance(ex, discord.HTTPException):
563563
if ex.status == 429: # Rate limit
564-
retry_after = int(ex.response.headers["Retry-After"]) * C_RATE_LIMIT_SAFETY_FACTOR
564+
retry_after = int(ex.response.headers["Retry-After"]) * RLIM_SAFETY_FACTOR
565565
if ex.code == 20016: # Slow Mode
566566
self.force_retry["ENABLED"] = True
567567
self.force_retry["TIME"] = retry_after
@@ -636,7 +636,7 @@ async def send(self) -> Union[dict, None]:
636636
for channel in self.channels:
637637
# Clear previous messages sent to channel if mode is MODE_DELETE_SEND
638638
if GLOBALS.is_user:
639-
await asyncio.sleep(C_USER_WAIT_TIME)
639+
await asyncio.sleep(RLIM_USER_WAIT_TIME)
640640
context = await self.send_channel(channel, **data_to_send)
641641
if context["success"]:
642642
succeded_channels.append(channel)
@@ -783,7 +783,7 @@ async def handle_error(self, ex: Exception):
783783
handled = False
784784
if isinstance(ex, discord.HTTPException):
785785
if ex.status == 429 or ex.code == 40003: # Too Many Requests or opening DMs too fast
786-
retry_after = float(ex.response.headers["Retry-After"]) * C_RATE_LIMIT_SAFETY_FACTOR
786+
retry_after = float(ex.response.headers["Retry-After"]) * RLIM_SAFETY_FACTOR
787787
trace(f"Rate limited, sleeping for {retry_after} seconds", TraceLEVELS.WARNING)
788788
await asyncio.sleep(retry_after)
789789
handled = True
@@ -792,7 +792,7 @@ async def handle_error(self, ex: Exception):
792792
self.previous_message = None
793793
handled = True
794794
elif ex.status == 400: # Bad Request
795-
await asyncio.sleep(C_USER_WAIT_TIME * 5) # To avoid triggering selfbot detection
795+
await asyncio.sleep(RLIM_USER_WAIT_TIME * 5) # To avoid triggering selfbot detection
796796

797797
return handled
798798

@@ -845,7 +845,7 @@ async def send(self) -> Union[dict, None]:
845845
data_to_send = self.get_data()
846846
if any(data_to_send.values()):
847847
if GLOBALS.is_user:
848-
await asyncio.sleep(C_USER_WAIT_TIME)
848+
await asyncio.sleep(RLIM_USER_WAIT_TIME)
849849
context = await self.send_channel(**data_to_send)
850850
if context["success"] is False:
851851
reason = context["reason"]

0 commit comments

Comments
 (0)