Skip to content

Commit f5ef6f6

Browse files
committed
attempted to fix some errors from mypy and updated gitignore and requirements.txt
1 parent 9dcfcd6 commit f5ef6f6

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ venv/
1919
*~
2020

2121
#VSCode
22-
settings.json
22+
settings.json
23+
24+
#for mypy
25+
/.mypy_cache/

dozer/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
if config['sentry_url'] != "":
6262
sentry_sdk.init( # pylint: disable=abstract-class-instantiated # noqa: E0110
63-
config['sentry_url'],
63+
str(config['sentry_url']),
6464
traces_sample_rate=1.0,
6565
)
6666

@@ -76,7 +76,7 @@
7676

7777
intents = discord.Intents.default()
7878
intents.members = True
79-
intents.presences = config['presences_intents']
79+
intents.presences = bool(config['presences_intents'])
8080

8181
bot = Dozer(config, intents=intents, max_messages=config['cache_size'])
8282

dozer/cogs/_utils.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import typing
66
from collections.abc import Mapping
7-
from typing import Dict
7+
from typing import Dict, Union
88

99
import discord
1010
from discord.ext import commands
@@ -175,7 +175,8 @@ def stop(self):
175175
self._action = self._stop_reaction
176176

177177
def _check_reaction(self, reaction: discord.Reaction, member: discord.Member):
178-
return reaction.message.id == self.message.id and member.id == self.caller.id
178+
if self.message is not None:
179+
return reaction.message.id == self.message.id and member.id == self.caller.id
179180

180181

181182
class Paginator(Reactor):
@@ -237,7 +238,7 @@ async def __aiter__(self):
237238
else: # Only valid option left is 4
238239
self.stop()
239240

240-
def go_to_page(self, page: int):
241+
def go_to_page(self, page: Union[int, str]):
241242
"""Goes to a specific help page"""
242243
if isinstance(page, int):
243244
page = page % self.len_pages

dozer/cogs/filter.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async def check_filters_messages(self, message: discord.Message):
5252
"""Check all the filters for a certain message (with it's guild)"""
5353
if message.author.id == self.bot.user.id or not hasattr(message.author, 'roles'):
5454
return
55+
5556
roles = await self.word_filter_role_whitelist.query_all(guild_id=message.guild.id)
5657
whitelisted_ids = set(role.role_id for role in roles)
5758
if any(x.id in whitelisted_ids for x in message.author.roles):
@@ -236,14 +237,14 @@ async def remove(self, ctx: DozerContext, filter_id: int):
236237
@guild_only()
237238
@has_permissions(manage_guild=True)
238239
@filter.command(name="dm")
239-
async def dm_config(self, ctx: DozerContext, config: bool):
240+
async def dm_config(self, ctx: DozerContext, config: str):
240241
"""Set whether filter words should be DMed when used in bot messages"""
241-
config = str(int(config)) # turns into "1" or "0" idk man
242+
config: str = str(int(config)) # turns into "1" or "0" idk man
242243
results = await WordFilterSetting.get_by(guild_id=ctx.guild.id, setting_type="dm")
243244
if results:
244245
before_setting = results[0].value
245246
# Due to the settings table having a serial ID, inserts always succeed, so update_or_add can't be used to
246-
# update in place. Instead we have to delete and reinsert the record.
247+
# update in place. Instead, we have to delete and reinsert the record.
247248
await WordFilterSetting.delete(guild_id=results[0].guild_id, setting_type=results[0].setting_type)
248249
else:
249250
before_setting = None
@@ -254,7 +255,8 @@ async def dm_config(self, ctx: DozerContext, config: bool):
254255
"The DM setting for this guild has been changed from {} to {}.".format(before_setting == "1",
255256
result.value == "1"))
256257

257-
dm_config.example_usage = "`{prefix}filter dm_config True` - Makes all messages containining filter lists to be sent through DMs"
258+
dm_config.example_usage = "`{prefix}filter dm_config True` - Makes all messages containining filter lists to be " \
259+
"sent through DMs "
258260

259261
@guild_only()
260262
@filter.group(invoke_without_command=True)
@@ -316,7 +318,7 @@ def setup(bot):
316318
class WordFilter(db.DatabaseTable):
317319
"""Object for each filter"""
318320
__tablename__ = 'word_filters'
319-
__uniques__ = 'filter_id'
321+
__uniques__ = ['filter_id']
320322

