1
1
import base64
2
2
import binascii
3
3
4
- from discord import AllowedMentions
4
+ from discord import AllowedMentions , app_commands
5
5
from discord .ext import commands
6
6
7
7
from tux .bot import Tux
@@ -44,16 +44,23 @@ async def send_message(self, ctx: commands.Context[Tux], data: str):
44
44
await ctx .reply (
45
45
content = data ,
46
46
allowed_mentions = allowed_mentions ,
47
- ephemeral = False ,
47
+ ephemeral = True ,
48
48
)
49
49
50
- @commands .hybrid_command (
51
- name = "encode" ,
50
+ @commands .hybrid_command (name = "encode" , aliases = ["ec" ], description = "Encode a message" )
51
+ @app_commands .describe (text = "Text to encode" )
52
+ @app_commands .choices (
53
+ codesystem = [
54
+ app_commands .Choice (name = "base16" , value = "base16" ),
55
+ app_commands .Choice (name = "base32" , value = "base32" ),
56
+ app_commands .Choice (name = "base64" , value = "base64" ),
57
+ app_commands .Choice (name = "base85" , value = "base85" ),
58
+ ],
52
59
)
53
60
async def encode (
54
61
self ,
55
62
ctx : commands .Context [Tux ],
56
- cs : str ,
63
+ codesystem : str ,
57
64
* ,
58
65
text : str ,
59
66
) -> None :
@@ -64,23 +71,23 @@ async def encode(
64
71
----------
65
72
ctx : commands.Context[Tux]
66
73
The context of the command.
67
- cs : str
74
+ codesystem : str
68
75
The coding system.
69
76
text : str
70
77
The text you want to encode.
71
78
"""
72
79
73
- cs = cs .lower ()
80
+ codesystem = codesystem .lower ()
74
81
btext = text .encode (encoding = "utf-8" )
75
82
76
83
try :
77
- if cs == "base16" :
84
+ if codesystem == "base16" :
78
85
data = base64 .b16encode (btext )
79
- elif cs == "base32" :
86
+ elif codesystem == "base32" :
80
87
data = base64 .b32encode (btext )
81
- elif cs == "base64" :
88
+ elif codesystem == "base64" :
82
89
data = base64 .b64encode (btext )
83
- elif cs == "base85" :
90
+ elif codesystem == "base85" :
84
91
data = base64 .b85encode (btext )
85
92
else :
86
93
await ctx .reply (
@@ -98,13 +105,21 @@ async def encode(
98
105
ephemeral = True ,
99
106
)
100
107
101
- @commands .hybrid_command (
102
- name = "decode" ,
108
+ @commands .hybrid_command (name = "decode" , aliases = ["dc" ], description = "Decode a message" )
109
+ @app_commands .describe (codesystem = "Which Coding System to use" )
110
+ @app_commands .describe (text = "Text to decode" )
111
+ @app_commands .choices (
112
+ codesystem = [
113
+ app_commands .Choice (name = "base16" , value = "base16" ),
114
+ app_commands .Choice (name = "base32" , value = "base32" ),
115
+ app_commands .Choice (name = "base64" , value = "base64" ),
116
+ app_commands .Choice (name = "base85" , value = "base85" ),
117
+ ],
103
118
)
104
119
async def decode (
105
120
self ,
106
121
ctx : commands .Context [Tux ],
107
- cs : str ,
122
+ codesystem : str ,
108
123
* ,
109
124
text : str ,
110
125
) -> None :
@@ -115,23 +130,23 @@ async def decode(
115
130
----------
116
131
ctx : commands.Context[Tux]
117
132
The context of the command.
118
- cs : str
133
+ codesystem : str
119
134
The coding system.
120
135
text : str
121
136
The text you want to decode.
122
137
"""
123
138
124
- cs = cs .lower ()
139
+ codesystem = codesystem .lower ()
125
140
btext = text .encode (encoding = "utf-8" )
126
141
127
142
try :
128
- if cs == "base16" :
143
+ if codesystem == "base16" :
129
144
data = base64 .b16decode (btext )
130
- elif cs == "base32" :
145
+ elif codesystem == "base32" :
131
146
data = base64 .b32decode (btext )
132
- elif cs == "base64" :
147
+ elif codesystem == "base64" :
133
148
data = base64 .b64decode (btext )
134
- elif cs == "base85" :
149
+ elif codesystem == "base85" :
135
150
data = base64 .b85decode (btext )
136
151
else :
137
152
await ctx .reply (
0 commit comments