Skip to content

Commit

Permalink
Rewrite GitHub functionality to be async
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrxyz committed Nov 5, 2023
1 parent 523b250 commit b069330
Show file tree
Hide file tree
Showing 5 changed files with 601 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
hooks:
- id: codespell
args:
- --ignore-words-list=nd,som
- --ignore-words-list=nd,som,pullrequest
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://github.com/hadolint/hadolint
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
discord
PyGithub==1.59.1
pre-commit==2.20.0
aiohttp==3.8.4
11 changes: 10 additions & 1 deletion src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import random
import traceback

import aiohttp
import discord
import gspread_asyncio
from discord.ext import commands, tasks
Expand Down Expand Up @@ -63,6 +64,9 @@ class MILBot(commands.Bot):
# Roles
egn4912_role: discord.Role

# Internal
session: aiohttp.ClientSession

def __init__(self):
super().__init__(
command_prefix="!",
Expand All @@ -77,6 +81,10 @@ async def on_ready(self):
self.change_status.start()
await self.fetch_vars()

async def close(self):
await self.session.close()
await super().close()

@tasks.loop(hours=1)
async def change_status(self):
activities: list[discord.Activity] = [
Expand Down Expand Up @@ -240,7 +248,8 @@ async def main():
logger = logging.getLogger()
logger.addHandler(RichHandler(rich_tracebacks=True))

async with bot:
async with bot, aiohttp.ClientSession() as session:
bot.session = session
await bot.start(token=DISCORD_TOKEN)


Expand Down
Loading

0 comments on commit b069330

Please sign in to comment.