diff --git a/bot/commands/resistor.py b/bot/commands/resistor.py index 8ee756ee..9cf5573e 100644 --- a/bot/commands/resistor.py +++ b/bot/commands/resistor.py @@ -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 diff --git a/bot/helpers/ResistorColourCode.py b/bot/helpers/ResistorColourCode.py index 5135c1c2..de5b19c1 100644 --- a/bot/helpers/ResistorColourCode.py +++ b/bot/helpers/ResistorColourCode.py @@ -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. @@ -80,31 +79,26 @@ 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) @@ -112,7 +106,6 @@ def tolerance_min(self): ############################################## def tolerance_max(self): - """Return the maximum tolerance.""" return max(self.tolerances) @@ -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. """ @@ -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. @@ -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 @@ -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: @@ -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 @@ -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 @@ -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: @@ -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: @@ -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: @@ -803,7 +788,6 @@ def _compute_value_from_colours(self): ############################################## def _guess_series(self): - """Guess the series of the resistor. @@ -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: @@ -847,7 +830,6 @@ def value_range(self): ############################################## def __str__(self): - if self.tolerance is not None: tolerance_str = "%.2f%%" % self.tolerance else: @@ -874,7 +856,6 @@ def __str__(self): ############################################## def digit_colour_iterator(self): - """Return a iterator over the colours of the resistance value.""" return iter( @@ -909,7 +890,6 @@ class ResistorDecoder(object): ############################################## def _append_hypothesis(self, resistor_configuration, hypotheses): - """Append an hypothesis if it is acceptable.""" # print 'Try:', keys @@ -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"] @@ -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) diff --git a/bot/mods/announcer.py b/bot/mods/announcer.py index cebfc16f..c0d61d57 100755 --- a/bot/mods/announcer.py +++ b/bot/mods/announcer.py @@ -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) @@ -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 diff --git a/bot/mods/auto_bahn.py b/bot/mods/auto_bahn.py index c32c4f1c..1d0bb156 100644 --- a/bot/mods/auto_bahn.py +++ b/bot/mods/auto_bahn.py @@ -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}") @@ -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: diff --git a/bot/mods/auto_vip.py b/bot/mods/auto_vip.py index a1a006b3..07997afa 100644 --- a/bot/mods/auto_vip.py +++ b/bot/mods/auto_vip.py @@ -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) diff --git a/bot/mods/hosts.py b/bot/mods/hosts.py index f748320c..85540b37 100644 --- a/bot/mods/hosts.py +++ b/bot/mods/hosts.py @@ -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(), diff --git a/bot/mods/ignorelist.py b/bot/mods/ignorelist.py index 2007208c..b7230cd0 100644 --- a/bot/mods/ignorelist.py +++ b/bot/mods/ignorelist.py @@ -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) diff --git a/bot/mods/polls_to_mqtt.py b/bot/mods/polls_to_mqtt.py index edf7f8d9..89b278b3 100644 --- a/bot/mods/polls_to_mqtt.py +++ b/bot/mods/polls_to_mqtt.py @@ -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 @@ -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) diff --git a/bot/mods/so.py b/bot/mods/so.py index a36ca782..ce05cf4c 100644 --- a/bot/mods/so.py +++ b/bot/mods/so.py @@ -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} " diff --git a/bot/mods/topic.py b/bot/mods/topic.py index 5df7f57c..d8508702 100755 --- a/bot/mods/topic.py +++ b/bot/mods/topic.py @@ -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} " @@ -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} " diff --git a/bot/mods/trivia.py b/bot/mods/trivia.py index e5d98050..a781c195 100644 --- a/bot/mods/trivia.py +++ b/bot/mods/trivia.py @@ -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 @@ -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(): @@ -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 diff --git a/bot/mods/unknown_command_logger.py b/bot/mods/unknown_command_logger.py index 54144f85..05f74b08 100644 --- a/bot/mods/unknown_command_logger.py +++ b/bot/mods/unknown_command_logger.py @@ -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 diff --git a/bot/mods/user_chat_time_logging.py b/bot/mods/user_chat_time_logging.py index a3ba2e28..d38b221c 100755 --- a/bot/mods/user_chat_time_logging.py +++ b/bot/mods/user_chat_time_logging.py @@ -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 diff --git a/readme.md b/readme.md index f1a3a985..c45163a6 100644 --- a/readme.md +++ b/readme.md @@ -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. \ No newline at end of file +This is a test, this is only a test. diff --git a/web/eventsub_manage.py b/web/eventsub_manage.py index 8e4eee82..1d8e36dd 100755 --- a/web/eventsub_manage.py +++ b/web/eventsub_manage.py @@ -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: diff --git a/web/routes/announcements.py b/web/routes/announcements.py index eecd8da3..16f180c6 100644 --- a/web/routes/announcements.py +++ b/web/routes/announcements.py @@ -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 diff --git a/web/routes/auto_bahn.py b/web/routes/auto_bahn.py index 63189499..e0992822 100644 --- a/web/routes/auto_bahn.py +++ b/web/routes/auto_bahn.py @@ -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}) @@ -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") diff --git a/web/routes/clips.py b/web/routes/clips.py index b8323865..15d213cf 100644 --- a/web/routes/clips.py +++ b/web/routes/clips.py @@ -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( @@ -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[A-Za-z0-9_\-]*)?)" match = re.search(regex, url) diff --git a/web/routes/commands.py b/web/routes/commands.py index fe4cca77..9d199503 100644 --- a/web/routes/commands.py +++ b/web/routes/commands.py @@ -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() diff --git a/web/routes/discord_webhooks.py b/web/routes/discord_webhooks.py index 9d0cbeb2..83f2af77 100644 --- a/web/routes/discord_webhooks.py +++ b/web/routes/discord_webhooks.py @@ -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() @@ -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) diff --git a/web/routes/send_command.py b/web/routes/send_command.py index b74b31d5..8835c7e8 100644 --- a/web/routes/send_command.py +++ b/web/routes/send_command.py @@ -26,7 +26,6 @@ async def post_topic( uri = "ws://bot:13337" try: async with websockets.connect(uri) as s: - # We don't actually need this, but we have to read it before the bot will accept commands await s.recv() diff --git a/web/routes/send_message.py b/web/routes/send_message.py index d9b38ebe..3856ed71 100644 --- a/web/routes/send_message.py +++ b/web/routes/send_message.py @@ -25,7 +25,6 @@ async def post_message( uri = "ws://bot:13337" try: async with websockets.connect(uri) as s: - # We don't actually need this, but we have to read it before the bot will accept commands await s.recv() diff --git a/web/routes/topic.py b/web/routes/topic.py index fda82873..8f65dcb4 100644 --- a/web/routes/topic.py +++ b/web/routes/topic.py @@ -38,7 +38,6 @@ async def post_topic( uri = "ws://bot:13337" try: async with websockets.connect(uri) as s: - # We don't actually need this, but we have to read it before the bot will accept commands await s.recv() diff --git a/web/routes/trivia.py b/web/routes/trivia.py index c683ecde..a1ab62a6 100644 --- a/web/routes/trivia.py +++ b/web/routes/trivia.py @@ -71,7 +71,6 @@ async def trivia_play_wav( request: Request, key: str = Depends(check_valid_api_key(level=AuthLevel.admin)), sound_id="default" ): def iterfile(): - audio_file_path = Path(__file__).resolve().parent / ".." / "static_files" / "trivia" / "sounds" question_file = audio_file_path / f"{sound_id}.wav" default_file = audio_file_path / "default.wav" @@ -157,7 +156,6 @@ async def trivia_winners( @router.get("/trivia/winners.html", response_class=FileResponse) async def trivia_winners_html(request: Request, key: str = Depends(check_valid_api_key(level=AuthLevel.admin))): - response = templates.TemplateResponse("winners.html", {"request": request, "key": key}) response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1. response.headers["Pragma"] = "no-cache" # HTTP 1.0. @@ -264,7 +262,6 @@ async def trivia_manage(request: Request, user=Depends(check_user(level=AuthLeve async def trivia_manage_upload( request: Request, questions: UploadFile = File(...), user=Depends(check_user(level=AuthLevel.admin)) ): - # Read the file and decode it to a dictionary value = await questions.read() value = value.decode("utf-8") @@ -279,7 +276,6 @@ async def trivia_manage_upload( try: # Update question if the question text is the same or force_update is set if question["text"] == query.text or question.get("force_update", False): - if question["text"] != query.text and question.get("force_update", False): # Update question text if it is different and force_update is set query.text = question["text"] @@ -341,7 +337,6 @@ async def trivia_manage_upload( @router.get("/trivia/manage/download") async def trivia_manage_download(request: Request, user=Depends(check_user(level=AuthLevel.admin))): - query = db.session.query(TriviaQuestions).order_by(TriviaQuestions.id).all() return_dict = {"quiz": {}} for u in query: diff --git a/web/routes/user_manage.py b/web/routes/user_manage.py index 9001588d..6ee3d95b 100644 --- a/web/routes/user_manage.py +++ b/web/routes/user_manage.py @@ -151,7 +151,6 @@ async def post_user_enable( enabled: bool = Form(...), user=Depends(check_user(level=AuthLevel.admin)), ): - if user.admin or user.mod: query = db.session.query(WebAuth).filter(WebAuth.id == user_id).one_or_none() if query: diff --git a/web/send_to_bot.py b/web/send_to_bot.py index c76a3686..f7ff2492 100644 --- a/web/send_to_bot.py +++ b/web/send_to_bot.py @@ -11,7 +11,6 @@ async def send_command_to_bot(cmd, args: list): - try: # The command console doesn't like when integers are sent, so convert everything to a string clean_args = [str(x) for x in args] diff --git a/web/web_auth.py b/web/web_auth.py index 2e1f6c24..f1463794 100644 --- a/web/web_auth.py +++ b/web/web_auth.py @@ -63,7 +63,6 @@ def check_user_req(request: Request): raise HTTPException(403) except HTTPException: - if request.method == "POST": # If a post request, just return a 403 so there isn't a redirect raise HTTPException(403) else: # Redirect to login if not logged in @@ -85,7 +84,6 @@ def check_api_key( api_key_query: str = Security(api_key_query), api_key_header: str = Security(api_key_header), ): - key = api_key_header or api_key_query if key is None: raise HTTPException(401) @@ -215,7 +213,6 @@ async def callback(request: Request, code: str): @router.get("/cake") async def cake(request: Request, user=Depends(check_user(level=AuthLevel.user))): - redirect_path = request.cookies.get("redirect", "/") # flake8: noqa E501