2021-01-08 18:40:57 +00:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
2021-04-19 17:39:01 +00:00
|
|
|
import royalnet.engineer as engi
|
|
|
|
|
2022-03-06 16:48:16 +00:00
|
|
|
import royalpack.bolts as rb
|
|
|
|
|
2021-01-08 18:40:57 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2021-04-30 13:22:58 +00:00
|
|
|
@rb.capture_errors
|
2021-04-17 02:19:11 +00:00
|
|
|
@engi.TeleportingConversation
|
2021-04-19 03:26:20 +00:00
|
|
|
async def ship(*, _msg: engi.Message, first: str, second: str, **__):
|
2021-01-08 18:40:57 +00:00
|
|
|
"""
|
2021-04-18 14:29:59 +00:00
|
|
|
Shippa insieme due persone! 💞
|
2021-01-08 18:40:57 +00:00
|
|
|
"""
|
|
|
|
log.info(f"Shipping: {first!r} + {second!r}")
|
|
|
|
|
|
|
|
# Convert the names to lowercase
|
|
|
|
first = first.lower()
|
|
|
|
second = second.lower()
|
|
|
|
|
|
|
|
log.debug(f"Lowercased: {first!r} + {second!r}")
|
|
|
|
|
2021-04-18 14:18:12 +00:00
|
|
|
# Decide the number of groups to keep
|
|
|
|
first_groups = len(first) // 5
|
|
|
|
second_groups = len(second) // 5
|
|
|
|
|
|
|
|
log.debug(f"Keeping first:{first} second:{second} groups")
|
|
|
|
|
|
|
|
# Try to get a match
|
|
|
|
first_match = re.search(rf"^(?:[^aeiou]*[aeiou]){{,{first_groups}}}", first)
|
|
|
|
second_match = re.search(rf"(?:[^aeiou\s]*[aeiou]){{,{second_groups}}}[a-z]?$", second)
|
2021-01-08 18:40:57 +00:00
|
|
|
|
|
|
|
log.debug(f"Matches: {first_match!r} + {second_match!r}")
|
|
|
|
|
|
|
|
# Get the matched characters if the matches were successful, or cut the names in half if they weren't
|
2021-04-03 16:53:52 +00:00
|
|
|
first_crop = first_match.group(0) if first_match else first[:(len(first) // 2)]
|
|
|
|
second_crop = second_match.group(0) if second_match else second[(len(second) // 2):]
|
2021-01-08 18:40:57 +00:00
|
|
|
|
2021-04-03 16:53:52 +00:00
|
|
|
log.debug(f"Cropped: {first_crop!r} + {second_crop!r}")
|
2021-01-08 18:40:57 +00:00
|
|
|
|
|
|
|
# Combine the two parts
|
2021-04-03 16:53:52 +00:00
|
|
|
combined = f"{first_crop}{second_crop}"
|
2021-01-08 18:40:57 +00:00
|
|
|
|
|
|
|
log.info(f"Combined: {combined!r}")
|
|
|
|
|
|
|
|
# Send the message to the chat
|
|
|
|
log.debug(f"Sending ship to the chat...")
|
2021-04-03 16:43:34 +00:00
|
|
|
await _msg.reply(
|
2021-04-20 00:43:48 +00:00
|
|
|
text=f"💞 {first.capitalize()} + {second.capitalize()} = \uE01B{combined.capitalize()}\uE00B"
|
2021-01-08 18:40:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Objects exported by this module
|
|
|
|
__all__ = (
|
|
|
|
"ship",
|
|
|
|
)
|