Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
s0lst1ce committed Mar 1, 2020
1 parent 3841817 commit f750912
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/exts/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,12 @@ async def on_message(self, message):
# poll_allowed_chans = ConfigFile(message.guild.id)["poll_channels"]
with ConfigFile(message.guild.id) as conf:
poll_allowed_chans = conf["poll_channels"]
print(poll_allowed_chans)

if (
message.channel.id in poll_allowed_chans
and message.content.startswith(PREFIX) != True
):

print("a poll channel")
local_logger.info(f"Message {message} is a poll one")
# rebuilding attachements
files = []
Expand Down
24 changes: 21 additions & 3 deletions src/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ async def start_interaction(self, pages: list, msg: discord.Message):
await msg.delete()

async def send_bot_help(self, mapping):
pages = get_bot_pages(lang)
pages = get_bot_pages(self.context.bot.cogs.values(), lang)
msg = await self.get_destination().send(embed=pages[0])

await self.set_reactions(msg, len(pages))
await self.start_interaction(pages, msg)


async def send_cog_help(self, cog):
pages = get_cog_pages(cog, self.get_help_lang())
msg = await self.get_destination().send(embed=pages[0])
Expand Down Expand Up @@ -177,6 +176,25 @@ def get_help(command, lang: str):
# the only commands not in a cog are in main.py -> ext group
return Translator("default", lang, help_type=True)[command.name]

def get_bot_pages(cogs, lang: str):
"""currently doesn't support commands outside of cogs"""
pages = []
for commands in cogs:
pages += get_cog_pages(cog, lang, paginate = False)

description = Translator("help", lang, help_type=True)._dict["description"]
header = discord.Embed(title="Help", description=description, color=7506394)

pages_number = len(pages)
header.set_footer(text=f"Page (1/{pages_number+1})")
for embed, crt in zip(pages, range(pages_number)):
embed.set_footer(text=f"Page ({crt+2}/{pages_number+1})")

pages.insert(0, header)
return pages



def get_cog_pages(cog: discord.ext.commands.Cog, lang: str, paginate: bool = True) -> list:
pages = []
for command in cog.get_commands():
Expand All @@ -185,7 +203,7 @@ def get_cog_pages(cog: discord.ext.commands.Cog, lang: str, paginate: bool = Tru
else:
pages += get_command_pages(command, lang, paginate=False)

description = Translator(cog.__module__.split(".")[1], lang, help_type=True)._dict["cog_description"]
description = Translator("help", lang, help_type=True)._dict[cog.qualified_name.lower()]
header = discord.Embed(title=cog.qualified_name, description=description, color=7506394)

#paginating
Expand Down
2 changes: 1 addition & 1 deletion src/lang/help/help.en
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"developement": "Allows the developers to update the bot and notify all server owners of the changes. It also facilitates bug fixing by providing an easy way to retrieve the log.",
"config": "Allows the owner of a server to configure the behavior of the bot.",
"defaults": "A suite of commands always activated which handle extension management. This cannot be unloaded as it is part of the core of the bot and is required for live updates."
}
}
3 changes: 3 additions & 0 deletions src/lang/help/strings.en
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"help_page_title": "Help"
}
2 changes: 1 addition & 1 deletion src/lang/role/help.en
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"role": ["role management utility. Requires a Gestion role", {
"add": ["Give roles to a member", "<member> [roles...]` gives *roles* to *member*"],
"rm": ["Remove roles from a member", "<member> [roles...]` removes *roles* from *member*"]
}]
}],
}
2 changes: 1 addition & 1 deletion src/lang/slapping/help.en
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"slap": ["Meant to give a warning to misbehavioring members. Cumulated slaps will result in warnings, role removal and eventually kick. Beware the slaps are logged throughout history.", "<member> [reason...]` slaps `member` with `reason`"],
"forgive": ["Pardonning a member to reduce his slap count", "<member> [nbr]` removes `nbr` slaps from `member`"],
"forgive": ["Pardonning a member to reduce his slap count Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa..", "<member> [nbr]` removes `nbr` slaps from `member`"],
"slaps": ["Returns an embed representing the number of slaps of each member. More detailed info can be obtained if member arguments are provided.", "[members...]` returns a list denoting the number of times each slapped member has been slapped. If `members` is precised then detailed information about the slaps of these members will be displayed."],
"spam": ["Can be used by anyone when they believe someone is spamming. One user can only report another once for the same spamming. Rules can be set for automatic moderation. A set amount of reports must be done for the counter-spamming rules to take effect.", "<member>` raises spam counter for `member` by one."],
"abuse": ["Can be used by anyone. This allows users to report unruly behavior from another member. This will send a report card to a set moderation channel for the moderators to review. A explanation for the report must be provided.", "<member> [reason...]` reports `member` because of `reason`"]
Expand Down
14 changes: 7 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def add(ctx, *extensions: str):
await ctx.send("UnexpectedError:\tReport issue to an admin")
raise e

