Skip to content

Commit

Permalink
- no tests just winging it
Browse files Browse the repository at this point in the history
  • Loading branch information
athphane committed Jun 3, 2024
1 parent efbee96 commit caa8c47
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions userbot/plugins/morse_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import asyncio

from pyrogram import filters
from pyrogram.types import Message

from userbot import UserBot
from userbot.helpers.constants import First
from userbot.plugins.help import add_command_help

# Dictionary representing the morse code chart
MORSE_CODE_DICT = {'A': '.-', 'B': '-...',
'C': '-.-.', 'D': '-..', 'E': '.',
'F': '..-.', 'G': '--.', 'H': '....',
'I': '..', 'J': '.---', 'K': '-.-',
'L': '.-..', 'M': '--', 'N': '-.',
'O': '---', 'P': '.--.', 'Q': '--.-',
'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--',
'X': '-..-', 'Y': '-.--', 'Z': '--..',
'1': '.----', '2': '..---', '3': '...--',
'4': '....-', '5': '.....', '6': '-....',
'7': '--...', '8': '---..', '9': '----.',
'0': '-----', ', ': '--..--', '.': '.-.-.-',
'?': '..--..', '/': '-..-.', '-': '-....-',
'(': '-.--.', ')': '-.--.-'}


@UserBot.on_message(filters.command("morse", ".") & filters.me)
async def morse_encrypt(bot: UserBot, message: Message):
cmd = message.command

def encrypt(input_string):
cipher = ''
for letter in input_string:
if letter != ' ':
cipher += MORSE_CODE_DICT[letter] + ' '
else:
cipher += ' '

return cipher

main_text = ""
if len(cmd) > 1:
main_text = " ".join(cmd[1:])
elif message.reply_to_message and len(cmd) == 1:
main_text = message.reply_to_message.text
elif not message.reply_to_message and len(cmd) == 1:
await message.edit("I need something to encrypt")
await asyncio.sleep(2)
await message.delete()
return

input_str = main_text
if not input_str:
await message.edit("`give me something to encrypt`")
return

await message.edit(encrypt(input_str))


@UserBot.on_message(filters.command("morsed", ".") & filters.me)
async def morse_decrypt(bot: UserBot, message: Message):
cmd = message.command

def decrypt(input_string):
input_string += ' '
decipher = ''
citext = ''
for letter in input_string:
if letter != ' ':
i = 0
citext += letter
else:
i += 1
if i == 2:
decipher += ' '
else:
decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT.values()).index(citext)]
citext = ''

return decipher

main_text = ""
if len(cmd) > 1:
main_text = " ".join(cmd[1:])
elif message.reply_to_message and len(cmd) == 1:
main_text = message.reply_to_message.text
elif not message.reply_to_message and len(cmd) == 1:
await message.edit("I need something to decrypt")
await asyncio.sleep(2)
await message.delete()
return

input_str = main_text
if not input_str:
await message.edit("`give me something to decrypt`")
return

await message.edit(decrypt(input_str))


# Command help section
add_command_help(
"morse",
[
[".morse", "Encrypt the input text into morse code"],
[".morsed", "Decrypt morse code to plain text"],
],
)

0 comments on commit caa8c47

Please sign in to comment.