mirror of https://github.com/stijndcl/didier
Compare commits
8 Commits
3bc9c15af7
...
ad0076537d
| Author | SHA1 | Date |
|---|---|---|
|
|
ad0076537d | |
|
|
ff5de8e88b | |
|
|
d7daeb02ff | |
|
|
a05d8e7138 | |
|
|
5bfb1cecb2 | |
|
|
3d429f21cc | |
|
|
6c8ab9a2a0 | |
|
|
accda93461 |
|
|
@ -5,15 +5,15 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
dependencies:
|
dependencies:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9.5'
|
python-version: '3.9.5'
|
||||||
- name: Cache dependencies
|
- name: Cache dependencies
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
||||||
|
|
@ -23,7 +23,7 @@ jobs:
|
||||||
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
run: pip3 install -r requirements.txt -r requirements-dev.txt
|
||||||
tests:
|
tests:
|
||||||
needs: [dependencies]
|
needs: [dependencies]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:14
|
image: postgres:14
|
||||||
|
|
@ -41,11 +41,11 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9.5'
|
python-version: '3.9.5'
|
||||||
- name: Cache dependencies
|
- name: Cache dependencies
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
||||||
|
|
@ -63,15 +63,15 @@ jobs:
|
||||||
token: ${{ secrets.CODECOV }}
|
token: ${{ secrets.CODECOV }}
|
||||||
linting:
|
linting:
|
||||||
needs: [tests]
|
needs: [tests]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9.5'
|
python-version: '3.9.5'
|
||||||
- name: Cache dependencies
|
- name: Cache dependencies
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
||||||
|
|
@ -83,15 +83,15 @@ jobs:
|
||||||
run: flake8
|
run: flake8
|
||||||
typing:
|
typing:
|
||||||
needs: [tests]
|
needs: [tests]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9.5'
|
python-version: '3.9.5'
|
||||||
- name: Cache dependencies
|
- name: Cache dependencies
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
||||||
|
|
@ -103,15 +103,15 @@ jobs:
|
||||||
run: mypy
|
run: mypy
|
||||||
formatting:
|
formatting:
|
||||||
needs: [tests]
|
needs: [tests]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: '3.9.5'
|
python-version: '3.9.5'
|
||||||
- name: Cache dependencies
|
- name: Cache dependencies
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.m2/repository
|
path: ~/.m2/repository
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from didier.data.apis.xkcd import fetch_xkcd_post
|
||||||
from didier.exceptions.no_match import expect
|
from didier.exceptions.no_match import expect
|
||||||
from didier.menus.memes import MemeSource
|
from didier.menus.memes import MemeSource
|
||||||
from didier.utils.discord import constants
|
from didier.utils.discord import constants
|
||||||
|
from didier.utils.types.string import mock
|
||||||
from didier.views.modals import GenerateMeme
|
from didier.views.modals import GenerateMeme
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -133,6 +134,30 @@ class Fun(commands.Cog):
|
||||||
"""Autocompletion for the 'template'-parameter"""
|
"""Autocompletion for the 'template'-parameter"""
|
||||||
return self.client.database_caches.memes.get_autocomplete_suggestions(current)
|
return self.client.database_caches.memes.get_autocomplete_suggestions(current)
|
||||||
|
|
||||||
|
@app_commands.command()
|
||||||
|
@app_commands.describe(message="The text to convert.")
|
||||||
|
async def mock(self, interaction: discord.Interaction, message: str):
|
||||||
|
"""Mock a message.
|
||||||
|
|
||||||
|
This returns the mocked version ephemerally so that you can copy-paste it easily,
|
||||||
|
instead of the old version where Didier would send a public message.
|
||||||
|
|
||||||
|
The mocked message escapes all Markdown syntax.
|
||||||
|
"""
|
||||||
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
|
# Nitro users can send longer messages that Didier can't repeat back to them
|
||||||
|
if len(message) > constants.Limits.MESSAGE_LENGTH:
|
||||||
|
return await interaction.followup.send("That message is too long.")
|
||||||
|
|
||||||
|
message = discord.utils.escape_markdown(message)
|
||||||
|
|
||||||
|
# Escaping md syntax can make the message longer than the limit
|
||||||
|
if len(message) > constants.Limits.MESSAGE_LENGTH:
|
||||||
|
return await interaction.followup.send("Because of Markdown syntax escaping, that message is too long.")
|
||||||
|
|
||||||
|
return await interaction.followup.send(mock(message))
|
||||||
|
|
||||||
@commands.hybrid_command(name="xkcd")
|
@commands.hybrid_command(name="xkcd")
|
||||||
@app_commands.rename(comic_id="id")
|
@app_commands.rename(comic_id="id")
|
||||||
async def xkcd(self, ctx: commands.Context, comic_id: Optional[int] = None):
|
async def xkcd(self, ctx: commands.Context, comic_id: Optional[int] = None):
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import math
|
import math
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
__all__ = ["abbreviate", "leading", "pluralize", "re_find_all", "re_replace_with_list", "get_edu_year_name"]
|
__all__ = ["abbreviate", "leading", "mock", "pluralize", "re_find_all", "re_replace_with_list", "get_edu_year_name"]
|
||||||
|
|
||||||
|
|
||||||
def abbreviate(text: str, max_length: int) -> str:
|
def abbreviate(text: str, max_length: int) -> str:
|
||||||
|
|
@ -38,6 +39,28 @@ def leading(character: str, string: str, target_length: Optional[int] = 2) -> st
|
||||||
return (frequency * character) + string
|
return (frequency * character) + string
|
||||||
|
|
||||||
|
|
||||||
|
def mock(string: str) -> str:
|
||||||
|
"""Mock an input string
|
||||||
|
|
||||||
|
The result of this is comparable to the Mocking Spongebob memes
|
||||||
|
"""
|
||||||
|
replacements = {"a": "4", "b": "8", "e": "3", "i": "1", "o": "0", "s": "5"}
|
||||||
|
result_string = ""
|
||||||
|
|
||||||
|
for letter in string.lower():
|
||||||
|
# Letter should be mocked
|
||||||
|
if letter.isalpha() and random.random() < 0.5:
|
||||||
|
# Use replacement if it exists
|
||||||
|
if letter in replacements and random.random() < 0.5:
|
||||||
|
result_string += replacements[letter]
|
||||||
|
else:
|
||||||
|
result_string += letter.upper()
|
||||||
|
else:
|
||||||
|
result_string += letter
|
||||||
|
|
||||||
|
return result_string
|
||||||
|
|
||||||
|
|
||||||
def pluralize(word: str, amount: int, plural_form: Optional[str] = None) -> str:
|
def pluralize(word: str, amount: int, plural_form: Optional[str] = None) -> str:
|
||||||
"""Turn a word into plural"""
|
"""Turn a word into plural"""
|
||||||
if amount == 1:
|
if amount == 1:
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ def test_parse_dm_string_dm_garbage():
|
||||||
parse_dm_string("AC/DC")
|
parse_dm_string("AC/DC")
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time("2022-09-11")
|
||||||
def test_parse_dm_string_semantic():
|
def test_parse_dm_string_semantic():
|
||||||
"""Test parsing date strings in the [DAY] [MONTH] and [MONTH] [DAY] formats"""
|
"""Test parsing date strings in the [DAY] [MONTH] and [MONTH] [DAY] formats"""
|
||||||
result = parse_dm_string("23rd november")
|
result = parse_dm_string("23rd november")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue