async def addemoji(self, ctx, emoji: typing.Union[int, str] = None): """Add an emoji from our list!""" data = json_mngr().read('./data/emojis.json') if emoji: for name in data.keys(): if isinstance(emoji, int) and emoji == data[name]['id']: te = discord.utils.get(self.bot.emojis, id=emoji) if te is None: raise GetError( code=1, reason='This emoji is unavailable (NotFound)') await self.addemoji_method(ctx, emoji=te, data=data) else: tea = discord.utils.get(self.bot.emojis, name=emoji) for te in tea: if isinstance(te, discord.Emoji): steven = await ctx.send( f"Is this the correct emoji? [y/n]\nPreview: {te}" ) try: def check(m): return (m.author, m.channel) == ( ctx.author, ctx.channel) and ( 'y' in m.content.lower() or 'y' in m.content.lower()) bob = await self.bot.wait_for('message', check=check, timeout=120) except asyncio.TimeoutError: return await steven.edit(content="Timed out.") if bob.content.lower().startswith('n'): await bob.edit(content="Finding another one.") continue elif bob.content.lower().startswith('y'): return await self.addemoji_method(ctx, data=data, emoji=te) else: return await ctx.send( "An unknown error caused this emoji to go unavailable\n" "Error code #0002") else: raise GetError(code=3, reason="Emoji not found") else: topag = "" for emoji in data.keys(): topag += f"Emoji name: {emoji}\nSource guild: {emoji['guild']}\nPreview: <{emoji['url']}>\n\n" if len(topag) > 1900: for page in pagify(topag, escape_stuff=True, page_length=1900): await ctx.send(page, delete_after=30) else: return await ctx.send( discord.utils.escape_markdown( discord.utils.escape_mentions(topag)))
def __init__(self, bot): self.bot = bot self.coin = '<:idle:551164099099230214>' self.success = '<:success:522078924432343040>' self.loading = '<a:loading20:553253741311295498>' self._loading = '<a:loading:551413963766890527>' self.error = '<:fail:522076877075251201>' self.betting = {} self.b.start() self.money_pool = {"amount": 0, 'users': [], 'userbets': {}} d = json_mngr().read('./data/event.json') self.event_multi = d['event_multi'] self.redeemed = [] self.code = d['redeem_codes'] self.getnewcodeauto.start()
async def lb(self, ctx): """get the global leaderboard""" my_dict = json_mngr().read('./data/eco.json') d = "" sort = list(reversed(sorted(my_dict.keys(), key=lambda x: my_dict[x]))) for num, user in enumerate(sort[:10], start=1): try: us = self.bot.get_user(int(user)) u = discord.utils.escape_mentions( discord.utils.escape_markdown(us.display_name)) except discord.NotFound: u = '*unknown user' us = await self.bot.fetch_user(int(user)) d += f'**{num}**. {u}: {self.coin}{my_dict[str(us.id)]}\n' e = discord.Embed(title="YourLocalEco! leaderboard:", description=d, color=discord.Color.blue()) await ctx.send(embed=e)
async def addemoji_add(self, ctx, emoji: discord.Emoji): """Add an emoji to the emojis to be able to use that emoji idfk it adds the emoji for the base command""" data = json_mngr().read('./data/emojis.json') if str(emoji.id) in data.keys(): return await ctx.send("We already have that emoji!") data[str(emoji.id)] = { "id": emoji.id, "url": str(emoji.url), "name": emoji.name, "guild": ctx.guild.name, 'submitter': str(ctx.author) } json_mngr.handle_modify('./data/emojis.json', newdata=data, backup=True) await ctx.send("Added to the list.")
async def fromtemplate(self, ctx, *, template: commands.clean_content = 'List'): """ create a server from some pre-defined templates! `template` can be a name of a template, or `list` to list available templates! can also be `info` to view info on a template """ templates = json_mngr().read('./data/templates.json') if str(template).lower().startswith('li'): # lazily assume its list e = discord.Embed(title="Templates:") for templ in templates.keys()[:24]: # shows up to 24 templates e.add_field(name=f"Name: {templ['name']}", value=f"Author: {templ['author']}\nTheme: {templ['theme']}" \ f"\nText Channels: {len(templ['textchannels'])}\nVoice Channels: " f"{len(templ['voicechannels'])}", inline=False) return await ctx.send(embed=e) if str(template).lower() not in [s.lower() for s in templates.keys()]: return await ctx.send( f"{template} is not a registered template!\nWant to add it? do `" f"{ctx.prefix}clone fromtemplate create`!\nWant to see a" f" list of templates? do `{ctx.prefix}clone fromtemplate list`!" ) c = lambda m: m.author == ctx.author and m.channel == ctx.channel t = templates[str(template).lower()] try: msg = await ctx.send( f"Please confirm you would like to use the template `{template}` [y/n]" f"\n```\nImporting:\n{len(t['textchannels'])} Text Channels\n" f"{len(t['voicechannels'])} Voice Channels\n{len(t['roles'])} roles\n```\n**REMEMBE" f"R THIS WIPES YOUR SERVER FIRST**") mr = await self.bot.wait_for('message', check=c, timeout=120) if mr.content.lower().startswith('y'): pass else: return await msg.edit(content="ok. cancelled.") except asyncio.TimeoutError: return await ctx.send("Timed out. assumed answer: n") for i in range(5, 0): if ctx.guild.me.top_role != list(reversed(ctx.guild.roles))[0]: await msg.edit( content= f"Please give me the highest role in this server first.\nRetries remaining: " f"{5 - i}") await asyncio.sleep(10) else: break else: return await msg.edit( content="I require the highest role to preform this action") await msg.edit("ok.") err = [] for channel in ctx.guild.channels: try: await channel.delete(reason="Forming Template") except Exception as e: err.append(e) continue for role in ctx.guild.roles: try: await role.delete(reason="Forming template") except Exception as e: err.append(e) for role in t['roles']: try: await ctx.guild.create_role(name=role['name'], permissions=role['permissions'], color=role['color'], hoist=role['hoist'], mentionable=role['mentionable'], reason="Importing roles") except Exception as e: err.append(f"Error while creating role {role.id}: {e}") for category in t['categories']: await ctx.guild.create_category(category.name, ) for textchannel in t['textchannels']: if textchannel.category is None: await ctx.guild.create_text_channel( textchannel['nname'], overwrites=textchannel['overwrites'], topic=textchannel['topic'], slowmode_delay=textchannel['slowmode_delay'], nsfe=textchannel['nsfw'], reason="No category channel imports")