mirror of https://github.com/stijndcl/didier
				
				
				
			Switch to flake8
							parent
							
								
									61128dda92
								
							
						
					
					
						commit
						dd66087193
					
				| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
[flake8]
 | 
			
		||||
exclude =
 | 
			
		||||
    .git,
 | 
			
		||||
    .github,
 | 
			
		||||
    .mypy_cache,
 | 
			
		||||
    .pytest_cache,
 | 
			
		||||
    __pycache__,
 | 
			
		||||
    alembic,
 | 
			
		||||
    htmlcov,
 | 
			
		||||
    tests,
 | 
			
		||||
    venv
 | 
			
		||||
ignore=E203
 | 
			
		||||
max-line-length = 120
 | 
			
		||||
per-file-ignores =
 | 
			
		||||
    # Missing __all__, main isn't supposed to be imported
 | 
			
		||||
    main.py: DALL000,
 | 
			
		||||
    # Missing __all__, Cogs aren't modules
 | 
			
		||||
    ./didier/cogs/*: DALL000
 | 
			
		||||
| 
						 | 
				
			
			@ -78,7 +78,7 @@ jobs:
 | 
			
		|||
      - name: Install dependencies
 | 
			
		||||
        run: pip3 install -r requirements.txt -r requirements-dev.txt
 | 
			
		||||
      - name: Linting
 | 
			
		||||
        run: pylint didier database
 | 
			
		||||
        run: flake8
 | 
			
		||||
  typing:
 | 
			
		||||
    needs: [dependencies]
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,8 +6,23 @@ from sqlalchemy.ext.asyncio import AsyncSession
 | 
			
		|||
from database.crud import users
 | 
			
		||||
from database.exceptions import currency as exceptions
 | 
			
		||||
from database.models import Bank, NightlyData
 | 
			
		||||
from database.utils.math.currency import rob_upgrade_price, interest_upgrade_price, capacity_upgrade_price
 | 
			
		||||
from database.utils.math.currency import (
 | 
			
		||||
    capacity_upgrade_price,
 | 
			
		||||
    interest_upgrade_price,
 | 
			
		||||
    rob_upgrade_price,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    "add_dinks",
 | 
			
		||||
    "claim_nightly",
 | 
			
		||||
    "get_bank",
 | 
			
		||||
    "get_nightly_data",
 | 
			
		||||
    "invest",
 | 
			
		||||
    "upgrade_capacity",
 | 
			
		||||
    "upgrade_interest",
 | 
			
		||||
    "upgrade_rob",
 | 
			
		||||
    "NIGHTLY_AMOUNT",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
NIGHTLY_AMOUNT = 420
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,16 @@ from database.exceptions.constraints import DuplicateInsertException
 | 
			
		|||
from database.exceptions.not_found import NoResultFoundException
 | 
			
		||||
from database.models import CustomCommand, CustomCommandAlias
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    "clean_name",
 | 
			
		||||
    "create_alias",
 | 
			
		||||
    "create_command",
 | 
			
		||||
    "edit_command",
 | 
			
		||||
    "get_command",
 | 
			
		||||
    "get_command_by_alias",
 | 
			
		||||
    "get_command_by_name",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def clean_name(name: str) -> str:
 | 
			
		||||
    """Convert a name to lowercase & remove spaces to allow easier matching"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
import datetime
 | 
			
		||||
 | 
			
		||||
from sqlalchemy import select, delete
 | 
			
		||||
from sqlalchemy import delete, select
 | 
			
		||||
from sqlalchemy.ext.asyncio import AsyncSession
 | 
			
		||||
 | 
			
		||||
from database.models import UforaCourse, UforaAnnouncement
 | 
			
		||||
from database.models import UforaAnnouncement, UforaCourse
 | 
			
		||||
 | 
			
		||||
__all__ = ["create_new_announcement", "get_courses_with_announcements", "remove_old_announcements"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_courses_with_announcements(session: AsyncSession) -> list[UforaCourse]:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,11 @@ from typing import Optional
 | 
			
		|||
from sqlalchemy import select
 | 
			
		||||
from sqlalchemy.ext.asyncio import AsyncSession
 | 
			
		||||
 | 
			
		||||
from database.models import User, Bank, NightlyData
 | 
			
		||||
from database.models import Bank, NightlyData, User
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    "get_or_add",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_or_add(session: AsyncSession, user_id: int) -> User:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
from urllib.parse import quote_plus
 | 
			
		||||
 | 
			
		||||
from sqlalchemy.engine import URL
 | 
			
		||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
 | 
			
		||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
 | 
			
		||||
from sqlalchemy.orm import sessionmaker
 | 
			
		||||
 | 
			
		||||
import settings
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,2 +1,5 @@
 | 
			
		|||
__all__ = ["DuplicateInsertException"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DuplicateInsertException(Exception):
 | 
			
		||||
    """Exception raised when a value already exists"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
__all__ = ["DoubleNightly", "NotEnoughDinks"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DoubleNightly(Exception):
 | 
			
		||||
    """Exception raised when claiming nightlies multiple times per day"""
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,2 +1,5 @@
 | 
			
		|||
__all__ = ["NoResultFoundException"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class NoResultFoundException(Exception):
 | 
			
		||||
    """Exception raised when nothing was found"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,9 +2,10 @@ import logging
 | 
			
		|||
 | 
			
		||||
from alembic import config, script
 | 
			
		||||
from alembic.runtime import migration
 | 
			
		||||
 | 
			
		||||
from database.engine import engine
 | 
			
		||||
 | 
			
		||||
__all__ = ["ensure_latest_migration"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def ensure_latest_migration():
 | 
			
		||||
    """Make sure we are currently on the latest revision, otherwise raise an exception"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,12 +3,25 @@ from __future__ import annotations
 | 
			
		|||
from datetime import datetime
 | 
			
		||||
from typing import Optional
 | 
			
		||||
 | 
			
		||||
from sqlalchemy import BigInteger, Column, Integer, Text, ForeignKey, Boolean, DateTime
 | 
			
		||||
from sqlalchemy import BigInteger, Boolean, Column, DateTime, ForeignKey, Integer, Text
 | 
			
		||||
from sqlalchemy.orm import declarative_base, relationship
 | 
			
		||||
 | 
			
		||||
Base = declarative_base()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    "Base",
 | 
			
		||||
    "Bank",
 | 
			
		||||
    "CustomCommand",
 | 
			
		||||
    "CustomCommandAlias",
 | 
			
		||||
    "NightlyData",
 | 
			
		||||
    "UforaAnnouncement",
 | 
			
		||||
    "UforaCourse",
 | 
			
		||||
    "UforaCourseAlias",
 | 
			
		||||
    "User",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Bank(Base):
 | 
			
		||||
    """A user's currency information"""
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
import math
 | 
			
		||||
 | 
			
		||||
__all__ = ["capacity_upgrade_price", "interest_upgrade_price", "rob_upgrade_price"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def interest_upgrade_price(level: int) -> int:
 | 
			
		||||
    """Calculate the price to upgrade your interest level"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,3 @@
 | 
			
		|||
from .didier import Didier
 | 
			
		||||
 | 
			
		||||
__all__ = ["Didier"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,11 @@ from discord.ext import commands
 | 
			
		|||
 | 
			
		||||
from database.crud import currency as crud
 | 
			
		||||
from database.exceptions.currency import DoubleNightly, NotEnoughDinks
 | 
			
		||||
from database.utils.math.currency import capacity_upgrade_price, interest_upgrade_price, rob_upgrade_price
 | 
			
		||||
from database.utils.math.currency import (
 | 
			
		||||
    capacity_upgrade_price,
 | 
			
		||||
    interest_upgrade_price,
 | 
			
		||||
    rob_upgrade_price,
 | 
			
		||||
)
 | 
			
		||||
from didier import Didier
 | 
			
		||||
from didier.utils.discord.checks import is_owner
 | 
			
		||||
from didier.utils.discord.converters import abbreviated_number
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
from typing import Mapping, Optional, List
 | 
			
		||||
from typing import List, Mapping, Optional
 | 
			
		||||
 | 
			
		||||
import discord
 | 
			
		||||
from discord.ext import commands
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,8 +8,8 @@ from database.crud import custom_commands
 | 
			
		|||
from database.exceptions.constraints import DuplicateInsertException
 | 
			
		||||
from database.exceptions.not_found import NoResultFoundException
 | 
			
		||||
from didier import Didier
 | 
			
		||||
from didier.data.modals.custom_commands import CreateCustomCommand, EditCustomCommand
 | 
			
		||||
from didier.data.flags.owner import EditCustomFlags
 | 
			
		||||
from didier.data.modals.custom_commands import CreateCustomCommand, EditCustomCommand
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Owner(commands.Cog):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,12 @@ from database.models import UforaCourse
 | 
			
		|||
from didier.utils.types.datetime import int_to_weekday
 | 
			
		||||
from didier.utils.types.string import leading
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    "fetch_ufora_announcements",
 | 
			
		||||
    "parse_ids",
 | 
			
		||||
    "UforaNotification",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@dataclass
 | 
			
		||||
class UforaNotification:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,3 @@
 | 
			
		|||
from .posix import PosixFlags
 | 
			
		||||
 | 
			
		||||
__all__ = ["PosixFlags"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@ from typing import Optional
 | 
			
		|||
 | 
			
		||||
from didier.data.flags import PosixFlags
 | 
			
		||||
 | 
			
		||||
__all__ = ["EditCustomFlags"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class EditCustomFlags(PosixFlags):
 | 
			
		||||
    """Flags for the edit custom command"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
from discord.ext import commands
 | 
			
		||||
 | 
			
		||||
__all__ = ["PosixFlags"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PosixFlags(commands.FlagConverter, delimiter=" ", prefix="--"):  # type: ignore
 | 
			
		||||
    """Base class to add POSIX-like flags to commands
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,8 @@ import discord
 | 
			
		|||
from database.crud.custom_commands import create_command, edit_command
 | 
			
		||||
from didier import Didier
 | 
			
		||||
 | 
			
		||||
__all__ = ["CreateCustomCommand", "EditCustomCommand"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CreateCustomCommand(discord.ui.Modal, title="Create Custom Command"):
 | 
			
		||||
    """Modal to create new custom commands"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,8 @@ from database.crud import custom_commands
 | 
			
		|||
from database.engine import DBSession
 | 
			
		||||
from didier.utils.discord.prefix import get_prefix
 | 
			
		||||
 | 
			
		||||
__all__ = ["Didier"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Didier(commands.Bot):
 | 
			
		||||
    """DIDIER <3"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,3 @@
 | 
			
		|||
from .message_commands import is_owner
 | 
			
		||||
 | 
			
		||||
__all__ = ["is_owner"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
from discord.ext import commands
 | 
			
		||||
 | 
			
		||||
__all__ = ["is_owner"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def is_owner(ctx: commands.Context) -> bool:
 | 
			
		||||
    """Check that a command is being invoked by the owner of the bot"""
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1,3 @@
 | 
			
		|||
from .numbers import *
 | 
			
		||||
from .numbers import abbreviated_number
 | 
			
		||||
 | 
			
		||||
__all__ = ["abbreviated_number"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,11 +31,11 @@ def abbreviated_number(argument: str) -> Union[str, int]:
 | 
			
		|||
        value = units.get(unit)
 | 
			
		||||
        argument = argument[:-1]
 | 
			
		||||
 | 
			
		||||
    # [int][unit]
 | 
			
		||||
    # [int][unit]  # noqa: E800
 | 
			
		||||
    if "." not in argument and value is not None:
 | 
			
		||||
        return int(argument) * (10**value)
 | 
			
		||||
 | 
			
		||||
    # [float][unit]
 | 
			
		||||
    # [float][unit]  # noqa: E800
 | 
			
		||||
    if "." in argument:
 | 
			
		||||
        # Floats themselves are not supported
 | 
			
		||||
        if value is None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@ from discord.ext import commands
 | 
			
		|||
 | 
			
		||||
from didier.data import constants
 | 
			
		||||
 | 
			
		||||
__all__ = ["get_prefix"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_prefix(client: commands.Bot, message: Message) -> str:
 | 
			
		||||
    """Match a prefix against a message
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
__all__ = ["int_to_weekday"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def int_to_weekday(number: int) -> str:  # pragma: no cover # it's useless to write a test for this
 | 
			
		||||
    """Get the Dutch name of a weekday from the number"""
 | 
			
		||||
    return ["Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"][number]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,8 @@
 | 
			
		|||
import math
 | 
			
		||||
from typing import Optional
 | 
			
		||||
 | 
			
		||||
__all__ = ["leading", "pluralize"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def leading(character: str, string: str, target_length: Optional[int] = 2) -> str:
 | 
			
		||||
    """Add a leading [character] to [string] to make it length [target_length]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								main.py
								
								
								
								
							
							
						
						
									
										3
									
								
								main.py
								
								
								
								
							| 
						 | 
				
			
			@ -1,9 +1,8 @@
 | 
			
		|||
import asyncio
 | 
			
		||||
import logging
 | 
			
		||||
import sys
 | 
			
		||||
from logging.handlers import RotatingFileHandler
 | 
			
		||||
 | 
			
		||||
import asyncio
 | 
			
		||||
 | 
			
		||||
import settings
 | 
			
		||||
from database.migrations import ensure_latest_migration
 | 
			
		||||
from didier import Didier
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,9 @@ omit = [
 | 
			
		|||
    "./didier/data/*"
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[tool.isort]
 | 
			
		||||
profile = "black"
 | 
			
		||||
 | 
			
		||||
[tool.mypy]
 | 
			
		||||
plugins = [
 | 
			
		||||
    "sqlalchemy.ext.mypy.plugin"
 | 
			
		||||
| 
						 | 
				
			
			@ -25,19 +28,6 @@ plugins = [
 | 
			
		|||
module = ["discord.*", "feedparser.*", "markdownify.*"]
 | 
			
		||||
ignore_missing_imports = true
 | 
			
		||||
 | 
			
		||||
[tool.pylint.master]
 | 
			
		||||
disable = [
 | 
			
		||||
    "missing-module-docstring",
 | 
			
		||||
    "too-few-public-methods",
 | 
			
		||||
    "too-many-arguments",
 | 
			
		||||
    "too-many-instance-attributes",
 | 
			
		||||
    "too-many-locals"
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[tool.pylint.format]
 | 
			
		||||
max-line-length = 120
 | 
			
		||||
good-names = ["i", "dt"]
 | 
			
		||||
 | 
			
		||||
[tool.pytest.ini_options]
 | 
			
		||||
asyncio_mode = "auto"
 | 
			
		||||
env = [
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,18 @@
 | 
			
		|||
black==22.3.0
 | 
			
		||||
coverage[toml]==6.4.1
 | 
			
		||||
mypy==0.961
 | 
			
		||||
pylint==2.14.1
 | 
			
		||||
pytest==7.1.2
 | 
			
		||||
pytest-asyncio==0.18.3
 | 
			
		||||
pytest-env==0.6.2
 | 
			
		||||
sqlalchemy2-stubs==0.0.2a23
 | 
			
		||||
types-pytz==2021.3.8
 | 
			
		||||
types-pytz==2021.3.8
 | 
			
		||||
 | 
			
		||||
# Flake8 + plugins
 | 
			
		||||
flake8==4.0.1
 | 
			
		||||
flake8-bandit==3.0.0
 | 
			
		||||
flake8-black==0.3.3
 | 
			
		||||
flake8-bugbear==22.7.1
 | 
			
		||||
flake8-dunder-all==0.2.1
 | 
			
		||||
flake8-eradicate==1.2.1
 | 
			
		||||
flake8-isort==4.1.1
 | 
			
		||||
flake8-simplify==0.19.2
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue