Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 79d01e9

Browse files
authored
refactor: rename howsign package to handshapes; remove the URL formatting functions (#4)
1 parent 34d56ee commit 79d01e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+97
-109
lines changed

bot.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import asyncio
2+
import base64
23
import datetime as dt
3-
import logging
44
import difflib
5+
import logging
56
import random
6-
from contextlib import suppress
77
import re
88
import uuid
9-
import base64
9+
from contextlib import suppress
1010
from typing import Optional
11+
from urllib.parse import quote_plus
1112

1213
import aiohttp
1314
import discord
15+
import gspread
1416
from discord.ext import commands
1517
from discord.ext.commands import Context
1618
from environs import Env
1719
from google.auth.crypt._python_rsa import RSASigner
1820
from google.oauth2.service_account import Credentials
19-
import gspread
2021

21-
import howsign
22+
import handshapes
2223
import cuteid
2324
import catchphrase
2425

@@ -137,13 +138,14 @@ def howsign_impl(word: str):
137138
else f"sending links for: '{word}'"
138139
)
139140
logger.info(log)
141+
quoted_word = quote_plus(word)
140142
return {
141143
"content": template.format(
142144
word_uppercased=word.upper(),
143-
lifeprint=howsign.get_lifeprint_url(word),
144-
signingsavvy=howsign.get_signingsavvy_url(word),
145-
spread_the_sign=howsign.get_spread_the_sign_url(word),
146-
youglish=howsign.get_youglish_url(word),
145+
lifeprint=f"https://www.google.com/search?&q=site%3Alifeprint.com+{quoted_word}",
146+
signingsavvy=f"https://www.signingsavvy.com/search/{quoted_word}",
147+
spread_the_sign=f"https://www.spreadthesign.com/en.us/search/?q={quoted_word}",
148+
youglish=f"https://youglish.com/pronounce/{quoted_word}/signlanguage/asl",
147149
)
148150
}
149151

