Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f1ff14c
Remove aio-pika and psutil
ChrisLovering Mar 17, 2022
bd13ed6
Bump all deps and exact version pin.
ChrisLovering Mar 19, 2022
4dab419
Bump d.py and bot-core
ChrisLovering Mar 17, 2022
43b6fee
Use bot-core scheduling and member util functions
ChrisLovering Mar 19, 2022
4635c31
Don't use discord.NoMoreItems as it's removed
ChrisLovering Mar 19, 2022
2b6deb8
Move to async cog loading
ChrisLovering Mar 31, 2022
1bae068
Use BotBase from bot-core
ChrisLovering Mar 31, 2022
f14bf00
Discord.py breaking changes
ChrisLovering Mar 31, 2022
047705a
Remove async stats and site api wrapper
ChrisLovering Mar 31, 2022
277bb01
Adding missing kwargs required by BotBase in test helper
ChrisLovering Apr 2, 2022
56e38ee
Update test helpers with breaking d.py changes
ChrisLovering Apr 2, 2022
450c9ce
Update tests to use new async cog setup function
ChrisLovering Apr 2, 2022
4db508e
Update tests to use new async cog_load function
ChrisLovering Apr 2, 2022
0afe07d
Remove sync cog init test
ChrisLovering Apr 2, 2022
4a9e281
Don't try to overwrite a read-only attr in help command test
ChrisLovering Apr 2, 2022
ecc08e7
Remove usages of init_task in thread bumper cog
ChrisLovering Apr 16, 2022
bd0c9f7
Wait for mod log to load when syncing defcon settings
ChrisLovering Apr 16, 2022
ff6e42c
Correct capitalisation of async and discord.py
ChrisLovering Apr 18, 2022
21acc03
Move redis session reconnect to bot-core
ChrisLovering Apr 18, 2022
a4cd6bc
Hardcode 8 test threads in CI
ChrisLovering Apr 18, 2022
6846a4b
Add cog_unload functions to cancel scheduled tasks
ChrisLovering Apr 18, 2022
eec5a13
Use discord.py's async cog loading for more cogs
ChrisLovering Apr 18, 2022
d62c17b
Refactor otn cog to use discord.py tasks
ChrisLovering Apr 18, 2022
87edeff
Test that sync cog syncers run when sync cog is loaded
ChrisLovering Apr 18, 2022
267f6d9
Add missing underscores to test function names
ChrisLovering Apr 18, 2022
c92fc31
Remove unused instance var from OTN cog
ChrisLovering Apr 18, 2022
9b21f52
Remove old task cancellations from modpings cog_unload
ChrisLovering Apr 18, 2022
cbca93e
Move api_client to a kwarg on creation of the Bot
ChrisLovering Apr 19, 2022
c89e407
Don't schedule a now non-existant task
ChrisLovering Apr 19, 2022
0cff5ca
Don't pass unused param to infraction scheduler cog_load
ChrisLovering Apr 19, 2022
72274ce
channel.history is now an async iterator, so has no .next() method
ChrisLovering Apr 19, 2022
88088e6
Empty embed descriptions are now None, rather than a sentinal
ChrisLovering Apr 19, 2022
56695df
Ensure error has an attr before checking the value in metabase
ChrisLovering Apr 19, 2022
f284cff
Bump bot-core for new discord.py version
ChrisLovering Apr 19, 2022
a90c844
Utilise new on_thread_create event for modlog
ChrisLovering Apr 19, 2022
4c1a076
Pass the now required intents kwarg when creating MockBot
ChrisLovering Apr 19, 2022
0a799bb
Don't hardcode ! as the bot prefix where possible
ChrisLovering Apr 20, 2022
9614432
Remove unneeded contextlib.suppress
ChrisLovering Apr 20, 2022
03a8c81
remove unneeded import in tests
ChrisLovering Apr 20, 2022
2e97bfa
Use fully qualified datetime.time()
ChrisLovering Apr 20, 2022
06aabf7
Don't use internal discord.py methods for available help channels mes…
ChrisLovering Apr 20, 2022
b28ad5e
Automatically determine number threads to use with pytest
ChrisLovering Apr 20, 2022
b9a6c9e
Refactor a try/except that will never raise
ChrisLovering Apr 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import asyncio
import os
from functools import partial, partialmethod
from typing import TYPE_CHECKING

