17
17
from discord .enums import ActivityType , Status
18
18
from discord .ext import commands , tasks
19
19
from discord .ext .commands .view import StringView
20
- from discord .utils import escape_markdown , escape_mentions
21
20
22
21
from aiohttp import ClientResponseError
23
22
from pkg_resources import parse_version
@@ -161,28 +160,41 @@ async def send_error_message(self, error):
161
160
command = self .context .kwargs .get ("command" )
162
161
val = self .context .bot .snippets .get (command )
163
162
if val is not None :
164
- return await self . get_destination (). send (
165
- escape_mentions ( f"**` { command } ` is a snippet, content:** \n \n { val } " )
163
+ embed = discord . Embed (
164
+ title = f" { command } is a snippet." , color = self . context . bot . main_color
166
165
)
166
+ embed .add_field (name = f"`{ command } ` will send:" , value = val )
167
+ return await self .get_destination ().send (embed = embed )
167
168
168
169
val = self .context .bot .aliases .get (command )
169
170
if val is not None :
170
171
values = utils .parse_alias (val )
171
172
172
- if len ( values ) == 1 :
173
+ if not values :
173
174
embed = discord .Embed (
174
- title = f"{ command } is an alias." ,
175
- color = self .context .bot .main_color ,
176
- description = f"`{ command } ` points to `{ escape_markdown (values [0 ])} `." ,
175
+ title = "Error" ,
176
+ color = self .context .bot .error_color ,
177
+ description = f"Alias `{ command } ` is invalid, this alias will now be deleted."
178
+ "This alias will now be deleted." ,
177
179
)
180
+ embed .add_field (name = f"{ command } ` used to be:" , value = val )
181
+ self .context .bot .aliases .pop (command )
182
+ await self .context .bot .config .update ()
178
183
else :
179
- embed = discord .Embed (
180
- title = f"{ command } is an alias." ,
181
- color = self .context .bot .main_color ,
182
- description = f"**`{ command } ` points to the following steps:**" ,
183
- )
184
- for i , val in enumerate (values , start = 1 ):
185
- embed .description += f"\n { i } : { escape_markdown (val )} "
184
+ if len (values ) == 1 :
185
+ embed = discord .Embed (
186
+ title = f"{ command } is an alias." , color = self .context .bot .main_color
187
+ )
188
+ embed .add_field (name = f"`{ command } ` points to:" , value = values [0 ])
189
+ else :
190
+ embed = discord .Embed (
191
+ title = f"{ command } is an alias." ,
192
+ color = self .context .bot .main_color ,
193
+ description = f"**`{ command } ` points to the following steps:**" ,
194
+ )
195
+ for i , val in enumerate (values , start = 1 ):
196
+ embed .add_field (name = f"Step { i } :" , value = val )
197
+
186
198
embed .set_footer (
187
199
text = f'Type "{ self .clean_prefix } { self .command_attrs ["name" ]} alias" '
188
200
"for more details on aliases."
@@ -901,33 +913,32 @@ async def alias(self, ctx, *, name: str.lower = None):
901
913
embed = discord .Embed (
902
914
title = "Error" ,
903
915
color = self .bot .error_color ,
904
- description = f"Alias `{ name } ` is invalid, it used to be ` { escape_markdown ( val ) } `. "
916
+ description = f"Alias `{ name } ` is invalid, this alias will now be deleted. "
905
917
"This alias will now be deleted." ,
906
918
)
919
+ embed .add_field (name = f"{ name } ` used to be:" , value = val )
907
920
self .bot .aliases .pop (name )
908
921
await self .bot .config .update ()
909
922
return await ctx .send (embed = embed )
910
923
911
924
if len (values ) == 1 :
912
- embed = discord .Embed (
913
- color = self .bot .main_color ,
914
- description = f"`{ name } ` points to `{ escape_markdown (values [0 ])} `." ,
915
- )
925
+ embed = discord .Embed (color = self .bot .main_color )
926
+ embed .add_field (name = f"`{ name } ` points to:" , value = values [0 ])
916
927
else :
917
928
embed = discord .Embed (
918
929
color = self .bot .main_color ,
919
930
description = f"**`{ name } ` points to the following steps:**" ,
920
931
)
921
932
for i , val in enumerate (values , start = 1 ):
922
- embed .description += f" \n { i } : { escape_markdown ( val )} "
933
+ embed .add_field ( name = f"Step { i } :" , value = val )
923
934
924
935
return await ctx .send (embed = embed )
925
936
926
937
if not self .bot .aliases :
927
938
embed = discord .Embed (
928
939
color = self .bot .error_color , description = "You dont have any aliases at the moment."
929
940
)
930
- embed .set_footer (text = f" Do { self .bot .prefix } help alias for more commands." )
941
+ embed .set_footer (text = f' Do " { self .bot .prefix } help alias" for more commands.' )
931
942
embed .set_author (name = "Aliases" , icon_url = ctx .guild .icon_url )
932
943
return await ctx .send (embed = embed )
933
944
@@ -952,56 +963,13 @@ async def alias_raw(self, ctx, *, name: str.lower):
952
963
if val is None :
953
964
embed = utils .create_not_found_embed (name , self .bot .aliases .keys (), "Alias" )
954
965
return await ctx .send (embed = embed )
955
- return await ctx .send (escape_markdown (escape_mentions (val )).replace ("<" , "\\ <" ))
956
-
957
- @alias .command (name = "add" )
958
- @checks .has_permissions (PermissionLevel .MODERATOR )
959
- async def alias_add (self , ctx , name : str .lower , * , value ):
960
- """
961
- Add an alias.
962
-
963
- Alias also supports multi-step aliases, to create a multi-step alias use quotes
964
- to wrap each step and separate each step with `&&`. For example:
965
-
966
- - `{prefix}alias add movenreply "move admin-category" && "reply Thanks for reaching out to the admins"`
967
-
968
- However, if you run into problems, try wrapping the command with quotes. For example:
969
-
970
- - This will fail: `{prefix}alias add reply You'll need to type && to work`
971
- - Correct method: `{prefix}alias add reply "You'll need to type && to work"`
972
- """
973
- embed = None
974
- if self .bot .get_command (name ):
975
- embed = discord .Embed (
976
- title = "Error" ,
977
- color = self .bot .error_color ,
978
- description = f"A command with the same name already exists: `{ name } `." ,
979
- )
980
966
981
- elif name in self .bot .aliases :
982
- embed = discord .Embed (
983
- title = "Error" ,
984
- color = self .bot .error_color ,
985
- description = f"Another alias with the same name already exists: `{ name } `." ,
986
- )
987
-
988
- elif name in self .bot .snippets :
989
- embed = discord .Embed (
990
- title = "Error" ,
991
- color = self .bot .error_color ,
992
- description = f"A snippet with the same name already exists: `{ name } `." ,
993
- )
994
-
995
- elif len (name ) > 120 :
996
- embed = discord .Embed (
997
- title = "Error" ,
998
- color = self .bot .error_color ,
999
- description = "Alias names cannot be longer than 120 characters." ,
1000
- )
1001
-
1002
- if embed is not None :
1003
- return await ctx .send (embed = embed )
967
+ embed = discord .Embed (color = self .bot .main_color )
968
+ val = utils .escape_code_block (val )
969
+ embed .add_field (name = f"`{ name } ` points to:" , value = f"```\n { val } ```" )
970
+ return await ctx .send (embed = embed )
1004
971
972
+ async def make_alias (self , name , value , action ):
1005
973
values = utils .parse_alias (value )
1006
974
save_aliases = []
1007
975
@@ -1012,14 +980,14 @@ async def alias_add(self, ctx, name: str.lower, *, value):
1012
980
description = "Invalid multi-step alias, try wrapping each steps in quotes." ,
1013
981
)
1014
982
embed .set_footer (text = f'See "{ self .bot .prefix } alias add" for more details.' )
1015
- return await ctx . send ( embed = embed )
983
+ return embed
1016
984
1017
985
multiple_alias = len (values ) > 1
1018
986
1019
- embed = discord .Embed (title = "Added alias" , color = self .bot .main_color )
987
+ embed = discord .Embed (title = f" { action } alias" , color = self .bot .main_color )
1020
988
1021
989
if not multiple_alias :
1022
- embed .description = f' `{ name } ` points to: " { values [0 ]} ".'
990
+ embed .add_field ( name = f" `{ name } ` points to:" , value = values [0 ])
1023
991
else :
1024
992
embed .description = f"`{ name } ` now points to the following steps:"
1025
993
@@ -1043,17 +1011,66 @@ async def alias_add(self, ctx, name: str.lower, *, value):
1043
1011
else :
1044
1012
embed .description = (
1045
1013
"The command you are attempting to point "
1046
- f"to in step { i } does not exist: `{ linked_command } `."
1014
+ f"to on step { i } does not exist: `{ linked_command } `."
1047
1015
)
1048
1016
1049
- return await ctx . send ( embed = embed )
1017
+ return embed
1050
1018
else :
1051
1019
save_aliases .append (val )
1052
-
1053
- embed .description += f" \n { i } : { val } "
1020
+ if multiple_alias :
1021
+ embed .add_field ( name = f"Step { i } :" , value = val )
1054
1022
1055
1023
self .bot .aliases [name ] = " && " .join (f'"{ a } "' for a in save_aliases )
1056
1024
await self .bot .config .update ()
1025
+ return embed
1026
+
1027
+ @alias .command (name = "add" )
1028
+ @checks .has_permissions (PermissionLevel .MODERATOR )
1029
+ async def alias_add (self , ctx , name : str .lower , * , value ):
1030
+ """
1031
+ Add an alias.
1032
+
1033
+ Alias also supports multi-step aliases, to create a multi-step alias use quotes
1034
+ to wrap each step and separate each step with `&&`. For example:
1035
+
1036
+ - `{prefix}alias add movenreply "move admin-category" && "reply Thanks for reaching out to the admins"`
1037
+
1038
+ However, if you run into problems, try wrapping the command with quotes. For example:
1039
+
1040
+ - This will fail: `{prefix}alias add reply You'll need to type && to work`
1041
+ - Correct method: `{prefix}alias add reply "You'll need to type && to work"`
1042
+ """
1043
+ embed = None
1044
+ if self .bot .get_command (name ):
1045
+ embed = discord .Embed (
1046
+ title = "Error" ,
1047
+ color = self .bot .error_color ,
1048
+ description = f"A command with the same name already exists: `{ name } `." ,
1049
+ )
1050
+
1051
+ elif name in self .bot .aliases :
1052
+ embed = discord .Embed (
1053
+ title = "Error" ,
1054
+ color = self .bot .error_color ,
1055
+ description = f"Another alias with the same name already exists: `{ name } `." ,
1056
+ )
1057
+
1058
+ elif name in self .bot .snippets :
1059
+ embed = discord .Embed (
1060
+ title = "Error" ,
1061
+ color = self .bot .error_color ,
1062
+ description = f"A snippet with the same name already exists: `{ name } `." ,
1063
+ )
1064
+
1065
+ elif len (name ) > 120 :
1066
+ embed = discord .Embed (
1067
+ title = "Error" ,
1068
+ color = self .bot .error_color ,
1069
+ description = "Alias names cannot be longer than 120 characters." ,
1070
+ )
1071
+
1072
+ if embed is None :
1073
+ embed = await self .make_alias (name , value , "Added" )
1057
1074
return await ctx .send (embed = embed )
1058
1075
1059
1076
@alias .command (name = "remove" , aliases = ["del" , "delete" ])
@@ -1085,58 +1102,7 @@ async def alias_edit(self, ctx, name: str.lower, *, value):
1085
1102
embed = utils .create_not_found_embed (name , self .bot .aliases .keys (), "Alias" )
1086
1103
return await ctx .send (embed = embed )
1087
1104
1088
- values = utils .parse_alias (value )
1089
- save_aliases = []
1090
-
1091
- if not values :
1092
- embed = discord .Embed (
1093
- title = "Error" ,
1094
- color = self .bot .error_color ,
1095
- description = "Invalid multi-step alias, try wrapping each steps in quotes." ,
1096
- )
1097
- embed .set_footer (text = f'See "{ self .bot .prefix } alias add" for more details.' )
1098
- return await ctx .send (embed = embed )
1099
-
1100
- multiple_alias = len (values ) > 1
1101
-
1102
- embed = discord .Embed (title = "Edited alias" , color = self .bot .main_color )
1103
-
1104
- if not multiple_alias :
1105
- embed .description = f'`{ name } ` points to: "{ values [0 ]} ".'
1106
- else :
1107
- embed .description = f"`{ name } ` now points to the following steps:"
1108
-
1109
- for i , val in enumerate (values , start = 1 ):
1110
- view = StringView (val )
1111
- linked_command = view .get_word ().lower ()
1112
- message = view .read_rest ()
1113
-
1114
- if not self .bot .get_command (linked_command ):
1115
- alias_command = self .bot .aliases .get (linked_command )
1116
- if alias_command is not None :
1117
- save_aliases .extend (utils .normalize_alias (alias_command , message ))
1118
- else :
1119
- embed = discord .Embed (title = "Error" , color = self .bot .error_color )
1120
-
1121
- if multiple_alias :
1122
- embed .description = (
1123
- "The command you are attempting to point "
1124
- f"to does not exist: `{ linked_command } `."
1125
- )
1126
- else :
1127
- embed .description = (
1128
- "The command you are attempting to point "
1129
- f"to n step { i } does not exist: `{ linked_command } `."
1130
- )
1131
-
1132
- return await ctx .send (embed = embed )
1133
- else :
1134
- save_aliases .append (val )
1135
-
1136
- embed .description += f"\n { i } : { val } "
1137
-
1138
- self .bot .aliases [name ] = " && " .join (f'"{ a } "' for a in save_aliases )
1139
- await self .bot .config .update ()
1105
+ embed = await self .make_alias (name , value , "Edited" )
1140
1106
return await ctx .send (embed = embed )
1141
1107
1142
1108
@commands .group (aliases = ["perms" ], invoke_without_command = True )
0 commit comments