示例#1
0
 async def __close(self, ctx, *, name: str):
     """toggles an application. for example, if it is already closed, it will open it."""
     _data = json_mngr().read('./data/apps.json')
     data = _data[str(ctx.guild.id)]
     _open = data['open']
     _closed = data['closed']
     for app in data['closed']:
         if app['name'] == name.lower():
             data['closed'].remove(app)
             data['open'].append(app)
             did = 'opened'
             break
     else:
         for app in data['open']:
             if app['name'] == name.lower():
                 data['open'].remove(app)
                 data['closed'].append(app)
                 did = 'closed'
                 break
         else:
             return await ctx.send("No app by that name was found.")
     json_mngr().handle_mod('./data/apps.json',
                            newdata=data,
                            indent=2,
                            backup=True)
     await ctx.send(
         f'{did} the application. view it with `{ctx.prefx}positions`!')
示例#2
0
 async def submit_app(self,
                      ctx,
                      embed: discord.Embed,
                      appname,
                      *,
                      rawdata=None):
     guild = str(ctx.guild.id)
     data = json_mngr().read('./data/settings.json')
     if str(guild) not in data.keys():  # wot
         await ctx.send(
             "Error: the bot was unable to send a message to the guild's log channel. please tell "
             "an administrator")
     else:
         logchannel = self.bot.get_channel(data[guild]['log_channel'])
         if logchannel is None:
             await ctx.send(
                 "Error: the bot was unable to send a message to the guild's log channel. please tell "
                 "an administrator to set a log channel")
         else:
             embed.title = f"The application for {ctx.author}, {appname}:"
             await logchannel.send(embed=embed)
         apps = json_mngr().read('./data/apps.json')
         apps[guild]['submitted'].append(embed)
         json_mngr().handle_modify('./data/apps.json',
                                   newdata=apps,
                                   backup=True)
         return
示例#3
0
 async def setup(self, ctx, *, name: str):
     """Run setup, and create your first app!"""
     # TODO: visualise errors
     data = json_mngr().read('./data/apps.json')
     if str(ctx.guild.id) not in data.keys():
         data[str(ctx.guild.id)] = {
             "open": [],
             "closed": [],
             "submitted": [],
             "appdata": {}
         }
     if name.lower() in data[str(ctx.guild.id)]['appdata'].keys():
         return await ctx.send("That application already exists!")
     appdata = await helper.App().create(ctx,
                                         name,
                                         timeout=120.0,
                                         setup=True)
     data[str(ctx.guild.id)]['open'].append({
         'name': name,
         'value': appdata['description']
     })
     data[str(ctx.guild.id)]['appdata'][name.lower()] = appdata
     json_mngr().handle_modify('./data/apps.json',
                               newdata=data,
                               indent=2,
                               backup=True)
     await ctx.send(ctx.author.mention +
                    ' Successfully made an application!')
示例#4
0
 def _setup(self, ctx):
     data = json_mngr().read('./data/settings.json')
     data[str(ctx.guild.id)] = {
         "edit_roles": [],
         "view_roles": [],
         "log_channel": None
     }
     return json_mngr().handle_modify('./data/settings.json', newdata=data)
示例#5
0
 async def settings_raw(self, ctx):
     """retrieves all of your guild's data and outputs it in a JSON format. only use this if you understand JSON."""
     data = json_mngr().read('./data/settings.json')
     if str(ctx.guild.id) not in data.keys():
         return await ctx.send("Your guild has no data!")
     else:
         with open('./data/' + str(ctx.guild.id) + '.json', 'w+') as f:
             f.write('{}')
             json_mngr().handle_modify(f'./data/{str(ctx.guild.id)}.json',
                                       newdata=data[str(ctx.guild.id)],
                                       backup=False)
             f.close()
         return await ctx.send("Here is your guild's data!",
                               file=discord.File('./data/{}.json'.format(
                                   str(ctx.guild.id))))
