Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 3, 2023
1 parent a097687 commit 260eacd
Show file tree
Hide file tree
Showing 27 changed files with 2 additions and 64 deletions.
1 change: 0 additions & 1 deletion bot/commands/resistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@Command("resistor")
async def resistor(msg, *colors):

if len(colors) == 0:
await msg.reply(f"{bot.msg_prefix}Try: !resistor brown black red gold")
return
Expand Down
24 changes: 1 addition & 23 deletions bot/helpers/ResistorColourCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class ValuesSeries(object):
##############################################

def __init__(self, name, number_of_digits, tolerances, values):

"""The parameter *name* gives the name of the series, the parameter *number_of_digits* defines the
number of digits of the values, the parameter *tolerances* gives the list of tolerances and
*values* gives the series of values.
Expand Down Expand Up @@ -80,39 +79,33 @@ def __init__(self, name, number_of_digits, tolerances, values):
##############################################

def __str__(self):

return self.name

##############################################

def __lt__(self, other):

return len(self) < len(other)

##############################################

def __contains__(self, value):

return value in self.values

##############################################

def __len__(self):

return len(self.values)

##############################################

def tolerance_min(self):

"""Return the minimum tolerance."""

return min(self.tolerances)

##############################################

def tolerance_max(self):

"""Return the maximum tolerance."""

return max(self.tolerances)
Expand Down Expand Up @@ -501,7 +494,6 @@ def tolerance_max(self):


def series_iterator(number_of_digits_min=2, number_of_digits_max=3, tolerance_min=1, tolerance_max=5):

"""Return an iterator over the series that match the given constraints on the number of digits
range and the tolerance ranges.
"""
Expand Down Expand Up @@ -578,7 +570,6 @@ def series_iterator(number_of_digits_min=2, number_of_digits_max=3, tolerance_mi


def format_value(x):

"""Return a string representation of a number *x* using the multiplier m, k, M and G, for example
the number 1230 will be formated as 1.23 k.
Expand Down Expand Up @@ -623,7 +614,6 @@ class ColourCode(object):
##############################################

def __init__(self, colour_name, digit, multiplier, tolerance, temperature_coefficient):