321323
@classmethod
322324
async def initial_create(cls):
@@ -354,7 +356,7 @@ async def get_by(cls, **kwargs):
354356
class WordFilterSetting(db.DatabaseTable):
355357
"""Each filter-related setting"""
356358
__tablename__ = 'word_filter_settings'
357-
__uniques__ = 'id'
359+
__uniques__ = ['id']
358360

359361
@classmethod
360362
async def initial_create(cls):
@@ -388,7 +390,7 @@ async def get_by(cls, **kwargs):
388390
class WordFilterRoleWhitelist(db.DatabaseTable):
389391
"""Object for each whitelisted role"""
390392
__tablename__ = 'word_filter_role_whitelist'
391-
__uniques__ = 'role_id'
393+
__uniques__ = ['role_id']
392394

393395
@classmethod
394396
async def initial_create(cls):

dozer/sources/AbstractSources.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
class Source:
77
"""Abstract base class for a data source."""
88

9-
full_name = "Source Name"
10-
short_name = "src"
11-
base_url = None
12-
aliases = tuple()
9+
full_name: str = "Source Name"
10+
short_name: str = "src"
11+
base_url: str = ""
12+
aliases: tuple = tuple()
1313
description = "Description"
1414
disabled = False
1515

@@ -100,9 +100,9 @@ class DataPoint:
100100
full_name: The string that will be displayed to the user of your cleaned, verified data.
101101
"""
102102

103-
def __init__(self, short_name, full_name):
104-
self.short_name = short_name
105-
self.full_name = full_name
103+
def __init__(self, short_name: str, full_name: str):
104+
self.short_name: str = short_name
105+
self.full_name: str = full_name
106106

107107
def __str__(self):
108108
return self.short_name

dozer/sources/RSSSources.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ def clean_html(raw_html):
1919

2020
class RSSSource(Source):
2121
"""Given an arbitrary RSS feed, get new posts from it"""
22-
url = None
22+
url: str = ""
2323
color = discord.colour.Color.blurple()
2424
date_formats = ["%a, %d %b %Y %H:%M:%S %z",
2525
"%a, %d %b %Y %H:%M:%S %Z"] # format for datetime.strptime()
26-
base_url = None
27-
read_more_str = "...\n Read More"
26+
base_url: str = ""
27+
read_more_str: str = "...\n Read More"
2828

2929
def __init__(self, aiohttp_session: aiohttp.ClientSession, bot):
3030
super().__init__(aiohttp_session, bot)
31-
self.guids_seen = set()
31+
self.guids_seen: set = set()
3232

3333
async def first_run(self):
3434
"""Fetch the current posts in the feed and add them to the guids_seen set"""
@@ -154,8 +154,8 @@ def generate_plain_text(self, data):
154154

155155
class FRCBlogPosts(RSSSource):
156156
"""Official blog posts from the FIRST Robotics Competition"""
157-
url = "https://www.firstinspires.org/robotics/frc/blog-rss"
158-
base_url = "https://www.firstinspires.org/robotics/frc/blog/"
157+
url: str = "https://www.firstinspires.org/robotics/frc/blog-rss"
158+
base_url: str = "https://www.firstinspires.org/robotics/frc/blog/"
159159
full_name = "FRC Blog Posts"
160160
short_name = "frc"
161161
description = "Official blog posts from the FIRST Robotics Competition"
@@ -228,7 +228,7 @@ class JVNBlog(RSSSource):
228228
base_url = "https://johnvneun.com/"
229229
full_name = "JVN's Blog"
230230
short_name = "jvn"
231-
aliases = ['148', 'robowranglers']
231+
aliases = '148', 'robowranglers'
232232
description = "Blog posts by John V Neun, 148 Head Engineer"
233233
color = discord.colour.Color(value=000000)
234234

@@ -239,7 +239,7 @@ class SpectrumBlog(RSSSource):
239239
base_url = "http://spectrum3847.org/category/blog/"
240240
full_name = "Spectrum Blog"
241241
short_name = "spectrum"
242-
aliases = ['3847']
242+
aliases = '3847'
243243
description = "Blog Posts from team 3847, Spectrum"
244244
color = discord.colour.Color.purple()
245245

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
asyncpg~=0.21.0
1+
asyncpg~=0.23.0
22
py-cord
33
tbapi~=1.3.1b5
44
aiotba~=0.0.2.post1

0 commit comments

Comments
 (0)