Skip to content

Commit

Permalink
chore: update type hints and fix syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexraskin committed Feb 19, 2024
1 parent 0de6e0d commit 38b3311
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import lru_cache

import motor.motor_asyncio
import psutil
import psutil # type: ignore
import sentry_sdk
from aiohttp import ClientSession, ClientTimeout
from cogs import EXTENSIONS
Expand Down Expand Up @@ -37,7 +37,7 @@ class LhBot(AutoShardedBot):

def __init__(self, *args, **options) -> None:
super().__init__(*args, **options)
self.session = None
self.session: ClientSession = None
self.db_client = None
self.start_time = None
self.version = config.bot_version
Expand Down
10 changes: 6 additions & 4 deletions bot/cogs/fun.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import random
from typing import Union
from typing import Union, TYPE_CHECKING

from discord import Colour, Embed, app_commands
from discord.ext import commands, tasks
from utils import bot_utils

if TYPE_CHECKING:
from ..bot import LhBot

class Fun(commands.Cog, name="Fun"):
def __init__(self, client: commands.Bot):
self.client = client
def __init__(self, client: LhBot):
self.client: LhBot = client
self.load_chuck_http_codes.start()
self.headers = {"Accept": "application/json"}

Expand Down Expand Up @@ -74,7 +76,7 @@ async def cat(self, ctx: commands.Context):
await ctx.send("Could not find a cat!")
return
else:
await ctx.send(f"{cat_url}/cat/{data['id']}")
await ctx.send(f"{cat_url}/cat/{data['_id']}")

@commands.hybrid_command(
name="dog", aliases=["dogpic", "doggo"], with_app_command=True
Expand Down
35 changes: 19 additions & 16 deletions bot/cogs/general.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import random
import os

from typing import TYPE_CHECKING, Union, Tuple

import discord
from discord.ext import commands, tasks
from discord.utils import oauth_url
from sentry_sdk import capture_exception

from utils import gpt

if TYPE_CHECKING:
from ..bot import LhBot

class General(commands.Cog, name="General"):
def __init__(self, client: commands.Bot):
self.client = client
def __init__(self, client: LhBot):
self.client: LhBot = client
self.streamer_name = "lhcloudy27"
self.cloudflare_url = os.environ.get("CLOUDFLARE_URL")
self.cloudflare_token = os.environ.get('CLOUDFLARE_TOKEN')
Expand All @@ -22,7 +27,7 @@ def __init__(self, client: commands.Bot):
}
self.status_task.start()

async def check_if_live(self) -> set:
async def check_if_live(self) -> Union[Tuple[bool, str, str, str], Tuple[bool, None, None, None]]:
async with self.client.session.post(
"https://id.twitch.tv/oauth2/token", data=self.body
) as response:
Expand Down Expand Up @@ -117,21 +122,21 @@ async def on_command_error(self, ctx, error) -> None:
self.client.logger.error(error)
capture_exception(error)
return


@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.author.bot:
return
if self.client.user.mentioned_in(message):
if message.author.nick:
name = message.author.nick

if self.client.user.mentioned_in(message): # type: ignore
if message.author.nick: # type: ignore
name = message.author.nick # type: ignore
else:
name = message.author.name
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + self.cloudflare_token,
"Authorization": f"Bearer {self.cloudflare_token}",
}
payload = {
"messages": [
Expand All @@ -141,11 +146,10 @@ async def on_message(self, message: discord.Message):
},
{
"role": "user",
"content": message.content.strip(f"<@!{self.client.user.id}>"),
"content": message.content.strip(f"<@!{self.client.user.id}>"), # type: ignore
},
]
}
await message.channel.typing()
response = await self.client.session.post(
url=self.cloudflare_url, headers=headers, json=payload
)
Expand All @@ -172,24 +176,23 @@ async def join(self, ctx: commands.Context):
perms.ban_members = True
perms.kick_members = True
perms.manage_messages = True
perms.manage_expressions = True
perms.embed_links = True
perms.speak = True
perms.connect = True
perms.read_message_history = True
perms.attach_files = True
perms.add_reactions = True
perms.use_application_commands = True
await ctx.send(f"<{oauth_url(self.client_id, permissions=perms)}>")
await ctx.send(f"<{oauth_url(self.client_id, permissions=perms)}>") # type: ignore

@commands.Cog.listener()
async def on_command_completion(self, ctx: commands.Context) -> None:
full_command_name = ctx.command.qualified_name
full_command_name = ctx.command.qualified_name # type: ignore
split = full_command_name.split(" ")
executed_command = str(split[0])
self.client.logger.info(
f"Executed {executed_command} command in {ctx.guild.name}"
+ f"(ID: {ctx.message.guild.id}) by {ctx.message.author} (ID: {ctx.message.author.id})"
f"Executed {executed_command} command in {ctx.guild.name}" # type: ignore
+ f"(ID: {ctx.message.guild.id}) by {ctx.message.author} (ID: {ctx.message.author.id})" # type: ignore
)


Expand Down

0 comments on commit 38b3311

Please sign in to comment.