Autobanking with templates
This commit is contained in:
		
							parent
							
								
									79cc34d331
								
							
						
					
					
						commit
						5693d690e1
					
				| @ -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 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 bobloy
						bobloy