Skip to content

Commit fe36a80

Browse files
committed
add other stealemote commands
1 parent d2ec3cb commit fe36a80

File tree

5 files changed

+237
-174
lines changed

5 files changed

+237
-174
lines changed

cogs/information.py

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import asyncio
21
import math
32
import random
4-
import re
53
import string
64
import time
75
from calendar import monthrange
86
from datetime import datetime
9-
from typing import Optional
107

11-
import aiohttp
128
import discord
139
import psutil
1410
from discord.ext import commands, tasks
@@ -1091,156 +1087,6 @@ async def set_event_channel_perms(self, member, channel_id, command):
10911087
member, overwrite=None, reason="User left event"
10921088
)
10931089

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-
12441090

12451091
async def setup(bot):
12461092
await bot.add_cog(Information(bot))

cogs/mainbot.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@ class MainBot(commands.Cog):
99
def __init__(self, bot: commands.Bot):
1010
self.bot = bot
1111
self.startup_extensions = [
12-
"statistics",
13-
"minesweeper",
12+
"admin",
13+
"aoc",
14+
"draw",
1415
"hangman",
15-
"quote",
1616
"help",
17-
"reputation",
18-
"admin",
17+
"information",
18+
"mainbot",
19+
"minesweeper",
1920
"owner",
21+
"quote",
22+
"reputation",
23+
"statistics",
24+
"stealemote",
2025
"voice",
21-
"information",
22-
"draw",
23-
"aoc",
24-
"mainbot"
2526
]
2627
self.watching_messages = [
2728
"students",
@@ -34,7 +35,7 @@ def __init__(self, bot: commands.Bot):
3435
"the other bots",
3536
"how to git gud",
3637
"memes",
37-
"the void"
38+
"the void",
3839
]
3940

4041
@commands.Cog.listener()
@@ -45,28 +46,41 @@ async def on_ready(self):
4546
log(f"Name: {self.bot.user.name if self.bot.user else '<no name>'}")
4647
log(f"ID: {self.bot.user.id if self.bot.user else '<no id>'}")
4748
log(f"Version: {discord.__version__}")
48-
await self.bot.change_presence(activity=discord.Activity(name=random.choice(self.watching_messages), type=discord.ActivityType.watching))
49+
await self.bot.change_presence(
50+
activity=discord.Activity(
51+
name=random.choice(self.watching_messages),
52+
type=discord.ActivityType.watching,
53+
)
54+
)
4955
print("-------------")
5056
count = await self.load_all_extensions(self.startup_extensions)
51-
log(f"Started up bot with {count}/{len(self.startup_extensions)-2} extensions loaded successfully.")
57+
log(
58+
f"Started up bot with {count}/{len(self.startup_extensions) - 2} extensions loaded successfully."
59+
)
5260
print("-------------")
53-
61+
5462
channel = self.bot.get_channel(1004090600934617238)
5563
if isinstance(channel, discord.abc.Messageable):
56-
embed = discord.Embed(title="Bot started up", timestamp=datetime.now(), color=0xcbd3d7)
64+
embed = discord.Embed(
65+
title="Bot started up", timestamp=datetime.now(), color=0xCBD3D7
66+
)
5767
await channel.send("<@205704051856244736>", embed=embed)
5868

5969
async def load_all_extensions(self, extensions_to_load) -> int:
6070
count = 0
6171
for extension in extensions_to_load:
6272
try:
6373
await self.bot.load_extension("cogs." + extension)
64-
log(f"Loaded extension \"{extension}\".")
74+
log(f'Loaded extension "{extension}".')
6575
count += 1
6676
except commands.errors.ExtensionAlreadyLoaded:
6777
pass
6878
except Exception as e:
69-
log(f"Failed loading extension \"{extension}\"\n-{e}: {type(e)}", print_it=True, warning=True)
79+
log(
80+
f'Failed loading extension "{extension}"\n-{e}: {type(e)}',
81+
print_it=True,
82+
warning=True,
83+
)
7084
return count
7185

7286
@commands.is_owner()
@@ -77,9 +91,8 @@ async def reload(self, ctx, cog=None):
7791
Permissions: Owner
7892
"""
7993
if cog is None:
80-
cog_list = '\n'.join(self.startup_extensions)
81-
await ctx.send(f"Following cogs exist:\n"
82-
f"{cog_list}")
94+
cog_list = "\n".join(self.startup_extensions)
95+
await ctx.send(f"Following cogs exist:\n{cog_list}")
8396
elif cog in self.startup_extensions:
8497
await ctx.send(await self.reload_cog(cog))
8598
await ctx.send(f"DONE - Reloaded `{cog}`")

0 commit comments

Comments
 (0)