forked from jeff502/Street-Fighter-6-Frame-Data-Discord-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_user_inputs.py
86 lines (72 loc) · 2.43 KB
/
handle_user_inputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import re
def character_aliases(user_character: str) -> str:
character_name_dict = {
"Ehonda": "E.Honda",
"Honda": "E.Honda",
"Chun": "Chun-Li",
"Chunli": "Chun-Li",
"Li": "Chun-Li",
"Dj": "Dee_Jay",
"Deejay": "Dee_Jay",
"Dhal": "Dhalsim",
"Sim": "Dhalsim",
"Jp": "JP",
"Gief": "Zangief",
"Zan": "Zangief",
"Kim": "Kimberly"
}
if user_character in character_name_dict:
return character_name_dict[user_character]
return user_character
def replace_input(input_string: str) -> str:
replacements = {
"QCF": "236",
"QCB": "214",
"HCF": "41236",
"HCB": "63214",
"DP": "623",
"BDP": "412",
"DU": "28",
"BF": "46",
"63214789": "360",
"6321478963214789": "720",
"BFBF": "4646",
"JAB": "LP",
"AB": "LP",
"STRONG": "MP",
"FIERCE": "HP",
"SHORT": "LK",
"FORWARD": "MK",
"ROUNDHOUSE": "HK",
"KICKS": "KKK",
"PUNCHES": "PPP",
"ALL": "PPPKKKK",
"TAUNT": "PPPKKKK",
"THROW": "LPLK"
}
# Ignore the leading 'J' if present
if input_string.count("J") > 1:
input_string = input_string.lstrip('J')
j = "J"
else:
j = ""
# Remove '5'
input_string = "".join(letter for letter in input_string if letter != "5")
# Sort the keys in descending order of length
sorted_keys = sorted(replacements.keys(), key=len, reverse=True)
# Find and replace the keys with their values
pattern = re.compile('|'.join(re.escape(key) for key in sorted_keys))
result = pattern.sub(lambda x: replacements[x.group()], input_string)
return j + result
def rearrange_input(input_string: str) -> str:
# Match the 'j' in the string
j_match = re.search(r'J', input_string)
j = j_match.group() if j_match else ''
# Remove 'j' from the input string
processed_string = input_string.replace('J', '')
# Extract the numbers and letters using regex
numbers_match = re.findall(r'\d+', processed_string)
letters_match = re.findall(r'[A-Za-z]+', processed_string)
# Concatenate the 'j', numbers, and letters in the desired order
rearranged_string = j + ''.join(numbers_match) + ''.join(letters_match)
return rearranged_string