|
1 | | -import asyncio |
2 | 1 | import math |
3 | 2 | import random |
4 | | -import re |
5 | 3 | import string |
6 | 4 | import time |
7 | 5 | from calendar import monthrange |
8 | 6 | from datetime import datetime |
9 | | -from typing import Optional |
10 | 7 |
|
11 | | -import aiohttp |
12 | 8 | import discord |
13 | 9 | import psutil |
14 | 10 | from discord.ext import commands, tasks |
@@ -1091,156 +1087,6 @@ async def set_event_channel_perms(self, member, channel_id, command): |
1091 | 1087 | member, overwrite=None, reason="User left event" |
1092 | 1088 | ) |
1093 | 1089 |
|
1094 | | - @commands.command( |
1095 | | - usage="stealemote [emote_id | emote_name]", aliases=["stealemote"] |
1096 | | - ) |
1097 | | - async def steal_emote(self, ctx: commands.Context, id: Optional[int | str] = None): |
1098 | | - """ |
1099 | | - Steal emotes of another message by replying to it. An optional ID or name of the emote can be passed in to specify which emote to steal. |
1100 | | - Without any options, all emotes will be stolen. If a name is passed in and there are multiple with the same name, all of them will be stolen. |
1101 | | - """ |
1102 | | - if not ctx.message.reference: |
1103 | | - await ctx.reply("Reply to a message to steal emotes from.") |
1104 | | - raise commands.errors.BadArgument() |
1105 | | - async with ctx.typing(): |
1106 | | - guilds = SQLFunctions.get_steal_emote_servers(ctx.author.id, self.conn) |
1107 | | - if len(guilds) == 0: |
1108 | | - await ctx.reply( |
1109 | | - "You have no servers to steal emotes to. Use `$set_server <server_id>` to set a server." |
1110 | | - ) |
1111 | | - raise commands.errors.BadArgument() |
1112 | | - message = await ctx.fetch_message(ctx.message.reference.message_id) |
1113 | | - emote_ids: list[tuple[str, str]] = re.findall( |
1114 | | - r"<a?:(\w+):(\d+)>", message.content |
1115 | | - ) |
1116 | | - if len(emote_ids) == 0: |
1117 | | - await ctx.reply("No emotes found in the message.") |
1118 | | - raise commands.errors.BadArgument() |
1119 | | - emotes: list[str] = [] |
1120 | | - emote_names: dict[str, str] = {} |
1121 | | - for name, emote in emote_ids: |
1122 | | - if isinstance(id, int): |
1123 | | - if emote.isnumeric() and int(emote) == id: |
1124 | | - emotes.append(emote) |
1125 | | - emote_names[emote] = name |
1126 | | - break |
1127 | | - elif isinstance(id, str): |
1128 | | - if emote.isnumeric() and name == id: |
1129 | | - emotes.append(emote) |
1130 | | - emote_names[emote] = name |
1131 | | - else: |
1132 | | - if emote.isnumeric(): |
1133 | | - emotes.append(emote) |
1134 | | - emote_names[emote] = name |
1135 | | - |
1136 | | - base_url = "https://cdn.discordapp.com/emojis/" |
1137 | | - |
1138 | | - async def fetch(emote_id: str): |
1139 | | - async with aiohttp.ClientSession() as session: |
1140 | | - async with session.get(base_url + emote_id) as response: |
1141 | | - if response.status != 200: |
1142 | | - return None |
1143 | | - return await response.read() |
1144 | | - |
1145 | | - results: list[bytes | None] = await asyncio.gather( |
1146 | | - *[fetch(emote) for emote in emotes] |
1147 | | - ) |
1148 | | - results: list[bytes] = [result for result in results if result] |
1149 | | - if len(results) == 0: |
1150 | | - await ctx.reply("No *valid* emotes found in the message.") |
1151 | | - raise commands.errors.BadArgument() |
1152 | | - |
1153 | | - success: list[str] = [] |
1154 | | - errors: list[str] = [] |
1155 | | - added = [] |
1156 | | - for guild_id in guilds: |
1157 | | - try: |
1158 | | - guild = await self.bot.fetch_guild(guild_id, with_counts=False) |
1159 | | - except Exception: |
1160 | | - errors.append(f"{guild_id}: Unable to fetch") |
1161 | | - continue |
1162 | | - |
1163 | | - for result in results: |
1164 | | - if result in added: |
1165 | | - continue |
1166 | | - try: |
1167 | | - emoji = await guild.create_custom_emoji( |
1168 | | - name=emote_names[emote], image=result |
1169 | | - ) |
1170 | | - success.append(f"{guild_id}: Success: {str(emoji)}") |
1171 | | - added.append(result) |
1172 | | - except discord.Forbidden: |
1173 | | - errors.append( |
1174 | | - f"{guild_id}: Missing permissions (`{emote_names[emote]}`)" |
1175 | | - ) |
1176 | | - continue |
1177 | | - except discord.HTTPException: |
1178 | | - errors.append( |
1179 | | - f"{guild_id}: Failed to add emote (`{emote_names[emote]}`)" |
1180 | | - ) |
1181 | | - continue |
1182 | | - |
1183 | | - success = "\n".join([f"- {x}" for x in success]) |
1184 | | - errors = "\n".join([f"- {x}" for x in errors]) |
1185 | | - embed = discord.Embed( |
1186 | | - description=f"**Success:**\n{success}\n\n**Errors:**\n{errors}" |
1187 | | - ) |
1188 | | - await ctx.reply(embed=embed) |
1189 | | - |
1190 | | - @commands.command(usage="set_server <server_id>", aliases=["setserver"]) |
1191 | | - async def set_server(self, ctx: commands.Context, id: int): |
1192 | | - """ |
1193 | | - Set the server that $stealemote steals emotes to. You can add multiple servers which will each be tried |
1194 | | - incase there's an error with any. |
1195 | | - """ |
1196 | | - # 5th march |
1197 | | - if ctx.author.id == 254709226738417665 and time.time() < 1741194911: |
1198 | | - await ctx.reply("You wish. Told you I won't let you use it.") |
1199 | | - return |
1200 | | - |
1201 | | - try: |
1202 | | - guild = await self.bot.fetch_guild(id) |
1203 | | - except discord.Forbidden: |
1204 | | - await ctx.reply( |
1205 | | - "Blud, I can't see that server. Invite me to your server first." |
1206 | | - ) |
1207 | | - raise commands.errors.BadArgument() |
1208 | | - except discord.HTTPException: |
1209 | | - await ctx.reply( |
1210 | | - "Blud, I can't work with that server. Invite me to your server first." |
1211 | | - ) |
1212 | | - raise commands.errors.BadArgument() |
1213 | | - |
1214 | | - try: |
1215 | | - user = await guild.fetch_member(ctx.author.id) |
1216 | | - except discord.Forbidden: |
1217 | | - await ctx.reply( |
1218 | | - "Blud, I can't see that server. Invite me to your server first." |
1219 | | - ) |
1220 | | - raise commands.errors.BadArgument() |
1221 | | - except discord.NotFound: |
1222 | | - await ctx.reply("Ayoo, you're not even on that server.") |
1223 | | - raise commands.errors.BadArgument() |
1224 | | - except discord.HTTPException: |
1225 | | - await ctx.reply("Invalid server ID") |
1226 | | - raise commands.errors.BadArgument() |
1227 | | - |
1228 | | - if not user.guild_permissions.create_expressions: |
1229 | | - await ctx.reply( |
1230 | | - "You don't have the permissions to manage emojis on that server." |
1231 | | - ) |
1232 | | - raise commands.errors.BadArgument() |
1233 | | - |
1234 | | - myself = await guild.fetch_member(self.bot.user.id) |
1235 | | - if not myself.guild_permissions.create_expressions: |
1236 | | - await ctx.reply( |
1237 | | - "I don't have the permissions to create emojis on that server." |
1238 | | - ) |
1239 | | - raise commands.errors.BadArgument() |
1240 | | - |
1241 | | - SQLFunctions.add_steal_emote_server(ctx.author.id, id, self.conn) |
1242 | | - await ctx.reply("Successfully set server for stealing emotes.") |
1243 | | - |
1244 | 1090 |
|
1245 | 1091 | async def setup(bot): |
1246 | 1092 | await bot.add_cog(Information(bot)) |
|
0 commit comments