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

Fix styling since merge funkiness removed the last one #119

Merged
merged 10 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use line ending normalisation on all files
* text=auto
19 changes: 19 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[yapf]
based_on_style = pep8
column_limit = 127
indent_width = 4
dedent_closing_brackets = true
split_all_comma_separated_values = true
split_before_arithmetic_operator = true
split_before_bitwise_operator = true
each_dict_entry_on_separate_line = true

[flake8]
max-line-length = 127

[pycodestyle]
max-line-length = 127

[mypy]
show_error_codes = True
disable_error_code = import
9 changes: 3 additions & 6 deletions src/esportsbot/base_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@


async def send_to_log_channel(self, guild_id, msg):
db_logging_call = db_gateway().get(
'guild_info', params={'guild_id': guild_id})
db_logging_call = db_gateway().get('guild_info', params={'guild_id': guild_id})
if db_logging_call and db_logging_call[0]['log_channel_id']:
await self.bot.get_channel(db_logging_call[0]['log_channel_id']).send(msg)

Expand Down Expand Up @@ -49,12 +48,10 @@ def user_id_from_mention(pre_clean_data: str) -> int:


def get_whether_in_vm_master(guild_id, channel_id):
in_master = db_gateway().get('voicemaster_master', params={
'guild_id': guild_id, 'channel_id': channel_id})
in_master = db_gateway().get('voicemaster_master', params={'guild_id': guild_id, 'channel_id': channel_id})
return bool(in_master)


def get_whether_in_vm_slave(guild_id, channel_id):
in_slave = db_gateway().get('voicemaster_slave', params={
'guild_id': guild_id, 'channel_id': channel_id})
in_slave = db_gateway().get('voicemaster_slave', params={'guild_id': guild_id, 'channel_id': channel_id})
return bool(in_slave)
80 changes: 53 additions & 27 deletions src/esportsbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from datetime import datetime, timedelta
import asyncio