示例#6
0
 async def remove(self, ctx, *, role: discord.Role):
     """remove an editing role"""
     data = json_mngr().read('./data/settings.json')
     if str(ctx.guild.id) not in data.keys():
         data[str(ctx.guild.id)] = {
             "edit_roles": [],
             "view_roles": [],
             "log_channel": None
         }
     if role:
         if role.id in data[str(ctx.guild.id)]['edit_roles']:
             data[str(ctx.guild.id)]['edit_roles'].remove(role.id)
         json_mngr().handle_modify('./data/settings.json',
                                   newdata=data,
                                   indent=2,
                                   backup=True)
         await ctx.send(f"removed {role.id} as an editing role.")
示例#7
0
    async def editrole(self, ctx, *, role: discord.Role):
        """Set the role that is allowed to edit apps
		leave blank to reset it"""
        data = json_mngr().read('./data/settings.json')
        if str(ctx.guild.id) not in data.keys():
            data[str(ctx.guild.id)] = {
                "edit_roles": [],
                "view_roles": [],
                "log_channel": None
            }
        if role:
            data[str(ctx.guild.id)]['edit_roles'].append(role.id)
            json_mngr().handle_modify('./data/settings.json',
                                      newdata=data,
                                      indent=2,
                                      backup=True)
            await ctx.send(f"added {role.id} as an editing role.")
示例#8
0
 async def setlog(self, ctx, channel: discord.TextChannel):
     """set a logging channel for apps"""
     data = json_mngr().read('./data/settings.json')
     if str(ctx.guild.id) not in data.keys():
         data = self._setup(ctx)
     m = await ctx.send("setting...")
     try:
         await channel.send(embed=discord.Embed(
             title="log permissions test"))
     except discord.Forbidden:
         return await m.edit(
             content=
             "Unable to send to that channel. please enable embed links and send messages"
             f" for me in {channel.mention}")
     json_mngr().handle_modify('./data/settings.json',
                               newdata=data,
                               backup=True)
     await m.edit(content="complete!")
示例#9
0
        def p(ctx):
            data = json_mngr().read('./data/settings.json')
            if str(ctx.guild.id) not in data.keys():
                return False  # no config

            if len(data[str(ctx.guild.id)]['edit_roles']) == 0:
                return False  # no role set

            for role in ctx.author.roles:
                if role.id in data[str(ctx.guild.id)]['edit_roles']:
                    return True
            else:
                return False  # no role
示例#10
0
    async def _settings(self, ctx, *, value: str = None):
        """View your server's current configuration settings!
		provide `value` and i will attempt to """
        data = json_mngr().read('./data/settings.json')
        if str(ctx.guild.id) not in data.keys():
            return await ctx.send("You haven't set any settings yet!")
        data = data[str(ctx.guild.id)]
        if ctx.author:
            e = discord.Embed(color=discord.Color.orange())
            for key in data.keys():
                e.add_field(name=key,
                            value=f'setting: {data[key]}',
                            inline=False)
            return await ctx.send(embed=e)
示例#11
0
 async def apply(self, ctx, *, appname: str):
     """apply for an app!"""
     # return await ctx.send("this command is None-functional as it does not have working framework.")
     _data = json_mngr().read('./data/apps.json')
     print(_data)
     data = _data[str(ctx.guild.id)]
     print(data)
     for app in data['open']:
         if app['name'].lower() == appname.lower():
             if app['name'] in data['appdata'].keys():
                 print(data['appdata'])
                 print(data['appdata'][app['name']])
                 print(data['appdata'][app['name']]["PURE_QUESTIONS"])
                 questions = data['appdata'][app['name']]["PURE_QUESTIONS"]
                 _questions = enumerate(questions, start=1)
                 e = discord.Embed(title=f"apply for {app['name']}!",
                                   color=discord.Color.blue())
                 message = await ctx.send(embed=e)
                 for n, q in _questions:
                     e.add_field(name=f"{n}. {q}", value="your answer here")
                     await message.edit(content=None, embed=e)
                     answer = await self.get_answer(ctx)
                     if answer is None:
                         return await ctx.send("Timed out.")
                     e.remove_field(len(e.fields) - 1)
                     e.add_field(name=f"{n}. {q}", value=answer.content)
                 x = await ctx.send(
                     "Are you sure you want to submit this application?")
                 yes = '\U00002705'
                 no = '\U0000274c'
                 await x.add_reaction(yes)
                 await x.add_reaction(no)
                 r, u = await self.bot.wait_for(
                     'reaction_add',
                     check=lambda r, u: str(r.emoji) in [yes, no] and r.
                     message.id == x.id and u.id == ctx.author.id)
                 if str(r.emoji) == yes:
                     await self.submit_app(ctx, e, app['name'])
                 else:
                     return await x.edit(content="cancelled.")
