Added functions for content filter and notifications

Minor logging for guild updates (Still need to do roles/emojis/features etc etc)
pull/9/head
sgoudham 4 years ago
parent 4cfe7a926c
commit eab9af4876

@ -1,29 +1,18 @@
def string_list(types, n, instance): # Ensō~Chan - A Multi Purpose Discord Bot That Has Everything Your Server Needs!
"""Return objects in nicely formatted strings""" # Copyright (C) 2020 Hamothy
if len(types) > n: # This program is free software: you can redistribute it and/or modify
# Retrieve the length of the remaining roles # it under the terms of the GNU General Public License as published by
length = len(types) - n # the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
if instance == "Emoji": # This program is distributed in the hope that it will be useful,
# Store the first 20 emojis in a string # but WITHOUT ANY WARRANTY; without even the implied warranty of
string = f"{' '.join(map(str, (types[:n])))} and **{length}** more..." # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
else: # GNU General Public License for more details.
# Store the first n roles/members in a string called "roles" (highest to lowest)
string = f"{' **|** '.join(_type.mention for _type in list(reversed(types))[:n])} and **{length}** more"
else: # You should have received a copy of the GNU General Public License
if instance == "Role": # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Display all roles as it is lower than n provided
string = f"{' **|** '.join(role.mention for role in list(reversed(types[1:])))}"
elif instance == "Emoji":
# Display all the emojis in the server as it is less than 20
string = " ".join(map(str, types))
else:
# Display all members as it is lower than n provided
string = f"{' **|** '.join(role.mention for role in list(reversed(types)))}"
return string
# List of regions mapped to emojis # List of regions mapped to emojis
@ -48,6 +37,47 @@ region = {
"brazil": ":flag_br: Brazil" "brazil": ":flag_br: Brazil"
} }
# List of content filters and their descriptions
filters = {
"disabled": "<:xMark:746834944629932032>",
"no_role": "<:greenTick:746834932936212570> For Members Without Roles",
"all_members": "<:greenTick:746834932936212570> For All Members"
}
# List of default notifications settings for guild
notifs = {
"all_messages": "<:greenTick:746834932936212570> For All Messages",
"only_mentions": "<:greenTick:746834932936212570> For All Mentions"
}
def string_list(types, n, instance):
"""Return objects in nicely formatted strings"""
if len(types) > n:
# Retrieve the length of the remaining roles
length = len(types) - n
if instance == "Emoji":
# Store the first 20 emojis in a string
string = f"{' '.join(map(str, (types[:n])))} and **{length}** more..."
else:
# Store the first n roles/members in a string called "roles" (highest to lowest)
string = f"{' **|** '.join(_type.mention for _type in list(reversed(types))[:n])} and **{length}** more"
else:
if instance == "Role":
# Display all roles as it is lower than n provided
string = f"{' **|** '.join(role.mention for role in list(reversed(types[1:])))}"
elif instance == "Emoji":
# Display all the emojis in the server as it is less than 20
string = " ".join(map(str, types))
else:
# Display all members as it is lower than n provided
string = f"{' **|** '.join(role.mention for role in list(reversed(types)))}"
return string
def get_region(disc_region): def get_region(disc_region):
"""Return Nicer Looking Region String""" """Return Nicer Looking Region String"""
@ -55,3 +85,19 @@ def get_region(disc_region):
for key in region: for key in region:
if key == disc_region: if key == disc_region:
return region[key] return region[key]
def get_content_filter(content_filter):
"""Return nicer looking content filter string"""
for key in filters:
if key == content_filter:
return filters[key]
def get_notifs(notif):
"""Return nicer looking notification string"""
for key in notifs:
if key == notif:
return notifs[key]