# Value to assign new guilds in their role_ping_cooldown_seconds attribute
DEFAULT_ROLE_PING_COOLDOWN = timedelta(hours=5)
# Value to assign new guilds in their pingme_create_poll_length_seconds attribute
Expand All @@ -34,13 +33,17 @@ def make_guild_init_data(guild: discord.Guild) -> Dict[str, Any]:
:return: A dictionary with default guild attributes, including the guild ID
:rtype: Dict[str, Any]
"""
return {'guild_id': guild.id, 'num_running_polls': 0, 'role_ping_cooldown_seconds': int(DEFAULT_ROLE_PING_COOLDOWN.total_seconds()),
"pingme_create_threshold": DEFAULT_PINGME_CREATE_THRESHOLD, "pingme_create_poll_length_seconds": int(DEFAULT_PINGME_CREATE_POLL_LENGTH.total_seconds())}
return {
'guild_id': guild.id,
'num_running_polls': 0,
'role_ping_cooldown_seconds': int(DEFAULT_ROLE_PING_COOLDOWN.total_seconds()),
"pingme_create_threshold": DEFAULT_PINGME_CREATE_THRESHOLD,
"pingme_create_poll_length_seconds": int(DEFAULT_PINGME_CREATE_POLL_LENGTH.total_seconds())
}


async def send_to_log_channel(guild_id, msg):
db_logging_call = db_gateway().get(
'guild_info', params={'guild_id': guild_id})
db_logging_call = db_gateway().get('guild_info', params={'guild_id': guild_id})
if db_logging_call and db_logging_call[0]['log_channel_id']:
await client.get_channel(db_logging_call[0]['log_channel_id']).send(msg)

Expand All @@ -50,7 +53,11 @@ async def on_ready():
"""Initialize the reactionMenuDB and pingme role cooldowns, since this can't be done synchronously
"""
await client.init()
await client.change_presence(status=discord.Status.dnd, activity=discord.Activity(type=discord.ActivityType.listening, name="your commands"))
await client.change_presence(
status=discord.Status.dnd,
activity=discord.Activity(type=discord.ActivityType.listening,
name="your commands")
)


@client.event
Expand All @@ -67,14 +74,15 @@ async def on_guild_remove(guild):

@client.event
async def on_member_join(member):
default_role_exists = db_gateway().get(
'guild_info', params={'guild_id': member.guild.id})
default_role_exists = db_gateway().get('guild_info', params={'guild_id': member.guild.id})

if default_role_exists[0]['default_role_id']:
default_role = member.guild.get_role(
default_role_exists[0]['default_role_id'])
default_role = member.guild.get_role(default_role_exists[0]['default_role_id'])
await member.add_roles(default_role)
await send_to_log_channel(member.guild.id, f"{member.mention} has joined the server and received the {default_role.mention} role")
await send_to_log_channel(
member.guild.id,
f"{member.mention} has joined the server and received the {default_role.mention} role"
)
else:
await send_to_log_channel(member.guild.id, f"{member.mention} has joined the server")

Expand All @@ -89,23 +97,38 @@ async def on_voice_state_update(member, before, after):
if not before.channel.members:
# Nobody else in VC
await before.channel.delete()
db_gateway().delete('voicemaster_slave', where_params={
'guild_id': member.guild.id, 'channel_id': before_channel_id})
db_gateway().delete(
'voicemaster_slave',
where_params={
'guild_id': member.guild.id,
'channel_id': before_channel_id
}
)
await send_to_log_channel(member.guild.id, f"{member.mention} has deleted a VM slave")
else:
# Still others in VC
await before.channel.edit(name=f"{before.channel.members[0].display_name}'s VC")
db_gateway().update('voicemaster_slave', set_params={'owner_id': before.channel.members[0].id}, where_params={
'guild_id': member.guild.id, 'channel_id': before_channel_id})
db_gateway().update(
'voicemaster_slave',
set_params={'owner_id': before.channel.members[0].id},
where_params={
'guild_id': member.guild.id,
'channel_id': before_channel_id
}
)
elif after_channel_id and get_whether_in_vm_master(member.guild.id, after_channel_id):
# Moved into a master VM VC
slave_channel_name = f"{member.display_name}'s VC"
new_slave_channel = await member.guild.create_voice_channel(slave_channel_name, category=after.channel.category)
db_gateway().insert('voicemaster_slave', params={'guild_id': member.guild.id,
'channel_id': new_slave_channel.id,
'owner_id': member.id,
'locked': False,
})
db_gateway().insert(
'voicemaster_slave',
params={
'guild_id': member.guild.id,
'channel_id': new_slave_channel.id,
'owner_id': member.id,
'locked': False,
}
)
await member.move_to(new_slave_channel)
await send_to_log_channel(member.guild.id, f"{member.mention} has created a VM slave")

Expand Down Expand Up @@ -202,24 +225,28 @@ async def on_command_error(ctx: Context, exception: Exception):
:param Exception exception: The exception caused by the message in ctx
"""
if isinstance(exception, MissingRequiredArgument):
await ctx.message.reply("Arguments are required for this command! See `" + client.command_prefix + "help " + ctx.invoked_with + "` for more information.")
await ctx.message.reply(
"Arguments are required for this command! See `" + client.command_prefix + "help " + ctx.invoked_with
+ "` for more information."
)
elif isinstance(exception, CommandNotFound):
try:
await ctx.message.add_reaction(client.unknownCommandEmoji.sendable)
except (Forbidden, HTTPException):
pass
except NotFound:
raise ValueError("Invalid unknownCommandEmoji: "
+ client.unknownCommandEmoji.sendable)
raise ValueError("Invalid unknownCommandEmoji: " + client.unknownCommandEmoji.sendable)
else:
sourceStr = str(ctx.message.id)
try:
sourceStr += "/" + ctx.channel.name + "#" + str(ctx.channel.id) \
+ "/" + ctx.guild.name + "#" + str(ctx.guild.id)
except AttributeError:
sourceStr += "/DM@" + ctx.author.name + "#" + str(ctx.author.id)
print(datetime.now().strftime("%m/%d/%Y %H:%M:%S - Caught "
+ type(exception).__name__ + " '") + str(exception) + "' from message " + sourceStr)
print(
datetime.now().strftime("%m/%d/%Y %H:%M:%S - Caught " + type(exception).__name__ + " '") + str(exception)
+ "' from message " + sourceStr
)
lib.exceptions.print_exception_trace(exception)


