16
16
import discord
17
17
from discord .enums import ActivityType , Status
18
18
from discord .ext import commands , tasks
19
+ from discord .ext .commands .view import StringView
19
20
from discord .utils import escape_markdown , escape_mentions
20
21
21
22
from aiohttp import ClientResponseError
@@ -1002,6 +1003,7 @@ async def alias_add(self, ctx, name: str.lower, *, value):
1002
1003
return await ctx .send (embed = embed )
1003
1004
1004
1005
values = utils .parse_alias (value )
1006
+ save_aliases = []
1005
1007
1006
1008
if not values :
1007
1009
embed = discord .Embed (
@@ -1012,59 +1014,45 @@ async def alias_add(self, ctx, name: str.lower, *, value):
1012
1014
embed .set_footer (text = f'See "{ self .bot .prefix } alias add" for more details.' )
1013
1015
return await ctx .send (embed = embed )
1014
1016
1015
- if len (values ) == 1 :
1016
- linked_command , * messages = values [0 ].split (maxsplit = 1 )
1017
+ multiple_alias = len (values ) > 1
1018
+
1019
+ embed = discord .Embed (
1020
+ title = "Added alias" ,
1021
+ color = self .bot .main_color
1022
+ )
1023
+
1024
+ if multiple_alias :
1025
+ embed .description = f'`{ name } ` points to: "{ values [0 ]} ".'
1026
+ else :
1027
+ embed .description = f"`{ name } ` now points to the following steps:"
1028
+
1029
+ for i , val in enumerate (values , start = 1 ):
1030
+ view = StringView (val )
1031
+ linked_command = view .get_word ()
1032
+ message = view .read_rest ()
1033
+
1017
1034
if not self .bot .get_command (linked_command ):
1018
1035
alias_command = self .bot .aliases .get (linked_command )
1019
1036
if alias_command is not None :
1020
- if messages :
1021
- values = [f"{ alias_command } { messages [0 ]} " ]
1022
- else :
1023
- values = [alias_command ]
1037
+ save_aliases .append (f"{ alias_command } { message } " .strip ())
1024
1038
else :
1025
- embed = discord .Embed (
1026
- title = "Error" ,
1027
- color = self .bot .error_color ,
1028
- description = "The command you are attempting to point "
1029
- f"to does not exist: `{ linked_command } `." ,
1030
- )
1031
- return await ctx .send (embed = embed )
1039
+ embed = discord .Embed (title = "Error" , color = self .bot .error_color )
1032
1040
1033
- embed = discord .Embed (
1034
- title = "Added alias" ,
1035
- color = self .bot .main_color ,
1036
- description = f'`{ name } ` points to: "{ values [0 ]} ".' ,
1037
- )
1041
+ if multiple_alias :
1042
+ embed .description = ("The command you are attempting to point "
1043
+ f"to does not exist: `{ linked_command } `." )
1044
+ else :
1045
+ embed .description = ("The command you are attempting to point "
1046
+ f"to n step { i } does not exist: `{ linked_command } `." )
1038
1047
1039
- else :
1040
- embed = discord .Embed (
1041
- title = "Added alias" ,
1042
- color = self .bot .main_color ,
1043
- description = f"`{ name } ` now points to the following steps:" ,
1044
- )
1048
+ return await ctx .send (embed = embed )
1049
+ else :
1050
+ save_aliases .append (val )
1045
1051
1046
- for i , val in enumerate (values , start = 1 ):
1047
- linked_command , * messages = val .split (maxsplit = 1 )
1048
- if not self .bot .get_command (linked_command ):
1049
- alias_command = self .bot .aliases .get (linked_command )
1050
- if alias_command is not None :
1051
- if messages :
1052
- values = [f"{ alias_command } { messages [0 ]} " ]
1053
- else :
1054
- values = [alias_command ]
1055
- else :
1056
- embed = discord .Embed (
1057
- title = "Error" ,
1058
- color = self .bot .error_color ,
1059
- description = "The command you are attempting to point "
1060
- f"to n step { i } does not exist: `{ linked_command } `." ,
1061
- )
1062
- return await ctx .send (embed = embed )
1063
- embed .description += f"\n { i } : { val } "
1052
+ embed .description += f"\n { i } : { val } "
1064
1053
1065
- self .bot .aliases [name ] = " && " .join (values )
1054
+ self .bot .aliases [name ] = " && " .join (f" \" { a } \" " for a in save_aliases )
1066
1055
await self .bot .config .update ()
1067
-
1068
1056
return await ctx .send (embed = embed )
1069
1057
1070
1058
@alias .command (name = "remove" , aliases = ["del" , "delete" ])
@@ -1097,6 +1085,7 @@ async def alias_edit(self, ctx, name: str.lower, *, value):
1097
1085
return await ctx .send (embed = embed )
1098
1086
1099
1087
values = utils .parse_alias (value )
1088
+ save_aliases = []
1100
1089
1101
1090
if not values :
1102
1091
embed = discord .Embed (
@@ -1107,56 +1096,44 @@ async def alias_edit(self, ctx, name: str.lower, *, value):
1107
1096
embed .set_footer (text = f'See "{ self .bot .prefix } alias add" for more details.' )
1108
1097
return await ctx .send (embed = embed )
1109
1098
1110
- if len (values ) == 1 :
1111
- linked_command , * messages = values [0 ].split (maxsplit = 1 )
1099
+ multiple_alias = len (values ) > 1
1100
+
1101
+ embed = discord .Embed (
1102
+ title = "Edited alias" ,
1103
+ color = self .bot .main_color
1104
+ )
1105
+
1106
+ if multiple_alias :
1107
+ embed .description = f'`{ name } ` points to: "{ values [0 ]} ".'
1108
+ else :
1109
+ embed .description = f"`{ name } ` now points to the following steps:"
1110
+
1111
+ for i , val in enumerate (values , start = 1 ):
1112
+ view = StringView (val )
1113
+ linked_command = view .get_word ()
1114
+ message = view .read_rest ()
1115
+
1112
1116
if not self .bot .get_command (linked_command ):
1113
1117
alias_command = self .bot .aliases .get (linked_command )
1114
1118
if alias_command is not None :
1115
- if messages :
1116
- values = [f"{ alias_command } { messages [0 ]} " ]
1117
- else :
1118
- values = [alias_command ]
1119
+ save_aliases .append (f"{ alias_command } { message } " .strip ())
1119
1120
else :
1120
- embed = discord .Embed (
1121
- title = "Error" ,
1122
- color = self .bot .error_color ,
1123
- description = "The command you are attempting to point "
1124
- f"to does not exist: `{ linked_command } `." ,
1125
- )
1126
- return await ctx .send (embed = embed )
1127
- embed = discord .Embed (
1128
- title = "Edited alias" ,
1129
- color = self .bot .main_color ,
1130
- description = f'`{ name } ` now points to: "{ values [0 ]} ".' ,
1131
- )
1121
+ embed = discord .Embed (title = "Error" , color = self .bot .error_color )
1132
1122
1133
- else :
1134
- embed = discord .Embed (
1135
- title = "Edited alias" ,
1136
- color = self .bot .main_color ,
1137
- description = f"`{ name } ` now points to the following steps:" ,
1138
- )
1139
-
1140
- for i , val in enumerate (values , start = 1 ):
1141
- linked_command , * messages = val .split (maxsplit = 1 )
1142
- if not self .bot .get_command (linked_command ):
1143
- alias_command = self .bot .aliases .get (linked_command )
1144
- if alias_command is not None :
1145
- if messages :
1146
- values = [f"{ alias_command } { messages [0 ]} " ]
1147
- else :
1148
- values = [alias_command ]
1123
+ if multiple_alias :
1124
+ embed .description = ("The command you are attempting to point "
1125
+ f"to does not exist: `{ linked_command } `." )
1149
1126
else :
1150
- embed = discord . Embed (
1151
- title = "Error" ,
1152
- color = self . bot . error_color ,
1153
- description = "The command you are attempting to point "
1154
- f"to on step { i } does not exist: ` { linked_command } `." ,
1155
- )
1156
- return await ctx . send ( embed = embed )
1157
- embed .description += f"\n { i } : { val } "
1127
+ embed . description = ( "The command you are attempting to point "
1128
+ f"to n step { i } does not exist: ` { linked_command } `." )
1129
+
1130
+ return await ctx . send ( embed = embed )
1131
+ else :
1132
+ save_aliases . append ( val )
1133
+
1134
+ embed .description += f"\n { i } : { val } "
1158
1135
1159
- self .bot .aliases [name ] = "&& " .join (values )
1136
+ self .bot .aliases [name ] = " && " .join (f" \" { a } \" " for a in save_aliases )
1160
1137
await self .bot .config .update ()
1161
1138
return await ctx .send (embed = embed )
1162
1139
0 commit comments