from discord.ext import commands
from botcore.utils import apply_monkey_patches

from bot import log, monkey_patches
from bot import log

if TYPE_CHECKING:
from bot.bot import Bot
Expand All @@ -16,16 +15,6 @@
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

monkey_patches.patch_typing()

# This patches any convertors that use PartialMessage, but not the PartialMessageConverter itself
# as library objects are made by this mapping.
# https://github.com/Rapptz/discord.py/blob/1a4e73d59932cdbe7bf2c281f25e32529fc7ae1f/discord/ext/commands/converter.py#L984-L1004
commands.converter.PartialMessageConverter = monkey_patches.FixedPartialMessageConverter

# Monkey-patch discord.py decorators to use the Command subclass which supports root aliases.
# Must be patched before any cogs are added.
commands.command = partial(commands.command, cls=monkey_patches.Command)
commands.GroupMixin.command = partialmethod(commands.GroupMixin.command, cls=monkey_patches.Command)
apply_monkey_patches()

instance: "Bot" = None # Global Bot instance.
72 changes: 68 additions & 4 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,80 @@
import asyncio

import aiohttp
import discord
from async_rediscache import RedisSession
from botcore import StartupError
from botcore.site_api import APIClient
from discord.ext import commands

import bot
from bot import constants
from bot.bot import Bot, StartupError
from bot.bot import Bot
from bot.log import get_logger, setup_sentry

setup_sentry()
LOCALHOST = "127.0.0.1"


async def _create_redis_session() -> RedisSession:
"""Create and connect to a redis session."""
redis_session = RedisSession(
address=(constants.Redis.host, constants.Redis.port),
password=constants.Redis.password,
minsize=1,
maxsize=20,
use_fakeredis=constants.Redis.use_fakeredis,
global_namespace="bot",
)
try:
await redis_session.connect()
except OSError as e:
raise StartupError(e)
return redis_session


async def main() -> None:
"""Entry async method for starting the bot."""
statsd_url = constants.Stats.statsd_host
if constants.DEBUG_MODE:
# Since statsd is UDP, there are no errors for sending to a down port.
# For this reason, setting the statsd host to 127.0.0.1 for development
# will effectively disable stats.
statsd_url = LOCALHOST

allowed_roles = list({discord.Object(id_) for id_ in constants.MODERATION_ROLES})
intents = discord.Intents.all()
intents.presences = False
intents.dm_typing = False
intents.dm_reactions = False
intents.invites = False
intents.webhooks = False
intents.integrations = False

async with aiohttp.ClientSession() as session:
bot.instance = Bot(
guild_id=constants.Guild.id,
http_session=session,
redis_session=await _create_redis_session(),
statsd_url=statsd_url,
command_prefix=commands.when_mentioned_or(constants.Bot.prefix),
activity=discord.Game(name=f"Commands: {constants.Bot.prefix}help"),
case_insensitive=True,
max_messages=10_000,
allowed_mentions=discord.AllowedMentions(everyone=False, roles=allowed_roles),
intents=intents,
allowed_roles=list({discord.Object(id_) for id_ in constants.MODERATION_ROLES}),
api_client=APIClient(
site_api_url=f"{constants.URLs.site_api_schema}{constants.URLs.site_api}",
site_api_token=constants.Keys.site_api,
),
)
async with bot.instance as _bot:
await _bot.start(constants.Bot.token)


try:
bot.instance = Bot.create()
bot.instance.load_extensions()
bot.instance.run(constants.Bot.token)
asyncio.run(main())
except StartupError as e:
message = "Unknown Startup Error Occurred."
if isinstance(e.exception, (aiohttp.ClientConnectorError, aiohttp.ServerDisconnectedError)):
Expand Down
102 changes: 0 additions & 102 deletions bot/api.py

This file was deleted.

41 changes: 0 additions & 41 deletions bot/async_stats.py

This file was deleted.

Loading