Expand Down Expand Up @@ -257,8 +284,7 @@ async def on_message(message):
@client.command()
@commands.has_permissions(administrator=True)
async def initialsetup(ctx):
already_in_db = db_gateway().get(
'guild_info', params={'guild_id': ctx.author.guild.id})
already_in_db = db_gateway().get('guild_info', params={'guild_id': ctx.author.guild.id})
if already_in_db:
await ctx.channel.send("This server is already set up")
else:
Expand Down
9 changes: 7 additions & 2 deletions src/esportsbot/cogs/AdminCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ def __init__(self, bot):
@commands.command(aliases=['cls', 'purge', 'delete', 'Cls', 'Purge', 'Delete', 'Clear'])
@commands.has_permissions(manage_messages=True)
async def clear(self, ctx, amount=5):
await ctx.channel.purge(limit=int(amount)+1)
await send_to_log_channel(self, ctx.author.guild.id, self.STRINGS['channel_cleared'].format(author_mention = ctx.author.mention, message_amount=amount))
await ctx.channel.purge(limit=int(amount) + 1)
await send_to_log_channel(
self,
ctx.author.guild.id,
self.STRINGS['channel_cleared'].format(author_mention=ctx.author.mention,
message_amount=amount)
)

@commands.command(aliases=['Members'])
@commands.has_permissions(manage_messages=True)
Expand Down
36 changes: 22 additions & 14 deletions src/esportsbot/cogs/DefaultRoleCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ def __init__(self, bot):
@commands.command()
@commands.has_permissions(administrator=True)
async def setdefaultrole(self, ctx, given_role_id=None):
cleaned_role_id = role_id_from_mention(
given_role_id) if given_role_id else False
cleaned_role_id = role_id_from_mention(given_role_id) if given_role_id else False
if cleaned_role_id:
db_gateway().update('guild_info', set_params={
'default_role_id': cleaned_role_id}, where_params={'guild_id': ctx.author.guild.id})
db_gateway().update(
'guild_info',
set_params={'default_role_id': cleaned_role_id},
where_params={'guild_id': ctx.author.guild.id}
)
await ctx.channel.send(self.STRINGS['default_role_set'].format(role_id=cleaned_role_id))
default_role = ctx.author.guild.get_role(cleaned_role_id)
await send_to_log_channel(
self,
ctx.author.guild.id,
self.STRINGS['default_role_set_log'].format(author=ctx.author.mention, role_mention=default_role.mention)
self,
ctx.author.guild.id,
self.STRINGS['default_role_set_log'].format(author=ctx.author.mention,
role_mention=default_role.mention)
)
else:
await ctx.channel.send(self.STRINGS['default_role_set_missing_params'])

@commands.command()
@commands.has_permissions(administrator=True)
async def getdefaultrole(self, ctx):
default_role_exists = db_gateway().get(
'guild_info', params={'guild_id': ctx.author.guild.id})
default_role_exists = db_gateway().get('guild_info', params={'guild_id': ctx.author.guild.id})

if default_role_exists[0]['default_role_id']:
await ctx.channel.send(self.STRINGS['default_role_get'].format(role_id=default_role_exists[0]['default_role_id']))
Expand All @@ -42,14 +44,20 @@ async def getdefaultrole(self, ctx):
@commands.command()
@commands.has_permissions(administrator=True)
async def removedefaultrole(self, ctx):
default_role_exists = db_gateway().get(
'guild_info', params={'guild_id': ctx.author.guild.id})
default_role_exists = db_gateway().get('guild_info', params={'guild_id': ctx.author.guild.id})

if default_role_exists[0]['default_role_id']:
db_gateway().update('guild_info', set_params={
'default_role_id': 'NULL'}, where_params={'guild_id': ctx.author.guild.id})
db_gateway().update(
'guild_info',
set_params={'default_role_id': 'NULL'},
where_params={'guild_id': ctx.author.guild.id}
)
await ctx.channel.send(self.STRINGS['default_role_removed'])
await send_to_log_channel(self, ctx.author.guild.id, self.STRINGS['default_role_removed_log'].format(author_mention=ctx.author.mention))
await send_to_log_channel(
self,
ctx.author.guild.id,
self.STRINGS['default_role_removed_log'].format(author_mention=ctx.author.mention)
)
else:
await ctx.channel.send(self.STRINGS['default_role_missing'])

Expand Down
Loading