Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import discord
- from discord.ext import commands
- from cogs.utils.dataIO import dataIO
- from cogs.utils import checks
- client = discord.Client()
- class bugreport:
- """Custom Cog for bugs"""
- def __init__(self, bot):
- self.bot = bot
- self.settings = dataIO.load_json('data/bugreport/settings.json')
- for s in self.settings:
- self.settings[s]['usercache'] = []
- def save_json(self):
- dataIO.save_json("data/bugreport/settings.json", self.settings)
- @commands.group(name="bugset", pass_context=True, no_pm=True)
- async def appset(self, ctx):
- """configuration settings"""
- if ctx.invoked_subcommand is None:
- await self.bot.send_cmd_help(ctx)
- def initial_config(self, server_id):
- """makes an entry for the server, defaults to turned off"""
- if server_id not in self.settings:
- self.settings[server_id] = {'inactive': True,
- 'output': [],
- 'cleanup': False,
- 'usercache': [],
- 'multiout': False
- }
- self.save_json()
- @checks.admin_or_permissions(Manage_server=True)
- @appset.command(name="reset", pass_context=True, no_pm=True)
- async def fix_cache(self, ctx):
- """Reset cache for applications"""
- server = ctx.message.server
- self.initial_config(ctx.message.server.id)
- self.settings[server.id]['usercache'] = []
- self.save_json()
- await self.bot.say("Cache has been reset")
- @checks.admin_or_permissions(Manage_server=True)
- @appset.command(name="roles", pass_context=True, no_pm=True)
- async def rolecreation(self, ctx):
- server = ctx.message.server
- author = ctx.message.author
- aprole = discord.utils.get(server.roles, name="Staff")
- if aprole not in server.roles:
- await self.bot.create_role(server, name="Staff")
- await self.bot.say("All done!")
- else:
- await self.bot.say("Roles already present")
- @checks.admin_or_permissions(Manage_server=True)
- @appset.command(name="channel", pass_context=True, no_pm=True)
- async def setoutput(self, ctx, chan=None):
- """sets the place to output application embed to when finished."""
- server = ctx.message.server
- if server.id not in self.settings:
- self.initial_config(server.id)
- if chan in self.settings[server.id]['output']:
- return await self.bot.say("Channel already set as output")
- for channel in server.channels:
- if str(chan) == str(channel.id):
- if self.settings[server.id]['multiout']:
- self.settings[server.id]['output'].append(chan)
- self.save_json()
- return await self.bot.say("Channel added to output list")
- else:
- self.settings[server.id]['output'] = [chan]
- self.save_json()
- return await self.bot.say("Channel set as output")
- await self.bot.say("I could not find a channel with that id")
- @checks.admin_or_permissions(Manage_server=True)
- @appset.command(name="toggle", pass_context=True, no_pm=True)
- async def reg_toggle(self, ctx):
- """Toggles applications for the server"""
- server = ctx.message.server
- if server.id not in self.settings:
- self.initial_config(server.id)
- self.settings[server.id]['inactive'] = \
- not self.settings[server.id]['inactive']
- self.save_json()
- if self.settings[server.id]['inactive']:
- await self.bot.say("Registration disabled.")
- else:
- await self.bot.say("Registration enabled.")
- @commands.command(name="bugreport", pass_context=True, aliases=['reportbug'])
- async def application(self, ctx):
- """"make an application by following the prompts"""
- author = ctx.message.author
- server = ctx.message.server
- aprole = discord.utils.get(server.roles, name="Staff")
- if server.id not in self.settings:
- return await self.bot.say("Contact DerpDays!")
- if self.settings[server.id]['inactive']:
- return await self.bot.say("We are not currently accepting applications, Try again later")
- if aprole in author.roles:
- await self.bot.say("{} You cannot submit a bug".format(author.mention))
- else:
- while True:
- avatar = author.avatar_url if author.avatar \
- else author.default_avatar_url
- em = discord.Embed(timestamp=ctx.message.timestamp, title="ID: {}".format(author.id), color=0xff5357)
- em.set_author(name='Bug Report by {}'.format(author.name), icon_url=avatar)
- howmsg = await self.bot.send_message(author, embed=discord.Embed(title="Before it happened", description="Can you explain in as much detail as possible of what you were doing prior to finding the bug/glitch.", color=0xff5357))
- while True:
- how = await self.bot.wait_for_message(channel=howmsg.channel, author=author, timeout=600)
- if how is None:
- await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
- break
- else:
- em.add_field(name="Before: ", value=how.content, inline=True)
- break
- if how is None:
- break
- reproducemsg = await self.bot.send_message(author, embed=discord.Embed(title="Reproduce", description="Can you reproduce said bug/glitch? If so how", color=0xff5357))
- while True:
- reproduce = await self.bot.wait_for_message(channel=reproducemsg.channel, author=author, timeout=600)
- if reproduce is None:
- await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
- break
- else:
- em.add_field(name="Reproducable:", value=reproduce.content, inline=True)
- break
- if reproduce is None:
- break
- modsmsg = await self.bot.send_message(author, embed=discord.Embed(title="Mods", description="What mods are involved in this bug/glitch?", color=0xff5357))
- while True:
- mods = await self.bot.wait_for_message(channel=modsmsg.channel, author=author, timeout=600)
- if mods is None:
- await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
- break
- else:
- em.add_field(name="Mods Involved: ", value=mods.content, inline=True)
- break
- if mods is None:
- break
- dimmsg = await self.bot.send_message(author, embed=discord.Embed(title="Dimension", description="What dimension were you in?", color=0xff5357))
- while True:
- dim = await self.bot.wait_for_message(channel=dimmsg.channel, author=author, timeout=600)
- if dim is None:
- await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
- break
- else:
- em.add_field(name="Dimension:", value=dim.content, inline=False)
- break
- if dim is None:
- break
- servermsg = await self.bot.send_message(author, embed=discord.Embed(title="Server", description="What server were you on?", color=0xff5357))
- while True:
- server = await self.bot.wait_for_message(channel=servermsg.channel, author=author, timeout=600)
- if server is None:
- await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
- break
- else:
- em.add_field(name="Server:", value=server.content, inline=False)
- await self.bot.send_message(author, embed=discord.Embed(title="Finished", description="Thank you for reporting a bug!", color=0xff5357))
- break
- if server is None:
- break
- for output in self.settings[server.id]['output']:
- where = server.get_channel(output)
- if where != None:
- botmsg = await self.bot.send_message(where, embed=em)
- await self.bot.add_reaction(botmsg, "👍")
- await self.bot.add_reaction(botmsg, "👎")
- break
- break
- return
- def check_folder():
- f = 'data/bugreport'
- if not os.path.exists(f):
- os.makedirs(f)
- def check_file():
- f = 'data/bugreport/settings.json'
- if dataIO.is_valid_json(f) is False:
- dataIO.save_json(f, {})
- def setup(bot):
- check_folder()
- check_file()
- n = bugreport(bot)
- bot.add_cog(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement