Compare commits

...

8 Commits

Author SHA1 Message Date
Stijn De Clercq ad0076537d
Merge pull request #160 from stijndcl/fix-ci
Fix CI
2023-01-11 23:43:28 +01:00
stijndcl ff5de8e88b Update CI & fix broken test 2023-01-11 23:37:39 +01:00
stijndcl d7daeb02ff Forgot some 2023-01-11 23:30:49 +01:00
stijndcl a05d8e7138 Fix CI 2023-01-11 23:27:09 +01:00
Stijn De Clercq 5bfb1cecb2
Merge pull request #159 from stijndcl/3.3.0
3.3.0
2023-01-11 23:18:08 +01:00
Stijn De Clercq 3d429f21cc
Merge pull request #156 from stijndcl/mock
Re-write Mock
2022-11-21 22:52:43 +01:00
stijndcl 6c8ab9a2a0 Check escaped message length before mocking it 2022-11-21 22:49:23 +01:00
stijndcl accda93461 Add Mock back in 2022-11-21 22:46:19 +01:00
4 changed files with 65 additions and 16 deletions

View File

@ -5,15 +5,15 @@ on:
jobs:
dependencies:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9.5'
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
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
tests:
needs: [dependencies]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
services:
postgres:
image: postgres:14
@ -41,11 +41,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9.5'
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
@ -63,15 +63,15 @@ jobs:
token: ${{ secrets.CODECOV }}
linting:
needs: [tests]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9.5'
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
@ -83,15 +83,15 @@ jobs:
run: flake8
typing:
needs: [tests]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9.5'
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}
@ -103,15 +103,15 @@ jobs:
run: mypy
formatting:
needs: [tests]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.9.5'
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt') }}

View File

@ -13,6 +13,7 @@ from didier.data.apis.xkcd import fetch_xkcd_post
from didier.exceptions.no_match import expect
from didier.menus.memes import MemeSource
from didier.utils.discord import constants
from didier.utils.types.string import mock
from didier.views.modals import GenerateMeme
@ -133,6 +134,30 @@ class Fun(commands.Cog):
"""Autocompletion for the 'template'-parameter"""
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")
@app_commands.rename(comic_id="id")
async def xkcd(self, ctx: commands.Context, comic_id: Optional[int] = None):

View File

@ -1,8 +1,9 @@
import math
import random
import re
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:
@ -38,6 +39,28 @@ def leading(character: str, string: str, target_length: Optional[int] = 2) -> st
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:
"""Turn a word into plural"""
if amount == 1:

View File

@ -28,6 +28,7 @@ def test_parse_dm_string_dm_garbage():
parse_dm_string("AC/DC")
@freeze_time("2022-09-11")
def test_parse_dm_string_semantic():
"""Test parsing date strings in the [DAY] [MONTH] and [MONTH] [DAY] formats"""
result = parse_dm_string("23rd november")