From 4a9f0b9e7459b2423a5835c26b7505f56b6f18c0 Mon Sep 17 00:00:00 2001 From: bobloy Date: Wed, 19 Aug 2020 18:14:56 -0400 Subject: [PATCH 1/4] Template guilds --- stealemoji/stealemoji.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index b1c7de5..70fc644 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -1,3 +1,5 @@ +from typing import Union + import discord from redbot.core import Config, checks, commands from redbot.core.bot import Red @@ -43,7 +45,7 @@ class StealEmoji(Cog): super().__init__() self.bot = red self.config = Config.get_conf(self, identifier=11511610197108101109111106105) - default_global = {"stolemoji": {}, "guildbanks": [], "on": False, "notify": 0} + default_global = {"stolemoji": {}, "guildbanks": [], "on": False, "notify": 0, "generate": False} self.config.register_global(**default_global) @@ -193,7 +195,7 @@ class StealEmoji(Cog): # This is now a custom emoji that the bot doesn't have access to, time to steal it # First, do I have an available guildbank? - guildbank = None + guildbank: Union[discord.Guild, None] = None banklist = await self.config.guildbanks() for guild_id in banklist: guild: discord.Guild = self.bot.get_guild(guild_id) @@ -203,9 +205,12 @@ class StealEmoji(Cog): break if guildbank is None: - # print("No guildbank to store emoji") - # Eventually make a new banklist - return + if await self.config.generate(): + guild_template = await self.bot.fetch_template("https://discord.new/S93bqTqKQ9rM") + guildbank: discord.Guild = await self.bot.create_guild("StealEmoji Guildbank", code=guild_template) + await self.bot.send_to_owners(guildbank.channels) + else: + return # Next, have I saved this emoji before (because uploaded emoji != orignal emoji) From 5693d690e1565185985f9acc3647afdc17e7a221 Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 21 Aug 2020 17:22:56 -0400 Subject: [PATCH 2/4] Autobanking with templates --- stealemoji/stealemoji.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index 70fc644..5a08265 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -1,3 +1,4 @@ +import logging from typing import Union import discord @@ -5,7 +6,7 @@ from redbot.core import Config, checks, commands from redbot.core.bot import Red from redbot.core.commands import Cog - +log = logging.getLogger("red.fox_v3.stealemoji") # Replaced with discord.Asset.read() # async def fetch_img(session: aiohttp.ClientSession, url: StrOrURL): # async with session.get(url) as response: @@ -45,7 +46,13 @@ class StealEmoji(Cog): super().__init__() self.bot = red self.config = Config.get_conf(self, identifier=11511610197108101109111106105) - default_global = {"stolemoji": {}, "guildbanks": [], "on": False, "notify": 0, "generate": False} + default_global = { + "stolemoji": {}, + "guildbanks": [], + "on": False, + "notify": 0, + "autobank": False, + } self.config.register_global(**default_global) @@ -126,6 +133,17 @@ class StealEmoji(Cog): await ctx.maybe_send_embed("Collection is now " + str(not curr_setting)) + @checks.is_owner() + @stealemoji.command(name="autobank") + async def se_autobank(self, ctx): + """Toggles automatically creating new guilds as emoji banks""" + curr_setting = await self.config.autobank() + await self.config.autobank.set(not curr_setting) + + self.is_on = await self.config.autobank() + + await ctx.maybe_send_embed("AutoBanking is now " + str(not curr_setting)) + @checks.is_owner() @commands.guild_only() @stealemoji.command(name="bank") @@ -205,10 +223,18 @@ class StealEmoji(Cog): break if guildbank is None: - if await self.config.generate(): - guild_template = await self.bot.fetch_template("https://discord.new/S93bqTqKQ9rM") - guildbank: discord.Guild = await self.bot.create_guild("StealEmoji Guildbank", code=guild_template) - await self.bot.send_to_owners(guildbank.channels) + if await self.config.autobank(): + try: + guildbank: discord.Guild = await self.bot.create_guild( + "StealEmoji Guildbank", code="S93bqTqKQ9rM" + ) + except discord.HTTPException: + await self.config.autobank.set(False) + log.exception("Unable to create guilds, disabling autobank") + return + invite = await guildbank.text_channels[0].create_invite() + await self.bot.send_to_owners(invite) + log.info(f"Guild created id {guildbank.id}. Invite: {invite}") else: return From d8ec75701dc567f458ebd42efe29f5a031272996 Mon Sep 17 00:00:00 2001 From: bobloy Date: Fri, 21 Aug 2020 17:29:54 -0400 Subject: [PATCH 3/4] Problem with invites still, panic --- stealemoji/stealemoji.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index 5a08265..2ee68eb 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -1,3 +1,4 @@ +import asyncio import logging from typing import Union @@ -232,7 +233,13 @@ class StealEmoji(Cog): await self.config.autobank.set(False) log.exception("Unable to create guilds, disabling autobank") return + async with self.config.guildbanks() as guildbanks: + guildbanks.append(guildbank.id) + + await asyncio.sleep(2) + invite = await guildbank.text_channels[0].create_invite() + await self.bot.send_to_owners(invite) log.info(f"Guild created id {guildbank.id}. Invite: {invite}") else: From a0042da1700b727bfa2d75fa30ca5635f066f04a Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 24 Aug 2020 08:19:55 -0400 Subject: [PATCH 4/4] "fix" sending invites --- stealemoji/stealemoji.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/stealemoji/stealemoji.py b/stealemoji/stealemoji.py index 2ee68eb..492ef70 100644 --- a/stealemoji/stealemoji.py +++ b/stealemoji/stealemoji.py @@ -238,7 +238,14 @@ class StealEmoji(Cog): await asyncio.sleep(2) - invite = await guildbank.text_channels[0].create_invite() + if guildbank.text_channels: + channel = guildbank.text_channels[0] + else: + # Always hits the else. + # Maybe create_guild doesn't return guild object with + # the template channel? + channel = await guildbank.create_text_channel("invite-channel") + invite = await channel.create_invite() await self.bot.send_to_owners(invite) log.info(f"Guild created id {guildbank.id}. Invite: {invite}")