Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
hypergonial committed Dec 17, 2023
1 parent 086445d commit d6f9cd0
Show file tree
Hide file tree
Showing 43 changed files with 230 additions and 201 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN poetry config virtualenvs.create false
RUN poetry install -n --only main

COPY . ./
CMD ["python3.11", "-O", "main.py"]
CMD ["python3.11", "-O", "-m", "src"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
dockerfile: Dockerfile
args:
postgres_version: ${POSTGRES_VERSION:-14}
command: ["python3.11", "-O", "main.py"]
command: ["python3.11", "-O", "-m", "src"]
depends_on:
- sned-db
restart: always
Expand Down
8 changes: 5 additions & 3 deletions src/main.py → src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import logging
import os
import pathlib
import platform
import re

from models import SnedBot
from src.models import SnedBot

DOTENV_REGEX = re.compile(r"^(?P<identifier>[A-Za-z_]+[A-Za-z0-9_]*)=(?P<value>[^#]+)(#.*)?$")
BASE_DIR = str(pathlib.Path(os.path.abspath(__file__)).parents[1])

if int(platform.python_version_tuple()[1]) < 10:
logging.fatal("Python version must be 3.10 or greater! Exiting...")
exit(1)

try:
with open(".env") as env:
with open(os.path.join(BASE_DIR, ".env")) as env:
for line in env.readlines():
match = DOTENV_REGEX.match(line)
if not match:
Expand All @@ -25,7 +27,7 @@
logging.info(".env file not found, using secrets from the environment instead.")

try:
from config import Config
from .config import Config
except ImportError:
logging.fatal(
"Failed loading configuration. Please make sure 'config.py' exists in the root directory of the project and contains valid data."
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions src/db/migrations/7.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import hikari
import lightbulb
from models import JournalEntry, JournalEntryType

from src.models import JournalEntry, JournalEntryType

if t.TYPE_CHECKING:
from models.db import Database
from src.models.db import Database

NOTE_REGEX = re.compile(
r"<t:(?P<timestamp>\d+):\w>: (?P<emoji>.+) \*\*(?P<verb>.+) (?:by|for) (?P<username>.+):\*\* (?P<content>.*)"
Expand Down Expand Up @@ -72,9 +73,9 @@ async def _migrate_notes(db: Database) -> None:
records = await db.fetch("SELECT * FROM users")

for record in records:
notes: list[str] = record.get("notes")
user_id: int = record.get("user_id")
guild_id: int = record.get("guild_id")
notes: list[str] = record["notes"]
user_id: int = record["user_id"]
guild_id: int = record["guild_id"]
if not notes:
continue
for note in notes:
Expand Down
3 changes: 2 additions & 1 deletion src/etc/settings_static.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hikari
import miru
from models.mod_actions import ModerationFlags

from src.models.mod_actions import ModerationFlags

# Static values for the settings extension

Expand Down
12 changes: 6 additions & 6 deletions src/extensions/annoverse.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import etc.const as const
import hikari
import lightbulb
from models.bot import SnedBot
from models.context import SnedContext
from models.plugin import SnedPlugin
from utils import helpers

from config import Config
import src.etc.const as const
from src.config import Config
from src.models.bot import SnedBot
from src.models.context import SnedContext
from src.models.plugin import SnedPlugin
from src.utils import helpers

annoverse = SnedPlugin("Annoverse")
annoverse.default_enabled_guilds = Config().DEBUG_GUILDS or (372128553031958529,)
Expand Down
17 changes: 9 additions & 8 deletions src/extensions/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import hikari
import kosu
import lightbulb
import utils
from etc import const
from etc.settings_static import default_automod_policies, notices
from models.bot import SnedBot
from models.events import AutoModMessageFlagEvent
from models.plugin import SnedPlugin
from utils import helpers
from utils.ratelimiter import MemberBucket

import src.utils as utils
from src.etc import const
from src.etc.settings_static import default_automod_policies, notices
from src.models.bot import SnedBot
from src.models.events import AutoModMessageFlagEvent
from src.models.plugin import SnedPlugin
from src.utils import helpers
from src.utils.ratelimiter import MemberBucket

INVITE_REGEX = re.compile(r"(?:https?://)?discord(?:app)?\.(?:com/invite|gg)/[a-zA-Z0-9]+/?")
"""Used to detect and handle Discord invites."""
Expand Down
17 changes: 9 additions & 8 deletions src/extensions/command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@

import hikari
import lightbulb
from etc import const
from etc.perms_str import get_perm_str
from models.bot import SnedBot
from models.context import SnedPrefixContext, SnedSlashContext
from models.errors import (

from src.etc import const
from src.etc.perms_str import get_perm_str
from src.models.bot import SnedBot
from src.models.context import SnedPrefixContext, SnedSlashContext
from src.models.errors import (
BotRoleHierarchyError,
InteractionTimeOutError,
MemberExpectedError,
RoleHierarchyError,
UserBlacklistedError,
)
from models.plugin import SnedPlugin
from utils import helpers
from src.models.plugin import SnedPlugin
from src.utils import helpers

if TYPE_CHECKING:
from models import SnedContext
from src.models import SnedContext

logger = logging.getLogger(__name__)

Expand Down
11 changes: 6 additions & 5 deletions src/extensions/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import hikari
import lightbulb
import miru
from etc import const
from miru.ext import nav
from models import AuthorOnlyNavigator, SnedPrefixContext
from models.bot import SnedBot
from models.plugin import SnedPlugin
from models.views import AuthorOnlyView

from src.etc import const
from src.models import AuthorOnlyNavigator, SnedPrefixContext
from src.models.bot import SnedBot
from src.models.plugin import SnedPlugin
from src.models.views import AuthorOnlyView

logger = logging.getLogger(__name__)

Expand Down
10 changes: 5 additions & 5 deletions src/extensions/fallingfrontier.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import hikari
import lightbulb
import miru
from etc import const
from models.bot import SnedBot
from models.context import SnedSlashContext
from models.plugin import SnedPlugin

from config import Config
from src.config import Config
from src.etc import const
from src.models.bot import SnedBot
from src.models.context import SnedSlashContext
from src.models.plugin import SnedPlugin

TESTER_STAGING_ROLE = 971843694896513074
TESTER_STAGING_CHANNEL = 971844463884382259
Expand Down
10 changes: 5 additions & 5 deletions src/extensions/fandom.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import hikari
import lightbulb
import yarl
from etc import const
from models.bot import SnedBot
from models.context import SnedSlashContext
from models.plugin import SnedPlugin

from config import Config
from src.config import Config
from src.etc import const
from src.models.bot import SnedBot
from src.models.context import SnedSlashContext
from src.models.plugin import SnedPlugin

fandom = SnedPlugin("Fandom")

Expand Down
23 changes: 12 additions & 11 deletions src/extensions/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@
import Levenshtein as lev # noqa: N813
import lightbulb
import miru
from etc import const
from miru.ext import nav
from models import SnedBot, SnedSlashContext
from models.checks import bot_has_permissions
from models.context import SnedContext, SnedUserContext
from models.plugin import SnedPlugin
from models.views import AuthorOnlyNavigator, AuthorOnlyView
from PIL import Image, ImageDraw, ImageFont
from utils import GlobalBucket, RateLimiter, helpers
from utils.dictionaryapi import DictionaryClient, DictionaryEntry, DictionaryError, UrbanEntry
from utils.ratelimiter import UserBucket
from utils.rpn import InvalidExpressionError, Solver

from config import Config
from src.etc import const
from src.models import SnedBot, SnedSlashContext
from src.models.checks import bot_has_permissions
from src.models.context import SnedContext, SnedUserContext
from src.models.plugin import SnedPlugin
from src.models.views import AuthorOnlyNavigator, AuthorOnlyView
from src.utils import GlobalBucket, RateLimiter, helpers
from src.utils.dictionaryapi import DictionaryClient, DictionaryEntry, DictionaryError, UrbanEntry
from src.utils.ratelimiter import UserBucket
from src.utils.rpn import InvalidExpressionError, Solver

from ..config import Config

if TYPE_CHECKING:
from fractions import Fraction
Expand Down
9 changes: 5 additions & 4 deletions src/extensions/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import typing as t

import etc.const as const
import hikari
import lightbulb
from models.plugin import SnedPlugin

import src.etc.const as const
from src.models.plugin import SnedPlugin

if t.TYPE_CHECKING:
from models import SnedBot
from models.context import SnedSlashContext
from src.models import SnedBot
from src.models.context import SnedSlashContext


help = SnedPlugin("Help")
Expand Down
15 changes: 8 additions & 7 deletions src/extensions/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import miru
import psutil
import pytz
from etc import const
from models import SnedBot
from models.checks import bot_has_permissions
from models.context import SnedMessageContext, SnedSlashContext
from models.plugin import SnedPlugin
from utils import helpers
from utils.scheduler import ConversionMode

from src.etc import const
from src.models import SnedBot
from src.models.checks import bot_has_permissions
from src.models.context import SnedMessageContext, SnedSlashContext
from src.models.plugin import SnedPlugin
from src.utils import helpers
from src.utils.scheduler import ConversionMode

logger = logging.getLogger(__name__)

Expand Down
25 changes: 13 additions & 12 deletions src/extensions/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
import hikari
import lightbulb
import miru
import models
from etc import const
from models import errors
from models.bot import SnedBot
from models.checks import bot_has_permissions, is_above_target, is_invoker_above_target
from models.context import SnedSlashContext, SnedUserContext
from models.db_user import DatabaseUser
from models.events import MassBanEvent
from models.journal import JournalEntry, JournalEntryType
from models.mod_actions import ModerationFlags
from models.plugin import SnedPlugin
from utils import helpers

import src.models as models
from src.etc import const
from src.models import errors
from src.models.bot import SnedBot
from src.models.checks import bot_has_permissions, is_above_target, is_invoker_above_target
from src.models.context import SnedSlashContext, SnedUserContext
from src.models.db_user import DatabaseUser
from src.models.events import MassBanEvent
from src.models.journal import JournalEntry, JournalEntryType
from src.models.mod_actions import ModerationFlags
from src.models.plugin import SnedPlugin
from src.utils import helpers

logger = logging.getLogger(__name__)

Expand Down
13 changes: 7 additions & 6 deletions src/extensions/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import hikari
import lightbulb
import miru
from etc import const
from models import SnedBot, SnedSlashContext, Timer, events
from models.plugin import SnedPlugin
from models.timer import TimerEvent
from models.views import AuthorOnlyNavigator
from utils import helpers

from src.etc import const
from src.models import SnedBot, SnedSlashContext, Timer, events
from src.models.plugin import SnedPlugin
from src.models.timer import TimerEvent
from src.models.views import AuthorOnlyNavigator
from src.utils import helpers

reminders = SnedPlugin(name="Reminders")

Expand Down
13 changes: 7 additions & 6 deletions src/extensions/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import hikari
import lightbulb
import miru
from etc import const
from models import SnedSlashContext
from models.bot import SnedBot
from models.context import SnedApplicationContext, SnedContext, SnedMessageContext, SnedUserContext
from models.plugin import SnedPlugin
from utils import helpers

from src.etc import const
from src.models import SnedSlashContext
from src.models.bot import SnedBot
from src.models.context import SnedApplicationContext, SnedContext, SnedMessageContext, SnedUserContext
from src.models.plugin import SnedPlugin
from src.utils import helpers

logger = logging.getLogger(__name__)

Expand Down
15 changes: 8 additions & 7 deletions src/extensions/role_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import hikari
import lightbulb
import miru
import models
from etc import const
from models import SnedBot, SnedSlashContext
from models.plugin import SnedPlugin
from models.rolebutton import RoleButton, RoleButtonMode
from utils import helpers
from utils.ratelimiter import MemberBucket, RateLimiter

import src.models as models
from src.etc import const
from src.models import SnedBot, SnedSlashContext
from src.models.plugin import SnedPlugin
from src.models.rolebutton import RoleButton, RoleButtonMode
from src.utils import helpers
from src.utils.ratelimiter import MemberBucket, RateLimiter

logger = logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit d6f9cd0

Please sign in to comment.