self.colour_name = colour_name
self.digit = digit
self.multiplier = multiplier
Expand All @@ -633,7 +623,6 @@ def __init__(self, colour_name, digit, multiplier, tolerance, temperature_coeffi
##############################################

def __repr__(self):

if self.digit is not None:
digit_str = "d%u" % self.digit
else:
Expand Down Expand Up @@ -665,7 +654,7 @@ def __repr__(self):
COLOUR_CODES = {}
for i, colour_name in enumerate(COLOUR_NAMES):
digit = i - 2
multiplier = 10 ** digit
multiplier = 10**digit
# digit is defined positive
if digit < 0:
digit = None
Expand Down Expand Up @@ -722,7 +711,6 @@ def __init__(
tolerance=None,
temperature_coefficient=None,
):

if value is not None:
self.value = value
self.number_of_digits = number_of_digits
Expand Down Expand Up @@ -750,7 +738,6 @@ def __init__(
##############################################

def _init_tolerance(self, tolerance):

"""Set the tolerance from a colour or a real number."""

if tolerance is None:
Expand All @@ -766,7 +753,6 @@ def _init_tolerance(self, tolerance):
##############################################

def _init_temperature_coefficient(self, temperature_coefficient):

"""Set the temperature coefficient from a colour or a real number."""

if temperature_coefficient is None:
Expand All @@ -782,7 +768,6 @@ def _init_temperature_coefficient(self, temperature_coefficient):
##############################################

def _compute_value_from_colours(self):

"""compute the resistance value from the colour code."""

try:
Expand All @@ -803,7 +788,6 @@ def _compute_value_from_colours(self):
##############################################

def _guess_series(self):

"""Guess the series of the resistor.
Expand Down Expand Up @@ -836,7 +820,6 @@ def _guess_series(self):
##############################################

def value_range(self):

"""Return the resistance range according to the resistance tolerance."""

if self.tolerance is not None:
Expand All @@ -847,7 +830,6 @@ def value_range(self):
##############################################

def __str__(self):

if self.tolerance is not None:
tolerance_str = "%.2f%%" % self.tolerance
else:
Expand All @@ -874,7 +856,6 @@ def __str__(self):
##############################################

def digit_colour_iterator(self):

"""Return a iterator over the colours of the resistance value."""

return iter(
Expand Down Expand Up @@ -909,7 +890,6 @@ class ResistorDecoder(object):
##############################################

def _append_hypothesis(self, resistor_configuration, hypotheses):

"""Append an hypothesis if it is acceptable."""

# print 'Try:', keys
Expand All @@ -933,7 +913,6 @@ def _append_hypothesis(self, resistor_configuration, hypotheses):
##############################################

def _decode(self, colour_names, hypotheses):

"""Decode a resistor in one direction from the given list of colour *colour_names*."""

two_digits_bands = ["digit1", "digit2", "multiplier"]
Expand All @@ -959,7 +938,6 @@ def _decode(self, colour_names, hypotheses):
##############################################

def decode(self, colour_names):

"""Decode a resistor from the given list of colour *colour_names*."""

number_of_colours = len(colour_names)
Expand Down
2 changes: 0 additions & 2 deletions bot/mods/announcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ async def announce_list(self, msg, *args):

@SubCommand(announce, "del", permission="admin")
async def announce_del(self, msg, *args):

try:
id = args[0]
id = int(id)
Expand Down Expand Up @@ -257,7 +256,6 @@ async def announce_del(self, msg, *args):

@SubCommand(announce, "add", permission="admin")
async def announce_add(self, msg, *args):

message = ""

# Build the message
Expand Down
2 changes: 0 additions & 2 deletions bot/mods/auto_bahn.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ async def update_json_list(self):
# This endpoint only returns 100 at a time
while offset < count:
async with aiohttp.ClientSession() as session:

response = await session.get(url=f"{url[1]}?offset={offset}")
ic(f"Retrieved url 2, offset {offset}")

Expand Down Expand Up @@ -163,7 +162,6 @@ async def check_to_ban_user(self, user: str, channel: Channel):
return False

async def do_ban(user: str):

discord_message = f"{user} banned for being a bot."

if self.autoban_enable:
Expand Down
1 change: 0 additions & 1 deletion bot/mods/auto_vip.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ async def on_channel_joined(self, channel: Channel):
await channel.send_message("/vips")

async def on_raw_message(self, msg: Message):

if msg.type is MessageType.NOTICE and msg.msg_id == "vips_success":
# Split the message on the colon which removes the preamble
temp_parse = msg.normalized_content.split(":", maxsplit=1)
Expand Down
1 change: 0 additions & 1 deletion bot/mods/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def __init__(self):
self.hosters = list()

async def timer_loop(self):

# Grab the UID of channel 0
headers = {
"client-id": get_client_id(),
Expand Down
1 change: 0 additions & 1 deletion bot/mods/ignorelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async def ignore(self, msg: Message):

@SubCommand(ignore, "add", permission="admin")
async def ignore_add(self, msg: Message, pattern: str):

# Check if the regex is valid, return error if not.
try:
re.compile(pattern)
Expand Down
2 changes: 0 additions & 2 deletions bot/mods/polls_to_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def get_poll_data(self, poll: PollData) -> str:
return json.dumps(poll_data)

async def on_poll_started(self, channel: Channel, poll: PollData):

# Send the setup data to MQTT
setup_json = self.get_poll_setup(poll)
bot.poll_display_active = True
Expand All @@ -54,7 +53,6 @@ async def on_poll_started(self, channel: Channel, poll: PollData):
await asyncio.sleep(self.update_frequency)

async def on_poll_ended(self, channel: Channel, poll: PollData):

# Send final results
data_json = self.get_poll_data(poll)
await self.mqtt.send(self.mqtt.Topics.poll_data, data_json)
Expand Down
1 change: 0 additions & 1 deletion bot/mods/so.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ async def shoutout(self, msg: Message, *args):

@SubCommand(shoutout, "msg", permission="admin")
async def shoutout_msg(self, msg: Message, *args):

message = ""
for word in args:
message += f"{word} "
Expand Down
2 changes: 0 additions & 2 deletions bot/mods/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ async def topic(self, msg, *args):

@SubCommand(topic, "set", permission="admin")
async def set_topic(self, msg, *args):

new_topic = ""
for arg in args:
new_topic += f"{arg} "
Expand All @@ -61,7 +60,6 @@ async def set_topic(self, msg, *args):

@SubCommand(topic, "goal", permission="admin")
async def set_topic_goal(self, msg, *args):

goal = ""
for arg in args:
goal += f"{arg} "
Expand Down
3 changes: 0 additions & 3 deletions bot/mods/trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ async def trivia_start(self, msg: Message, debug=False):

@SubCommand(trivia, "end", permission="bot")
async def trivia_end(self, msg: Message):

self.trivia_active = False # Deactivate trivia, allows winner to run
self.start_running = False
# Clears the current question, interrupting the timer loop for it
Expand Down Expand Up @@ -570,7 +569,6 @@ def calculate_scoreboard(self):
return ordered_scoreboard

async def send_answers_to_mqtt(self, done: bool = False, explanation: str = None, answer_id=None):

# Track the total number of votes so we can send it to the front end
total_votes = 0
for k, v in self.current_question_answers_count.items():
Expand Down Expand Up @@ -677,7 +675,6 @@ async def update_users_in_database(self, question_id: int = 0, final: list = [])
return True

async def get_user_id_with_retry(self, username: str):

# Get the user id, but sometimes this fails and returns a -1, if it's -1 try again up to 3 times.
# If it still fails, send a message to the console and do not insert into the database.
user_id = -1
Expand Down
1 change: 0 additions & 1 deletion bot/mods/unknown_command_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self):
async def on_privmsg_received(self, msg: Message):
"""Check if a command exists, and log it if it doesn't."""
try:

first = msg.parts[0]
if first[0] == cfg.prefix:
# The bot framework never fires on_privmsg_received if it detects
Expand Down
1 change: 0 additions & 1 deletion bot/mods/user_chat_time_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ async def on_bot_shutdown(self):
await self.user_exit(users, channels[chan])

async def user_exit(self, users: Union[str, frozenset], channel: Channel):

now = datetime.now()

# If only a single user is passed, convert it to a frozenset as if a list of users was passed
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,4 @@ All Stream related MQTT topics are prefixed with `stream/`
- `first_time_chatter` TwitchBot sends json `{"author":"author name", "timestamp"=str(datetime.now())}` when a new chatter is seen ever.
- `new_chatter_topic` TwitchBot sends json `{"author":"author name", "timestamp"=str(datetime.now())}` when a new chatter is seen for the first time this stream.

This is a test, this is only a test.
This is a test, this is only a test.
1 change: 0 additions & 1 deletion web/eventsub_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@


def get_app_key(force_update: bool = False):

# Get client_id and client_secret
res = session.query(Settings).filter(Settings.key == "twitch_client").one_or_none()
if not res:
Expand Down
1 change: 0 additions & 1 deletion web/routes/announcements.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ async def post_announcements_category(
category: int = Form(...),
user=Depends(check_user(level=AuthLevel.mod)),
):

query = db.session.query(Announcements).filter(Announcements.id == announcement_id).one_or_none()
if query:
query.category = category
Expand Down
2 changes: 0 additions & 2 deletions web/routes/auto_bahn.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async def autoban_manage(request: Request, user=Depends(check_user(level=AuthLev

@router.get("/autoban/manage.html")
async def autoban_manage_html(request: Request, user=Depends(check_user(level=AuthLevel.admin))):

result = db.session.query(BotRegex).order_by(BotRegex.id).all()

response = templates.TemplateResponse("manage.html.jinja", {"request": request, "result": result})
Expand All @@ -43,7 +42,6 @@ async def autoban_manage_html(request: Request, user=Depends(check_user(level=Au

@router.get("/autoban/manage.js")
async def autoban_manage_js(request: Request, user=Depends(check_user(level=AuthLevel.admin))):

return FileResponse("static_files/autoban/manage.js")


Expand Down
2 changes: 0 additions & 2 deletions web/routes/clips.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ async def clips(request: Request, user=Depends(check_user(level=AuthLevel.admin)

@router.get("/clips/manage.html", response_class=HTMLResponse)
async def clips_manage_html(request: Request, user=Depends(check_user(level=AuthLevel.admin))):

result = db.session.query(Clips).order_by(Clips.id).all()
message = request.cookies.get("clipmsg", "") or "Manage Clips"
response = templates.TemplateResponse(
Expand Down Expand Up @@ -83,7 +82,6 @@ async def post_clips_add(
url: str = Form(...),
user=Depends(check_user(level=AuthLevel.admin)),
):

regex = r"(https?:\/\/(www\.|clips\.)?twitch\.tv\/(baldengineer\/clip\/)?(?P<clip_id>[A-Za-z0-9_\-]*)?)"
match = re.search(regex, url)

Expand Down
1 change: 0 additions & 1 deletion web/routes/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@router.get("/commands", response_class=HTMLResponse)
async def get_commands(request: Request, user=Depends(check_user(level=AuthLevel.admin))):

try:
result = db.session.query(CustomCommand).order_by(CustomCommand.id).all()

Expand Down
2 changes: 0 additions & 2 deletions web/routes/discord_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def discord_webhook(request: Request, user=Depends(check_user(level=AuthLevel.ad

@router.get("/discord/webhook_manage.html", response_class=HTMLResponse)
def discord_webhook_html(request: Request, user=Depends(check_user(level=AuthLevel.admin))):

key_list = ["to_do_webhook", "link_webhook", "ban_webhook"]

result = db.session.query(Settings).filter(Settings.key.in_(key_list)).all()
Expand All @@ -47,7 +46,6 @@ async def discord_webhook_manage_save(
webhook_url: str = Form(...),
user=Depends(check_user(level=AuthLevel.admin)),
):

pattern = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)"
match = re.search(pattern, webhook_url)

Expand Down
Loading

0 comments on commit 260eacd

Please sign in to comment.