示例#12
0
 async def positions(self, ctx):
     """List the current applications for this server"""
     if self.session is None:
         self.session = await self.d()
     data = json_mngr().read('./data/apps.json')
     if str(ctx.guild.id) not in data.keys():
         e = discord.Embed(description="This guild has no apps!",
                           color=discord.Color.dark_magenta())
         return await ctx.send(embed=e)
     else:
         content = ""
         ccontent = ""
         _open = discord.Embed(title="Open Applications:",
                               color=discord.Color.green())
         for app in data[str(ctx.guild.id)]['open'][:25]:
             _open.add_field(name=app['name'],
                             value=app['value'],
                             inline=True)
             content += f"App Name: {app['name']}\nApp Value: {app['value']}\n\n"
         if len(_open) > 6000:
             _open.clear_fields()
             url = await self.post(content)
             url = f'https://mystb.in/{url["key"]}.md'
             _open.description = f"Too many characters to display, so i put it in the url! click my title."
             _open.url = url
         closed = discord.Embed(title="closed applications:",
                                color=discord.Color.red())
         for app in data[str(ctx.guild.id)]['closed'][:25]:
             closed.add_field(name=app['name'],
                              value=app['value'],
                              inline=True)
             ccontent += f"App Name: {app['name']}\nApp Value: {app['value']}\n\n"
         if len(closed) > 6000:
             closed.clear_fields()
             url = await self.post(content)
             url = f'https://mystb.in/{url["key"]}.md'
             closed.description = f"Too many characters to display, so i put it in the url! click my title."
             closed.url = url
         await ctx.send(embed=_open)
         await ctx.send(embed=closed)
示例#13
0
 async def guildbancheck(self):
     data = json_mngr().read('./data/allowed_guilds.json')
     for guild in self.bot.guilds:
         if guild.id not in data['whitelist']:
             try:
                 await guild.owner.send(
                     f"Sorry, but your guild ({guild.name}) is not whitelisted, so i left.\nif this is a mistake"
                     ", please contanct my developer.\n\nNot a mistake, but still want me? go"
                     "to http://dragdev.xyz/ya/beta-join.html and request acces!"
                 )
             except:
                 pass
             finally:
                 await guild.leave()
             channel = self.bot.get_channel(606993571014377474)
             if channel is None:
                 print(
                     f"left unauthorized guild: {guild.name} {guild.owner} {guild.id}"
                 )
             else:
                 await channel.send(
                     f"left {guild.name} ({guild.id}) {guild.owner} for: unauthorized "
                 )
             continue
示例#14
0
import discord, base64, typing, traceback, time

import manager
import helper
from discord.ext import commands, tasks

data = manager.json_mngr().read('./prefixes.json')
prefixf = open('./token', 'r')
prefix = prefixf.readlines()
prefix = base64.b64encode(bytes(prefix[0], 'utf-8'))
prefixf.close()


def get_prefix(b0t, message):
    return commands.when_mentioned_or("ym!" if str(
        message.guild.id) not in data.keys() else data[str(message.guild.id)])(
            b0t, message)


bot = commands.AutoShardedBot(command_prefix=get_prefix,
                              case_insensitive=True,
                              help_command=commands.MinimalHelpCommand(),
                              owner_id=421698654189912064)
bot.last_tb = 'nerd, im bug free so far!'
print("+===+ STATUS +===+")


@bot.event
async def on_shard_ready(shard):
    print("|Shard {}:ONLINE|".format(shard))