New pre-commit compliance
This commit is contained in:
parent
e9500d6ce1
commit
ace64e9ad9
8 changed files with 104 additions and 32 deletions
2
.flake8
2
.flake8
|
@ -1,7 +1,7 @@
|
||||||
[flake8]
|
[flake8]
|
||||||
extend-ignore =
|
extend-ignore =
|
||||||
Q0, E501, C812, E203, W503, # These default to arguing with Black. We might configure some of them eventually
|
Q0, E501, C812, E203, W503, # These default to arguing with Black. We might configure some of them eventually
|
||||||
ANN101, # Ignore self annotation
|
ANN1, # Ignore self and cls annotations
|
||||||
ANN204, ANN206, # return annotations for special methods and class methods
|
ANN204, ANN206, # return annotations for special methods and class methods
|
||||||
D105, D107, # Missing Docstrings in magic method and __init__
|
D105, D107, # Missing Docstrings in magic method and __init__
|
||||||
S311, # Standard pseudo-random generators are not suitable for security/cryptographic purposes.
|
S311, # Standard pseudo-random generators are not suitable for security/cryptographic purposes.
|
||||||
|
|
|
@ -31,8 +31,8 @@ __version__ = "2.0.0a0"
|
||||||
async def on_ready() -> None:
|
async def on_ready() -> None:
|
||||||
"""Lepton on_ready override."""
|
"""Lepton on_ready override."""
|
||||||
global restart_ctx
|
global restart_ctx
|
||||||
print(" Logged in as {0.user}".format(jarvis))
|
print(" Logged in as {0.user}".format(jarvis)) # noqa: T001
|
||||||
print(" Connected to {} guild(s)".format(len(jarvis.guilds)))
|
print(" Connected to {} guild(s)".format(len(jarvis.guilds))) # noqa: T001
|
||||||
|
|
||||||
|
|
||||||
@listen()
|
@listen()
|
||||||
|
@ -60,7 +60,7 @@ def run() -> None:
|
||||||
for extension in utils.get_extensions():
|
for extension in utils.get_extensions():
|
||||||
jarvis.load_extension(extension)
|
jarvis.load_extension(extension)
|
||||||
|
|
||||||
print(
|
print( # noqa: T001
|
||||||
" https://discord.com/api/oauth2/authorize?client_id="
|
" https://discord.com/api/oauth2/authorize?client_id="
|
||||||
"{}&permissions=8&scope=bot%20applications.commands".format(jconfig.client_id)
|
"{}&permissions=8&scope=bot%20applications.commands".format(jconfig.client_id)
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,7 @@ from dis_snek.models.snek.application_commands import (
|
||||||
from dis_snek.models.snek.command import check
|
from dis_snek.models.snek.command import check
|
||||||
|
|
||||||
from jarvis.db.models import Ban, Unban
|
from jarvis.db.models import Ban, Unban
|
||||||
from jarvis.utils import build_embed, find
|
from jarvis.utils import build_embed, find, find_all
|
||||||
from jarvis.utils.cachecog import CacheCog
|
from jarvis.utils.cachecog import CacheCog
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ class BanCog(CacheCog):
|
||||||
bans,
|
bans,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
results = [x for x in filter(lambda x: x.user.username == user, bans)]
|
results = find_all(lambda x: x.user.username == user, bans)
|
||||||
if results:
|
if results:
|
||||||
if len(results) > 1:
|
if len(results) > 1:
|
||||||
active_bans = []
|
active_bans = []
|
||||||
|
|
|
@ -174,7 +174,6 @@ class DbrandCog(Scale):
|
||||||
elif search == "🏳️":
|
elif search == "🏳️":
|
||||||
search = "fr"
|
search = "fr"
|
||||||
else:
|
else:
|
||||||
print(search)
|
|
||||||
await ctx.send("Please use text to search for shipping.")
|
await ctx.send("Please use text to search for shipping.")
|
||||||
return
|
return
|
||||||
if len(search) > 2:
|
if len(search) > 2:
|
||||||
|
|
|
@ -26,8 +26,7 @@ def create_layout() -> list:
|
||||||
custom_id=f"verify_button||{id}",
|
custom_id=f"verify_button||{id}",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
action_row = spread_to_rows(*buttons, max_in_row=3)
|
return spread_to_rows(*buttons, max_in_row=3)
|
||||||
return action_row
|
|
||||||
|
|
||||||
|
|
||||||
class VerifyCog(Scale):
|
class VerifyCog(Scale):
|
||||||
|
|
|
@ -65,8 +65,7 @@ class Config(object):
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_yaml(cls, y: dict) -> "Config":
|
def from_yaml(cls, y: dict) -> "Config":
|
||||||
"""Load the yaml config file."""
|
"""Load the yaml config file."""
|
||||||
instance = cls(**y)
|
return cls(**y)
|
||||||
return instance
|
|
||||||
|
|
||||||
|
|
||||||
def get_config(path: str = "config.yaml") -> Config:
|
def get_config(path: str = "config.yaml") -> Config:
|
||||||
|
|
|
@ -21,8 +21,8 @@ __api = tweepy.API(__auth)
|
||||||
|
|
||||||
async def _tweets() -> None:
|
async def _tweets() -> None:
|
||||||
"""J.A.R.V.I.S. twitter blocking task."""
|
"""J.A.R.V.I.S. twitter blocking task."""
|
||||||
guild_cache = dict()
|
guild_cache = {}
|
||||||
channel_cache = dict()
|
channel_cache = {}
|
||||||
twitters = Twitter.objects(active=True)
|
twitters = Twitter.objects(active=True)
|
||||||
for twitter in twitters:
|
for twitter in twitters:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
"""J.A.R.V.I.S. Utility Functions."""
|
"""J.A.R.V.I.S. Utility Functions."""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from operator import attrgetter
|
|
||||||
from pkgutil import iter_modules
|
from pkgutil import iter_modules
|
||||||
from typing import Any, Callable, Iterable, Optional, TypeVar
|
from typing import Any, Callable, Iterable, List, Optional, TypeVar
|
||||||
|
|
||||||
import git
|
import git
|
||||||
from dis_snek.models.discord.embed import Embed
|
from dis_snek.models.discord.embed import Embed
|
||||||
|
@ -88,25 +87,101 @@ def get_repo_hash() -> str:
|
||||||
return repo.head.object.hexsha
|
return repo.head.object.hexsha
|
||||||
|
|
||||||
|
|
||||||
def find(predicate: Callable[[T], Any], seq: Iterable[T]) -> Optional[T]:
|
def find(predicate: Callable, sequence: Iterable) -> Optional[Any]:
|
||||||
for element in seq:
|
"""
|
||||||
if predicate(element):
|
Find the first element in a sequence that matches the predicate.
|
||||||
return element
|
|
||||||
|
??? Hint "Example Usage:"
|
||||||
|
```python
|
||||||
|
member = find(lambda m: m.name == "UserName", guild.members)
|
||||||
|
```
|
||||||
|
Args:
|
||||||
|
predicate: A callable that returns a boolean value
|
||||||
|
sequence: A sequence to be searched
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A match if found, otherwise None
|
||||||
|
|
||||||
|
"""
|
||||||
|
for el in sequence:
|
||||||
|
if predicate(el):
|
||||||
|
return el
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get(iterable: Iterable[T], **attrs: Any) -> Optional[T]:
|
def find_all(predicate: Callable, sequence: Iterable) -> List[Any]:
|
||||||
if len(attrs) == 1:
|
"""
|
||||||
k, v = attrs.popitem()
|
Find all elements in a sequence that match the predicate.
|
||||||
pred = attrgetter(k.replace("__", "."))
|
|
||||||
for elem in iterable:
|
??? Hint "Example Usage:"
|
||||||
if pred(elem) == v:
|
```python
|
||||||
return elem
|
members = find_all(lambda m: m.name == "UserName", guild.members)
|
||||||
|
```
|
||||||
|
Args:
|
||||||
|
predicate: A callable that returns a boolean value
|
||||||
|
sequence: A sequence to be searched
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A list of matches
|
||||||
|
|
||||||
|
"""
|
||||||
|
matches = []
|
||||||
|
for el in sequence:
|
||||||
|
if predicate(el):
|
||||||
|
matches.append(el)
|
||||||
|
return matches
|
||||||
|
|
||||||
|
|
||||||
|
def get(sequence: Iterable, **kwargs: Any) -> Optional[Any]:
|
||||||
|
"""
|
||||||
|
Find the first element in a sequence that matches all attrs.
|
||||||
|
|
||||||
|
??? Hint "Example Usage:"
|
||||||
|
```python
|
||||||
|
channel = get(guild.channels, nsfw=False, category="General")
|
||||||
|
```
|
||||||
|
|
||||||
|
Args:
|
||||||
|
sequence: A sequence to be searched
|
||||||
|
kwargs: Keyword arguments to search the sequence for
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A match if found, otherwise None
|
||||||
|
"""
|
||||||
|
if not kwargs:
|
||||||
|
return sequence[0]
|
||||||
|
|
||||||
|
for el in sequence:
|
||||||
|
if any(not hasattr(el, attr) for attr in kwargs.keys()):
|
||||||
|
continue
|
||||||
|
if all(getattr(el, attr) == value for attr, value in kwargs.items()):
|
||||||
|
return el
|
||||||
return None
|
return None
|
||||||
|
|
||||||
converted = [(attrgetter(attr.replace("__", ".")), value) for attr, value in attrs.items()]
|
|
||||||
|
|
||||||
for elem in iterable:
|
def get_all(sequence: Iterable, **kwargs: Any) -> List[Any]:
|
||||||
if all(pred(elem) == value for pred, value in converted):
|
"""
|
||||||
return elem
|
Find all elements in a sequence that match all attrs.
|
||||||
return None
|
|
||||||
|
??? Hint "Example Usage:"
|
||||||
|
```python
|
||||||
|
channels = get_all(guild.channels, nsfw=False, category="General")
|
||||||
|
```
|
||||||
|
|
||||||
|
Args:
|
||||||
|
sequence: A sequence to be searched
|
||||||
|
kwargs: Keyword arguments to search the sequence for
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A list of matches
|
||||||
|
"""
|
||||||
|
if not kwargs:
|
||||||
|
return sequence
|
||||||
|
|
||||||
|
matches = []
|
||||||
|
for el in sequence:
|
||||||
|
if any(not hasattr(el, attr) for attr in kwargs.keys()):
|
||||||
|
continue
|
||||||
|
if all(getattr(el, attr) == value for attr, value in kwargs.items()):
|
||||||
|
matches.append(el)
|
||||||
|
return matches
|
||||||
|
|
Loading…
Add table
Reference in a new issue