Skip to content

Commit

Permalink
fix: change defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
camalot committed Nov 20, 2023
1 parent c43fc54 commit c271658
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions bot/cogs/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def save(self, ctx):
categoryId=category_id,
channelLimit=0,
channelLocked=False,
bitrate=CategorySettingsDefaults.BITRATE_DEFAULT.value,
bitrate=CategorySettingsDefaults.BITRATE
defaultRole=temp_default_role.id if temp_default_role else None,
)

Expand Down Expand Up @@ -184,7 +184,7 @@ async def _name(self, ctx, name: typing.Optional[str] = None, saveSettings: bool
categoryId=category_id,
channelLimit=0,
channelLocked=False,
bitrate=CategorySettingsDefaults.BITRATE_DEFAULT.value,
bitrate=CategorySettingsDefaults.BITRATE,
defaultRole=temp_default_role.id if temp_default_role else None,
)

Expand Down
40 changes: 21 additions & 19 deletions bot/cogs/channel_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async def on_guild_channel_update(self, before, after):
temp_default_role = utils.get_by_name_or_id(after.guild.roles, default_role)
self.log.debug(guild_id, _method, f"temp_default_role: {temp_default_role}")
user_settings = self.usersettings_db.get_user_settings(guild_id, owner_id)
system_default_role = after.guild.default_role

self.log.debug(guild_id, _method , f"Channel Type: {after.type}")

Expand Down Expand Up @@ -115,13 +116,14 @@ async def on_guild_channel_update(self, before, after):
guildId=guild_id,
userId=owner_id,
channelName=after.name,
channelLimit=0,
channelLocked=False,
bitrate=CategorySettingsDefaults.BITRATE_DEFAULT.value,
defaultRole=temp_default_role.id,
autoGame=False,
autoName=True,
allowSoundboard=False,)
channelLimit=CategorySettingsDefaults.CHANNEL_LIMIT,
channelLocked=CategorySettingsDefaults.LOCKED,
bitrate=CategorySettingsDefaults.BITRATE,
defaultRole=temp_default_role.id if temp_default_role else system_default_role.id,
autoGame=CategorySettingsDefaults.AUTO_GAME,
autoName=CategorySettingsDefaults.AUTO_NAME,
allowSoundboard=CategorySettingsDefaults.ALLOW_SOUNDBOARD,
)
except discord.errors.NotFound as nf:
self.log.warn(guild_id, _method, str(nf), traceback.format_exc())
except Exception as e:
Expand Down Expand Up @@ -178,12 +180,12 @@ async def on_voice_state_update(self, member, before, after):
) or 0

# CHANNEL SETTINGS START
limit = CategorySettingsDefaults.CHANNEL_LIMIT_DEFAULT.value
locked = False
auto_name = True
auto_game = False
allow_soundboard = False
bitrate = CategorySettingsDefaults.BITRATE_DEFAULT.value
limit = CategorySettingsDefaults.CHANNEL_LIMIT
locked = CategorySettingsDefaults.LOCKED
auto_name = CategorySettingsDefaults.AUTO_NAME
auto_game = CategorySettingsDefaults.AUTO_GAME
allow_soundboard = CategorySettingsDefaults.ALLOW_SOUNDBOARD
bitrate = CategorySettingsDefaults.BITRATE
name = utils.get_random_name()
user_name = name
# get game activity from all activities
Expand Down Expand Up @@ -215,12 +217,12 @@ async def on_voice_state_update(self, member, before, after):
auto_game = guildSettings.auto_game
allow_soundboard = guildSettings.allow_soundboard
else:
limit = CategorySettingsDefaults.CHANNEL_LIMIT_DEFAULT.value
locked = False
bitrate = CategorySettingsDefaults.BITRATE_DEFAULT.value
auto_name = True
auto_game = False
allow_soundboard = False
limit = CategorySettingsDefaults.CHANNEL_LIMIT
locked = CategorySettingsDefaults.LOCKED
bitrate = CategorySettingsDefaults.BITRATE
auto_name = CategorySettingsDefaults.AUTO_NAME
auto_game = CategorySettingsDefaults.AUTO_GAME
allow_soundboard = CategorySettingsDefaults.ALLOW_SOUNDBOARD
else:
user_name = userSettings.channel_name
limit = userSettings.channel_limit
Expand Down
12 changes: 7 additions & 5 deletions bot/cogs/lib/enums/category_settings_defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from enum import Enum


class CategorySettingsDefaults(Enum):
CHANNEL_LIMIT_DEFAULT = 0
BITRATE_DEFAULT = 64
class CategorySettingsDefaults:
CHANNEL_LIMIT: int = 0
BITRATE: int = 64
ALLOW_SOUNDBOARD: bool = False
AUTO_GAME: bool = False
AUTO_NAME: bool = True
LOCKED: bool = False
6 changes: 3 additions & 3 deletions bot/cogs/lib/models/category_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def __init__(self, **kwargs):
if not isinstance(kwargs.get("channel_limit"), int):
raise ValueError("channel_limit must be an integer")
# if channel_limit is less than 0
if kwargs.get("channel_limit", CategorySettingsDefaults.CHANNEL_LIMIT_DEFAULT.value) < 0:
if kwargs.get("channel_limit", CategorySettingsDefaults.CHANNEL_LIMIT) < 0:
raise ValueError("channel_limit must be greater than or equal to 0")
self.channel_limit = int(kwargs.get("channel_limit", CategorySettingsDefaults.CHANNEL_LIMIT_DEFAULT.value))
self.channel_limit = int(kwargs.get("channel_limit", CategorySettingsDefaults.CHANNEL_LIMIT))

self.channel_locked = kwargs.get("channel_locked", False)
if kwargs.get("bitrate") is not None:
if not isinstance(kwargs.get("bitrate"), int):
raise ValueError("bitrate must be an integer")
if kwargs.get("bitrate", CategorySettingsDefaults.BITRATE_DEFAULT.value) < 0:
if kwargs.get("bitrate", CategorySettingsDefaults.BITRATE) < 0:
raise ValueError("bitrate must be greater than or equal to 0")
self.bitrate = kwargs.get("bitrate")
if kwargs.get("default_role") is not None:
Expand Down
5 changes: 2 additions & 3 deletions bot/cogs/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ def str_replace(input_string: str, *args, **kwargs) -> str:

def get_by_name_or_id(iterable, nameOrId: typing.Optional[typing.Union[int, str]]):
if isinstance(nameOrId, str):
val = discord.utils.get(iterable, name=nameOrId)
val = discord.utils.get(iterable, name=str(nameOrId))
if val is None:
val = discord.utils.get(iterable, id=int(nameOrId))
return val
elif isinstance(nameOrId, int):
val = discord.utils.get(iterable, id=nameOrId)
print(val)
val = discord.utils.get(iterable, id=int(nameOrId))
return val
else:
print("get_by_name_or_id: nameOrId is not a string or int")
Expand Down

0 comments on commit c271658

Please sign in to comment.