Skip to content

Commit

Permalink
Clean up post-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed Apr 9, 2024
1 parent 639eff2 commit c20952f
Show file tree
Hide file tree
Showing 52 changed files with 250 additions and 5,594 deletions.
1 change: 1 addition & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
cache: "pip"
cache-dependency-path: |
**/*requirements*.txt
- name: Install apt deps
run: sudo apt-get update && sudo apt-get install -qq -y libxml2-dev libxslt1-dev
- name: Install dependencies
Expand Down
4 changes: 3 additions & 1 deletion cloudbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def __init__(
db_path = self.config.get("database", "sqlite:///cloudbot.db")
self.db_engine = create_engine(db_path)
database.configure(self.db_engine)
self.db_executor_pool = ExecutorPool(50, max_workers=1, thread_name_prefix='cloudbot-db')
self.db_executor_pool = ExecutorPool(
50, max_workers=1, thread_name_prefix="cloudbot-db"
)

logger.debug("Database system initialised.")

Expand Down
1 change: 0 additions & 1 deletion cloudbot/event.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import concurrent.futures
import enum
import logging
from functools import partial
Expand Down
3 changes: 2 additions & 1 deletion cloudbot/util/async_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def run_coroutine_threadsafe(coro, loop):
asyncio.run_coroutine_threadsafe(coro, loop)


def create_future(loop):
def create_future(loop=None):
loop = loop if loop is not None else asyncio.get_event_loop()
return loop.create_future()


Expand Down
3 changes: 1 addition & 2 deletions cloudbot/util/backoff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import random

import time


Expand All @@ -17,7 +16,7 @@ def randfunc(self):

def __enter__(self):
self._exp = min(self._exp + 1, self._max)
wait = self.randfunc(0, self._base * (2 ** self._exp))
wait = self.randfunc(0, self._base * (2**self._exp))
time.sleep(wait)
return self

Expand Down
6 changes: 4 additions & 2 deletions cloudbot/util/executor_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cloudbot.util.async_util import create_future

logger = logging.getLogger('cloudbot')
logger = logging.getLogger("cloudbot")


class ExecutorWrapper:
Expand All @@ -26,7 +26,9 @@ def __del__(self):


class ExecutorPool:
def __init__(self, max_executors=None, executor_type=ThreadPoolExecutor, **kwargs):
def __init__(
self, max_executors=None, executor_type=ThreadPoolExecutor, **kwargs
):
if max_executors is None:
max_executors = (os.cpu_count() or 1) * 5

Expand Down
30 changes: 15 additions & 15 deletions cloudbot/util/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from typing import Dict, Optional, Union

import requests
from pbincli import api as pb_api
from pbincli.format import Paste as pb_Paste
from requests import (
HTTPError,
PreparedRequest,
Expand All @@ -28,9 +30,6 @@
Response,
)

from pbincli import api as pb_api
from pbincli.format import Paste as pb_Paste

# Constants
DEFAULT_SHORTENER = "is.gd"
DEFAULT_PASTEBIN = ""
Expand Down Expand Up @@ -376,16 +375,17 @@ class PrivateBin(Pastebin):
def __init__(self, url):
super().__init__()
self.api_client = pb_api.PrivateBin(
str(url), {'proxy': '', 'nocheckcert': False, 'noinsecurewarn': False}
str(url),
{"proxy": "", "nocheckcert": False, "noinsecurewarn": False},
)

def paste(self, data, ext, password=None, expire='1day'):
if ext in ('txt', 'text'):
syntax = 'plaintext'
elif ext in ('md', 'markdown'):
syntax = 'markdown'
def paste(self, data, ext, password=None, expire="1day"):
if ext in ("txt", "text"):
syntax = "plaintext"
elif ext in ("md", "markdown"):
syntax = "markdown"
else:
syntax = 'syntaxhighlighting'
syntax = "syntaxhighlighting"

try:
version = self.api_client.getVersion()
Expand Down Expand Up @@ -428,16 +428,16 @@ def paste(self, data, ext, password=None, expire='1day'):
except RequestException as e:
raise ServiceError(e.request, "Connection error occurred") from e

if result['status'] != 0:
raise ServiceError(None, result['message'])
if result["status"] != 0:
raise ServiceError(None, result["message"])

return "{}?{}#{}".format(
self.api_client.server, result['id'], _paste.getHash()
self.api_client.server, result["id"], _paste.getHash()
)


pastebins.register('hastebin', Hastebin(HASTEBIN_SERVER))
pastebins.register('privatebin', PrivateBin('https://privatebin.net/'))
pastebins.register("hastebin", Hastebin(HASTEBIN_SERVER))
pastebins.register("privatebin", PrivateBin("https://privatebin.net/"))

shorteners.register("git.io", Gitio())
shorteners.register("goo.gl", Googl())
Expand Down
2 changes: 1 addition & 1 deletion plugins/core/server_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def do_isupport(bot):


@hook.connect()
def clear_isupport(conn: 'IrcClient'):
def clear_isupport(conn: "IrcClient"):
serv_info = conn.memory.setdefault("server_info", {})
statuses = get_status_modes(serv_info, clear=True)
for s in DEFAULT_STATUS:
Expand Down
Loading

0 comments on commit c20952f

Please sign in to comment.