await ctx.send("Successfully added and loadded {}".format(extension))
await ctx.send(f"Successfully added and loadded {extension}")


@ext.command()
Expand All @@ -111,7 +111,7 @@ async def rm(ctx, extension: str):

except Exception as e:
main_logger.exception(e)
await ctx.send("UnexpectedError:\tReport issue to an admin\n{}".format(e))
await ctx.send(f"UnexpectedError:\tReport issue to an admin\n{e}")
raise e

# if the extension was correctly unloaded, removing it from the enblaed extension file
Expand All @@ -126,10 +126,10 @@ async def rm(ctx, extension: str):

except Exception as e:
main_logger.exception(e)
await ctx.send("UnexpectedError:\tReport issue to an admin\n{}".format(e))
await ctx.send(f"UnexpectedError:\tReport issue to an admin\n{e}")
raise e

await ctx.send("Successfully removed and unloaded {}".format(extension))
await ctx.send(f"Successfully removed and unloaded {extension}")
LOCAL_LOGGER.info(f"Disabled and removed {extension}")


Expand All @@ -155,14 +155,14 @@ async def ls(ctx):
# building strings
disabled_str = ""
for e in disabled:
disabled_str += f"""{EMOJIS["X"]} {e}\n"""
disabled_str += EMOJIS["X"] + e + "\n"

enabled_str = ""
for e in enabled:
if EXT_FOLDER + "." + e in running:
enabled_str += f"""{EMOJIS["check"]} {e}\n"""
enabled_str += EMOJIS["check"] + e + "\n"
else:
enabled_str += f"""{EMOJIS["x"]} {e}\n"""
enabled_str += EMOJIS["x"] + e + "\n"

# building embed
ext_embed = discord.Embed(
Expand Down
10 changes: 5 additions & 5 deletions src/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def check_condition(ctx):


def is_init():
"""checks whether the server has been initialized. Meant as a fale-safe for commands requiring configuration."""
"""checks whether the server has been initialized. Meant as a fail-safe for commands requiring configuration."""

def check_condition(ctx):
conf_files = os.listdir(CONFIG_FOLDER)
Expand All @@ -67,7 +67,7 @@ def predicate(ctx):
for role in ctx.author.roles:
if role.id in allowed_roles:
return True
#await ctx.send(embed=get_embed_err(ERR_UNSUFFICIENT_PRIVILEGE)) -> not async
# await ctx.send(embed=get_embed_err(ERR_UNSUFFICIENT_PRIVILEGE)) -> not async
local_logger.warning(ERR_UNSUFFICIENT_PRIVILEGE[1])
return False

Expand Down Expand Up @@ -221,14 +221,14 @@ def make_file(self):
if self.file not in files:
if not self.force:
return False
with open(os.path.join(self.folder, self.file), "w") as file:
with open(os.path.join(self.folder, self.file), "w", encoding="utf-8") as file:
json.dump({0: 0}, file) # creating empty file
return True

def save(self):
"""makes the file from the dict"""
try:
with open(self.path, "w") as file:
with open(self.path, "w", encoding="utf-8") as file:
json.dump(self.data, file)

except Exception as e:
Expand Down Expand Up @@ -286,7 +286,7 @@ def guess_lang(cls, ctx, ext, **kwargs):

def load_strings(self):
try:
with open(self.file, "r") as translation:
with open(self.file, "r", encoding="utf-8") as translation:
return json.load(translation)
except json.decoder.JSONDecodeError as e:
local_logger.error(f"Couldn't read translation for file {self.file}")
Expand Down

0 comments on commit f750912

Please sign in to comment.