@@ -157,7 +159,9 @@ async def howsign_command(ctx: Context, *, word: str):
157159
async def howsign_error(ctx, error):
158160
if isinstance(error, commands.errors.MissingRequiredArgument):
159161
logger.info(f"missing argument to '{ctx.invoked_with}'")
160-
await ctx.send(f"Enter a word or phrase after `{COMMAND_PREFIX}howsign`")
162+
await ctx.send(
163+
f"Enter a word or phrase after `{COMMAND_PREFIX}{ctx.invoked_with}`"
164+
)
161165
else:
162166
logger.error(
163167
f"unexpected error when handling '{ctx.invoked_with}'", exc_info=error
@@ -182,14 +186,14 @@ async def howsign_error(ctx, error):
182186
def handshape_impl(name: str):
183187
logger.info(f"handshape: '{name}'")
184188
if name == "random":
185-
name = random.choice(tuple(howsign.HANDSHAPES.keys()))
189+
name = random.choice(tuple(handshapes.HANDSHAPES.keys()))
186190
logger.info(f"chose '{name}'")
187191

188192
try:
189-
handshape = howsign.get_handshape(name)
190-
except howsign.HandshapeNotFoundError:
193+
handshape = handshapes.get_handshape(name)
194+
except handshapes.HandshapeNotFoundError:
191195
logger.info(f"handshape '{name}' not found")
192-
suggestion = did_you_mean(name, tuple(howsign.HANDSHAPES.keys()))
196+
suggestion = did_you_mean(name, tuple(handshapes.HANDSHAPES.keys()))
193197
if suggestion:
194198
return {
195199
"content": f'"{name}" not found. Did you mean "{suggestion}"? Enter `{COMMAND_PREFIX}handshapes` to see a list of handshapes.'
@@ -230,7 +234,8 @@ async def handshape_command(ctx, name="random"):
230234
def handshapes_impl():
231235
return {
232236
"content": HANDSHAPES_TEMPLATE.format(
233-
handshapes=", ".join(howsign.HANDSHAPES.keys()), COMMAND_PREFIX=COMMAND_PREFIX
237+
handshapes=", ".join(handshapes.HANDSHAPES.keys()),
238+
COMMAND_PREFIX=COMMAND_PREFIX,
234239
)
235240
}
236241

lib/handshapes/__init__.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from dataclasses import dataclass
2+
from pathlib import Path
3+
4+
from .case_insensitive_dict import CaseInsensitiveDict
5+
6+
ASSETS_PATH = Path(__file__).parent / "assets"
7+
HANDSHAPES = CaseInsensitiveDict(
8+
{
9+
"1": ASSETS_PATH / "1.png",
10+
"3": ASSETS_PATH / "3.png",
11+
"Bent3": ASSETS_PATH / "Bent3.png",
12+
"4": ASSETS_PATH / "4.png",
13+
"5": ASSETS_PATH / "5.png",
14+
"Claw5": ASSETS_PATH / "Claw5.png",
15+
"6": ASSETS_PATH / "6.png",
16+
"7": ASSETS_PATH / "7.png",
17+
"8": ASSETS_PATH / "8.png",
18+
"Open8": ASSETS_PATH / "Open8.png",
19+
"9": ASSETS_PATH / "9.png",
20+
"Flat9": ASSETS_PATH / "Flat9.png",
21+
"A": ASSETS_PATH / "A.png",
22+
"OpenA": ASSETS_PATH / "OpenA.png",
23+
"B": ASSETS_PATH / "B.png",
24+
"BentB": ASSETS_PATH / "BentB.png",
25+
"FlatB": ASSETS_PATH / "FlatB.png",
26+
"OpenB": ASSETS_PATH / "OpenB.png",
27+
"C": ASSETS_PATH / "C.png",
28+
"FlatC": ASSETS_PATH / "FlatC.png",
29+
"SmallC": ASSETS_PATH / "SmallC.png",
30+
"D": ASSETS_PATH / "D.png",
31+
"E": ASSETS_PATH / "E.png",
32+
"G": ASSETS_PATH / "G.png",
33+
"H": ASSETS_PATH / "H.png",
34+
"I": ASSETS_PATH / "I.png",
35+
"K": ASSETS_PATH / "K.png",
36+
"L": ASSETS_PATH / "L.png",
37+
"M": ASSETS_PATH / "M.png",
38+
"OpenM": ASSETS_PATH / "OpenM.png",
39+
"N": ASSETS_PATH / "N.png",
40+
"OpenN": ASSETS_PATH / "OpenN.png",
41+
"O": ASSETS_PATH / "O.png",
42+
"FlatO": ASSETS_PATH / "FlatO.png",
43+
"SmallO": ASSETS_PATH / "SmallO.png",
44+
"R": ASSETS_PATH / "R.png",
45+
"S": ASSETS_PATH / "S.png",
46+
"T": ASSETS_PATH / "T.png",
47+
"V": ASSETS_PATH / "V.png",
48+
"BentV": ASSETS_PATH / "BentV.png",
49+
"X": ASSETS_PATH / "X.png",
50+
"OpenX": ASSETS_PATH / "OpenX.png",
51+
"Y": ASSETS_PATH / "Y.png",
52+
"ILY": ASSETS_PATH / "ILY.png",
53+
"Corna": ASSETS_PATH / "Corna.png",
54+
}
55+
)
56+
57+
58+
@dataclass
59+
class Handshape:
60+
name: str
61+
path: Path
62+
63+
64+
class HandshapeNotFoundError(KeyError):
65+
pass
66+
67+
68+
def get_handshape(name):
69+
try:
70+
cased_name = HANDSHAPES._store[name.lower()][0]
71+
path = HANDSHAPES[name]
72+
except KeyError as error:
73+
raise HandshapeNotFoundError(
74+
f"Could not find handshape with name '{name}'"
75+
) from error
76+
return Handshape(name=cased_name, path=path)

0 commit comments

Comments
 (0)