Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import urllib.parse
from functools import partial
# import sys
import aiohttp
import discord
from bs4 import BeautifulSoup
from bs4.element import NavigableString
from markdownify import MarkdownConverter
# sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import _used
class DocMarkdownConverter(MarkdownConverter):
# def convert_code(self, el, text):
# """Undo `markdownify`s underscore escaping."""
# print(el)
# print(el.strings)
# print(text)
# return f"`{text}`".replace('\\', '')
def convert_pre(self, el, text):
"""Wrap any codeblocks in `py` for syntax highlighting."""
code = ''.join(el.strings)
return f"```py\n{code}```"
from will import settings
from .base import IOBackend
from will.utils import Bunch, UNSURE_REPLIES, clean_for_pickling
from will.mixins import SleepMixin, StorageMixin
from multiprocessing import Process
from will.abstractions import Event, Message, Person, Channel
from slackclient import SlackClient
from slackclient.server import SlackConnectionError
SLACK_SEND_URL = "https://slack.com/api/chat.postMessage"
SLACK_SET_TOPIC_URL = "https://slack.com/api/channels.setTopic"
SLACK_PRIVATE_SET_TOPIC_URL = "https://slack.com/api/groups.setTopic"
class SlackMarkdownConverter(MarkdownConverter):
def convert_strong(self, el, text):
return '*%s*' % text if text else ''
class SlackBackend(IOBackend, SleepMixin, StorageMixin):
friendly_name = "Slack"
internal_name = "will.backends.io_adapters.slack"
required_settings = [
{
"name": "SLACK_API_TOKEN",
"obtain_at": """1. Go to https://api.slack.com/custom-integrations/legacy-tokens and sign in as yourself (or a user for Will).
2. Find the workspace you want to use, and click "Create token."
3. Set this token as SLACK_API_TOKEN."""
}
]
async def wrapper(*args) -> Any:
"""Decorator wrapper for the caching logic."""
key = ':'.join(args[arg_offset:])
value = async_cache.cache.get(key)
if value is None:
if len(async_cache.cache) > max_size:
async_cache.cache.popitem(last=False)
async_cache.cache[key] = await function(*args)
return async_cache.cache[key]
return wrapper
return decorator
class DocMarkdownConverter(MarkdownConverter):
"""Subclass markdownify's MarkdownCoverter to provide custom conversion methods."""
def convert_code(self, el: PageElement, text: str) -> str:
"""Undo `markdownify`s underscore escaping."""
return f"`{text}`".replace('\\', '')
def convert_pre(self, el: PageElement, text: str) -> str:
"""Wrap any codeblocks in `py` for syntax highlighting."""
code = ''.join(el.strings)
return f"```py\n{code}```"
def markdownify(html: str) -> DocMarkdownConverter:
"""Create a DocMarkdownConverter object from the input html."""
return DocMarkdownConverter(bullets='•').convert(html)