diff --git a/minato_namikaze/bot_files/lib/classes/converter.py b/minato_namikaze/bot_files/lib/classes/converter.py index a3f68b5d..41d66785 100644 --- a/minato_namikaze/bot_files/lib/classes/converter.py +++ b/minato_namikaze/bot_files/lib/classes/converter.py @@ -8,6 +8,7 @@ time_dict = {"h": 3600, "s": 1, "m": 60, "d": 86400} + class TimeConverter(commands.Converter): async def convert(self, ctx, argument): args = argument.lower() @@ -24,15 +25,19 @@ async def convert(self, ctx, argument): raise commands.BadArgument(f"{key} is not a number!") return round(time) + class Arguments(argparse.ArgumentParser): def error(self, message): raise RuntimeError(message) def can_execute_action(ctx, user, target): - return user.id == ctx.bot.owner_id or \ - user == ctx.guild.owner or \ - user.top_role > target.top_role + return ( + user.id == ctx.bot.owner_id + or user == ctx.guild.owner + or user.top_role > target.top_role + ) + class MemberID(commands.Converter): async def convert(self, ctx, argument): @@ -42,17 +47,26 @@ async def convert(self, ctx, argument): try: member_id = int(argument, base=10) except ValueError: - raise commands.BadArgument(f"{argument} is not a valid member or member ID.") from None + raise commands.BadArgument( + f"{argument} is not a valid member or member ID." + ) from None else: m = await ctx.bot.get_or_fetch_member(ctx.guild, member_id) if m is None: # hackban case - return type('_Hackban', (), {'id': member_id, '__str__': lambda s: f'Member ID {s.id}'})() + return type( + "_Hackban", + (), + {"id": member_id, "__str__": lambda s: f"Member ID {s.id}"}, + )() if not can_execute_action(ctx, ctx.author, m): - raise commands.BadArgument('You cannot do this action on this user due to role hierarchy.') + raise commands.BadArgument( + "You cannot do this action on this user due to role hierarchy." + ) return m + class BannedMember(commands.Converter): async def convert(self, ctx, argument): if argument.isdigit(): @@ -60,26 +74,34 @@ async def convert(self, ctx, argument): try: return await ctx.guild.fetch_ban(discord.Object(id=member_id)) except discord.NotFound: - raise commands.BadArgument('This member has not been banned before.') from None + raise commands.BadArgument( + "This member has not been banned before." + ) from None ban_list = await ctx.guild.bans() - entity = discord.utils.find(lambda u: str(u.user) == argument, ban_list) + entity = discord.utils.find( + lambda u: str(u.user) == argument, ban_list) if entity is None: - raise commands.BadArgument('This member has not been banned before.') + raise commands.BadArgument( + "This member has not been banned before.") return entity + class ActionReason(commands.Converter): async def convert(self, ctx, argument): - ret = f'{ctx.author} (ID: {ctx.author.id}): {argument}' + ret = f"{ctx.author} (ID: {ctx.author.id}): {argument}" if len(ret) > 512: reason_max = 512 - len(ret) + len(argument) - raise commands.BadArgument(f'Reason is too long ({len(argument)}/{reason_max})') + raise commands.BadArgument( + f"Reason is too long ({len(argument)}/{reason_max})" + ) return ret + def safe_reason_append(base, to_append): - appended = base + f'({to_append})' + appended = base + f"({to_append})" if len(appended) > 512: return base return appended diff --git a/minato_namikaze/bot_files/lib/mendeleev/electronegativity.py b/minato_namikaze/bot_files/lib/mendeleev/electronegativity.py index 2c3ddcee..19fbb3fe 100644 --- a/minato_namikaze/bot_files/lib/mendeleev/electronegativity.py +++ b/minato_namikaze/bot_files/lib/mendeleev/electronegativity.py @@ -1,6 +1,5 @@ # Code written here is not mine. # Its taken from https://github.com/lmmentel/mendeleev - """ Electronegativity scale formulas """ @@ -82,7 +81,7 @@ def martynov_batsanov(ionization_energies: List[float]) -> float: - :math:`I_{k}` is the :math:`k` th ionization potential. """ - return math.sqrt(abs(sum(ionization_energies)/len(ionization_energies))) + return math.sqrt(abs(sum(ionization_energies) / len(ionization_energies))) def mulliken( @@ -160,4 +159,4 @@ def generic(zeff: float, radius: float, rpow: float = 1, apow: float = 1) -> flo - :math:`\\alpha,\\beta` parameters """ - return math.pow(zeff / math.pow(radius, rpow), apow) \ No newline at end of file + return math.pow(zeff / math.pow(radius, rpow), apow) diff --git a/minato_namikaze/bot_files/lib/mendeleev/mendeleev.py b/minato_namikaze/bot_files/lib/mendeleev/mendeleev.py index ed8fb4a0..41ed5257 100644 --- a/minato_namikaze/bot_files/lib/mendeleev/mendeleev.py +++ b/minato_namikaze/bot_files/lib/mendeleev/mendeleev.py @@ -52,7 +52,8 @@ def element(ids: Union[int, str]) -> Element: return _get_element(ids) else: raise ValueError( - "Expected a , , or , got: {0:s}".format(type(ids)) + "Expected a , , or , got: {0:s}".format( + type(ids)) ) @@ -72,7 +73,8 @@ def _get_element(ids): elif isinstance(ids, int): return session.query(Element).filter(Element.atomic_number == ids).one() else: - raise ValueError("Expecting a or , got: {0:s}".format(type(ids))) + raise ValueError( + "Expecting a or , got: {0:s}".format(type(ids))) def get_all_elements(): @@ -136,4 +138,4 @@ def deltaN(id1, id2, charge1=0, charge2=0, missingIsZero=True): 2.0 * (e1.hardness(charge=charge1) + e2.hardness(charge=charge2)) ) else: - return None \ No newline at end of file + return None diff --git a/minato_namikaze/bot_files/lib/mendeleev/models.py b/minato_namikaze/bot_files/lib/mendeleev/models.py index b74be6c5..e7ac1633 100644 --- a/minato_namikaze/bot_files/lib/mendeleev/models.py +++ b/minato_namikaze/bot_files/lib/mendeleev/models.py @@ -2,7 +2,6 @@ # Its taken from https://github.com/lmmentel/mendeleev # -*- coding: utf-8 -*- - """module specifying the database models""" import math @@ -39,7 +38,6 @@ "ScreeningConstant", ] - Base = declarative_base() @@ -301,9 +299,8 @@ def mass_str(self) -> str: else: return "{aw:.3f}".format(aw=self.atomic_weight) else: - dec = int(abs( - math.floor(math.log10(abs(self.atomic_weight_uncertainty))) - )) + dec = int( + abs(math.floor(math.log10(abs(self.atomic_weight_uncertainty))))) dec = min(dec, 5) if self.is_radioactive: return "[{aw:.{dec}f}]".format(aw=self.atomic_weight, dec=dec) @@ -349,7 +346,8 @@ def hardness(self, charge: int = 0) -> float: return None elif charge < 0: raise ValueError( - "Charge has to be a non-negative integer, got: {}".format(charge) + "Charge has to be a non-negative integer, got: {}".format( + charge) ) @hybrid_method @@ -400,13 +398,16 @@ def zeff( if n is None: n = self.ec.max_n() elif not isinstance(n, int): - raise ValueError(" should be an integer, got: {}".format(type(n))) + raise ValueError( + " should be an integer, got: {}".format(type(n))) if o is None: # take the shell with max `l` for a given `n` - o = ORBITALS[max(get_l(x[1]) for x in self.ec.conf.keys() if x[0] == n)] + o = ORBITALS[max(get_l(x[1]) + for x in self.ec.conf.keys() if x[0] == n)] elif o not in ORBITALS: - raise ValueError(" should be one of {}".format(", ".join(ORBITALS))) + raise ValueError( + " should be one of {}".format(", ".join(ORBITALS))) if method.lower() == "slater": return self.atomic_number - self.ec.slater_screening(n=n, o=o, alle=alle) @@ -417,7 +418,8 @@ def zeff( else: return sc else: - raise ValueError(" should be one of {}".format("slater, clementi")) + raise ValueError( + " should be one of {}".format("slater, clementi")) def electrophilicity(self) -> float: r""" @@ -580,7 +582,8 @@ def electronegativity_mulliken( ea = self.ionenergies.get(charge, None) else: raise ValueError( - "Charge has to be a non-negative integer, got: {}".format(charge) + "Charge has to be a non-negative integer, got: {}".format( + charge) ) return mulliken( ip, ea, missing_is_zero=missing_is_zero, allow_negative_ea=allow_negative_ea @@ -610,7 +613,8 @@ def oxides(self) -> List[str]: oxide_coeffs = [coeffs(ox) for ox in self.oxistates if ox > 0] # convert to strings and replace 1 with empty string - normal_coeffs = [[str(c) if c != 1 else "" for c in t] for t in oxide_coeffs] + normal_coeffs = [[str(c) if c != 1 else "" for c in t] + for t in oxide_coeffs] return [f"{self.symbol}{cme}O{co}" for cme, co in normal_coeffs] def __str__(self): @@ -646,7 +650,8 @@ def fetch_attrs_for_group(attrs: List[str], group: int = 18) -> Tuple[List[Any]] .all() ) - results = tuple([getattr(member, attr) for member in members] for attr in attrs) + results = tuple([getattr(member, attr) + for member in members] for attr in attrs) session.close() return results @@ -879,4 +884,4 @@ def __repr__(self): return "".format( self.atomic_number, self.n, self.s, self.screening - ) \ No newline at end of file + )