@ -23,7 +23,7 @@ from discord import Member, Embed, DMChannel, NotFound
from discord.ext.commands import command, guild_only, has_guild_permissions, bot_has_guild_permissions, Greedy, \ from discord.ext.commands import command, guild_only, has_guild_permissions, bot_has_guild_permissions, Greedy, \
cooldown, BucketType, Cog cooldown, BucketType, Cog
from cogs.libs.functions import string_list, get_region from cogs.libs.functions import string_list, get_region, get_content_filter, get_notifs
# TODO: CREATE A BITARRAY SO THAT THE MODLOG EVENTS ARE TOGGLEABLE # TODO: CREATE A BITARRAY SO THAT THE MODLOG EVENTS ARE TOGGLEABLE
# TODO: MAKE SURE THAT THE BITARRAY IS ONLY IMPLEMENTED AFTER ALL EVENTS ARE CODED # TODO: MAKE SURE THAT THE BITARRAY IS ONLY IMPLEMENTED AFTER ALL EVENTS ARE CODED
@ -874,29 +874,21 @@ class Moderation(Cog):
new_roles = [roles for roles in after.changed_roles] new_roles = [roles for roles in after.changed_roles]
old_roles = [roles for roles in before.changed_roles] old_roles = [roles for roles in before.changed_roles]
def role_string(roles): # Get total new_roles in the channel
# Check if the amount of roles is above 20 new_role_string = string_list(new_roles, 20, "Role")
if len(roles) > 20: # Get total old_roles in the channel
# Retrieve the length of the remaining roles old_role_string = string_list(old_roles, 20, "Role")
length = len(roles) - 20
# Store the first 20 roles in a string (highest to lowest) embed = Embed(title="Role Overrides Updated",
string = f"{' **|** '.join(role.mention for role in list(reversed(roles))[:20])} and **{length}** more" description=f"**Channel -->** {after.mention}\n"
return string f"**ID -->** {after.id}",
else:
# Display all roles as it is lower than 20
string = f"{' **|** '.join(role.mention for role in list(reversed(roles[1:])))}"
return string
embed = Embed(description=f"**{after.mention} Role Overrides Updated**",
colour=self.bot.admin_colour, colour=self.bot.admin_colour,
timestamp=datetime.datetime.utcnow()) timestamp=datetime.datetime.utcnow())
embed.set_author(name=after.guild, icon_url=after.guild.icon_url) embed.set_author(name=after.guild, icon_url=after.guild.icon_url)
embed.add_field(name="Before", embed.add_field(name="Before",
value=role_string(old_roles) or after.guild.default_role.mention, inline=False) value=old_role_string or after.guild.default_role.mention, inline=False)
embed.add_field(name="After", embed.add_field(name="After",
value=role_string(new_roles) or after.guild.default_role.mention, inline=False) value=new_role_string or after.guild.default_role.mention, inline=False)
embed.set_footer(text="Role Overrides Updated") embed.set_footer(text="Role Overrides Updated")
await modlogs_channel.send(embed=embed) await modlogs_channel.send(embed=embed)
@ -910,24 +902,35 @@ class Moderation(Cog):
if modlogs := self.bot.get_modlog_for_guild(after.id): if modlogs := self.bot.get_modlog_for_guild(after.id):
modlogs_channel = self.bot.get_channel(modlogs) modlogs_channel = self.bot.get_channel(modlogs)
# Logging guild updates attributes = ["name", "verification_level", "afk_channel", "mfa_level", "icon_url",
if before.name != after.name or before.verification_level != after.verification_level \ "default_notifications", "region", "explicit_content_filter"]
or before.afk_channel != after.afk_channel or before.mfa_level != after.mfa_level \
or before.icon_url != after.icon_url or before.default_notifications != after.default_notifications \ if any(getattr(before, x) != getattr(after, x) for x in attributes):
or before.region != after.region:
# TODO: ADD LOGGING FOR THE ABOVE IF STATEMENTS. # TODO: ADD LOGGING FOR THE ABOVE IF STATEMENTS.
fields = [("Before", fields = [("Before",
f"**Guild Name -->** {before.name}\n" f"**Guild Name -->** {before}\n"
f"**Region -->** {get_region(str(before.region))}\n" f"**Region -->** {get_region(str(before.region))}\n\n"
f"**Verification Level -->** {before.verification_level.name.capitalize()}\n"
f"**AFK Channel -->** #{before.afk_channel or 'N/A'} **|** {before.afk_timeout}s\n", False), f"**2-Factor Authentication -->** {self.bot.tick if before.mfa_level == 1 else self.bot.cross}\n"
f"**Explicit Content Filter -->** {get_content_filter(before.explicit_content_filter.name)}\n"
f"**Verification Level -->** {before.verification_level.name.capitalize()}\n\n"
f"**Default Notifications -->** {get_notifs(before.default_notifications)}\n"
f"**AFK Channel -->** {before.afk_channel.mention if before.afk_channel else '#N/A'} **|** {before.afk_timeout}s\n",
False),
("After", ("After",
f"**Guild Name -->** {after.name}\n" f"**Guild Name -->** {after}\n"
f"**Region -->** {get_region(str(after.region))}\n" f"**Region -->** {get_region(str(after.region))}\n\n"
f"**Verification Level -->** {after.verification_level.name.capitalize()}\n"
f"**AFK Channel -->** #{after.afk_channel or 'N/A'} **|** {after.afk_timeout}s\n", False)] f"**2-Factor Authentication -->** {self.bot.tick if after.mfa_level == 1 else self.bot.cross}\n"
f"**Explicit Content Filter -->** {get_content_filter(after.explicit_content_filter.name)}\n"
f"**Verification Level -->** {after.verification_level.name.capitalize()}\n\n"
f"**Default Notifications -->** {get_notifs(after.default_notifications)}\n"
f"**AFK Channel -->** {after.afk_channel.mention if after.afk_channel else '#N/A'} **|** {after.afk_timeout}s\n",
False)]
embed = Embed(title="Guild Updated", embed = Embed(title="Guild Updated",
description=f"**Owner --> {after.owner.mention} |** {after.owner}\n" description=f"**Owner --> {after.owner.mention} |** {after.owner}\n"

Loading…
Cancel
Save