-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmido_util.py
265 lines (229 loc) ยท 8.49 KB
/
mido_util.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import discord
from discord.ext import commands
import re
import random
#get_status
def get_status(member):
if str(member.status) == "online":
return "๐ใชใณใฉใคใณ"
elif str(member.status) == "idle":
return "๐งก้ๅธญไธญ"
elif str(member.status) == "dnd":
return "โคๅใ่พผใฟไธญ"
elif str(member.status) == "offline":
return "๐คใชใใฉใคใณ"
#resolve_url
def resolve_url(url):
HTTP_URL_REGEX = "https?://[\w/:%#\$&\?\(\)~\.=\+\-]+"
URL_REGEX = "[\w/:%#\$&\?\(\)~\.=\+\-]+"
if re.match(HTTP_URL_REGEX, str(url)):
return str(url)
elif re.match(URL_REGEX, str(url)):
return f"http://" + str(url)
#resolve_invite
async def resolve_invite(ctx, code:str):
try:
return await ctx.bot.fetch_invite(code)
except discord.NotFound:
raise commands.BadArgument(f"Invite {code} not found.")
except discord.HTTPException as e:
raise commands.BadArgument(f"Error fetching invite code: {e}")
#get_channel_or_user
def get_channel_or_user(ctx, id:int):
result = ctx.bot.get_user(id)
if result is None:
result = ctx.bot.get_channel(id)
if result is None:
raise commands.BadArgument(f"Argument {id} not found.")
return result
#get_features
def get_features(guild):
feature = guild.features
key = []
features = {
"VIP_REGIONS":"VIP Region",
"VANITY_URL":"Vanity URL",
"INVITE_SPLASH":"Splash Invite",
"VERIFIED":"Verified",
"PARTNERED":"Partnered",
"MORE_EMOJI":"More Emoji",
"DISCOVERABLE":"Discoverable",
"FEATUREABLE":"Featureable",
"COMMUNITY":"Community",
"PUBLIC":"Public",
"NEWS":"News",
"BANNER":"Banner",
"ANIMATED_ICON":"Animated Icon",
"PUBLIC_DISABLED":"Public Disabled",
"WELCOME_SCREEN_ENABLED":"Welcome Screen Enabled",
"MEMBER_VERIFICATION_GATE_ENABLED":"Member Verification Gate Enabled",
"PREVIEW_ENABLED":"Preview Enabled"
}
for i in range(len(feature)):
try:
key.append(features[str(feature)])
except KeyError:
key.append(str(feature))
return key
#get_region
def get_region(guild):
region = guild.region
regions = {
"brazil":"๐ง๐ท Brazil",
"europe":"๐ช๐บ Europe",
"hongkong":"๐ญ๐ฐ HongKong",
"india":"๐ฎ๐ณ India",
"japan":"๐ฏ๐ต Japan",
"russia":"๐ท๐บ Russia",
"singapore":"๐ธ๐ฌ Singapore",
"southafrica":"๐ฟ๐ฆ SouthAfrica",
"sydney":"๐ฆ๐บ Sydney",
"us_central":"๐บ๐ธ US_Central",
"us_east":"๐บ๐ธ US_East",
"us_south":"๐บ๐ธ US_South",
"us_west":"๐บ๐ธ US_West"
}
try:
key = regions[str(region)]
except KeyError:
key = str(region)
return key
#Neta
def is_jun50(ctx, member=None):
if member is None:
member = ctx.author
return member.id in [579598776721735690, 449867036558884866]
#get_guild_or_user
async def get_guild_or_user(ctx, id):
if ctx.bot.get_guild(id) is None:
try:
return await FetchUserConverter().convert(ctx, str(id))
except:
raise commands.BadArgument(f"ID {id} not guild or user.")
#choice
def choice(l, c=1):
r = []
for c in range(c):
d = random.choice(l)
r.append(d)
l.remove(d)
return r
#VoiceChannelConverter
class VoiceChannelConverter(commands.Converter):
async def convert(self, ctx, argument):
try:
return await commands.VoiceChannelConverter().convert(ctx, argument)
except:
try:
channel_id = int(argument, base=10)
except ValueError:
raise commands.BadArgument(f"VoiceChannel {argument!r} not found.")
else:
channel = ctx.bot.get_channel(channel_id)
if channel is None:
raise commands.BadArgument(f"VoiceChannel {argument!r} not found.")
return channel
#TextChannelConverter
class TextChannelConverter(commands.Converter):
async def convert(self, ctx, argument):
try:
return await commands.TextChannelConverter().convert(ctx, argument)
except commands.BadArgument:
try:
channel_id = int(argument, base=10)
except ValueError:
raise commands.BadArgument(f"TextChannel {argument!r} not found.")
else:
channel = ctx.bot.get_channel(channel_id)
if channel is None:
raise commands.BadArgument(f"TextChannel {argument!r} not found.")
return channel
#ChannelConverter
class ChannelConverter(commands.Converter):
async def convert(self, ctx, argument):
try:
return await TextChannelConverter().convert(ctx, argument)
except:
try:
return await VoiceChannelConverter().convert(ctx, argument)
except:
try:
return await commands.CategoryChannelConverter().convert(ctx, argument)
except:
raise commands.ChannelNotFound(argument)
#GuildConverter
class GuildConverter(commands.Converter):
async def convert(self, ctx, argument):
guild = None
if argument.isdigit():
guild = ctx.bot.get_guild(int(argument))
if guild is None:
raise commands.BadArgument(f"Guild {argument} not found.")
else:
if guild is None:
guild = discord.utils.get(ctx.bot.guilds, name=argument)
if guild is None:
raise commands.BadArgument(f"Guild {argument} not found.")
return guild
#BotUserConverter
class BotUserConverter(commands.Converter):
async def convert(self, ctx, argument):
if not argument.isdigit():
raise commands.BadArgument("Not a valid bot user ID.")
try:
result = await ctx.bot.fetch_user(argument)
except discord.NotFound:
raise commands.BadArgument("Bot user not found (404).")
except discord.HTTPException as exc:
raise commands.BadArgument(f"Error fetching bot user: {exc}")
else:
if not result.bot:
raise commands.BadArgument("This is not a bot.")
return result
#BannedMemberConverter
class BannedMemberConverter(commands.Converter):
async def convert(self, ctx, argument):
if argument.isdigit():
member_id = int(argument, base=10)
try:
return await ctx.guild.fetch_ban(discord.Object(id=member_id))
except discord.NotFound:
raise commands.BadArgument(f'User {argument} is not banned.') from None
ban_list = await ctx.guild.bans()
entity = discord.utils.find(lambda u: str(u.user) == argument, ban_list)
if entity is None:
raise commands.BadArgument(f'User {argument} is not banned.')
return entity
#FetchUserConverter
class FetchUserConverter(commands.Converter):
async def convert(self, ctx, argument):
if not argument.isdigit():
return await commands.MemberConverter().convert(ctx, argument)
try:
return await ctx.bot.fetch_user(int(argument))
except discord.NotFound:
raise commands.BadArgument(f'User {argument} not found.') from None
except discord.HTTPException as exc:
raise commands.BadArgument(f'Error fetching user: {exc}') from None
#MemberConverter
class MemberConverter(commands.Converter):
async def convert(self, ctx, argument):
if not argument.isdigit():
try:
return await commands.MemberConverter().convert(ctx, argument)
except:
try:
return await commands.UserConverter().convert(ctx, argument)
except:
raise commands.MemberNotFound(argument)
else:
try:
return await commands.MemberConverter().convert(ctx, argument)
except:
try:
return await commands.UserConverter().convert(ctx, argument)
except:
try:
return await FetchUserConverter().convert(ctx, argument)
except:
raise commands.MemberNotFound(argument)