Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.70 KB | None | 0 0
  1. import os
  2. import discord
  3. from discord.ext import commands
  4. from cogs.utils.dataIO import dataIO
  5. from cogs.utils import checks
  6. client = discord.Client()
  7.  
  8. class bugreport:
  9. """Custom Cog for bugs"""
  10. def __init__(self, bot):
  11. self.bot = bot
  12. self.settings = dataIO.load_json('data/bugreport/settings.json')
  13. for s in self.settings:
  14. self.settings[s]['usercache'] = []
  15. def save_json(self):
  16. dataIO.save_json("data/bugreport/settings.json", self.settings)
  17.  
  18. @commands.group(name="bugset", pass_context=True, no_pm=True)
  19. async def appset(self, ctx):
  20. """configuration settings"""
  21. if ctx.invoked_subcommand is None:
  22. await self.bot.send_cmd_help(ctx)
  23. def initial_config(self, server_id):
  24. """makes an entry for the server, defaults to turned off"""
  25. if server_id not in self.settings:
  26. self.settings[server_id] = {'inactive': True,
  27. 'output': [],
  28. 'cleanup': False,
  29. 'usercache': [],
  30. 'multiout': False
  31. }
  32. self.save_json()
  33.  
  34. @checks.admin_or_permissions(Manage_server=True)
  35. @appset.command(name="reset", pass_context=True, no_pm=True)
  36. async def fix_cache(self, ctx):
  37. """Reset cache for applications"""
  38. server = ctx.message.server
  39. self.initial_config(ctx.message.server.id)
  40. self.settings[server.id]['usercache'] = []
  41. self.save_json()
  42. await self.bot.say("Cache has been reset")
  43.  
  44. @checks.admin_or_permissions(Manage_server=True)
  45. @appset.command(name="roles", pass_context=True, no_pm=True)
  46. async def rolecreation(self, ctx):
  47. server = ctx.message.server
  48. author = ctx.message.author
  49. aprole = discord.utils.get(server.roles, name="Staff")
  50. if aprole not in server.roles:
  51. await self.bot.create_role(server, name="Staff")
  52. await self.bot.say("All done!")
  53. else:
  54. await self.bot.say("Roles already present")
  55.  
  56. @checks.admin_or_permissions(Manage_server=True)
  57. @appset.command(name="channel", pass_context=True, no_pm=True)
  58. async def setoutput(self, ctx, chan=None):
  59. """sets the place to output application embed to when finished."""
  60. server = ctx.message.server
  61. if server.id not in self.settings:
  62. self.initial_config(server.id)
  63. if chan in self.settings[server.id]['output']:
  64. return await self.bot.say("Channel already set as output")
  65. for channel in server.channels:
  66. if str(chan) == str(channel.id):
  67. if self.settings[server.id]['multiout']:
  68. self.settings[server.id]['output'].append(chan)
  69. self.save_json()
  70. return await self.bot.say("Channel added to output list")
  71. else:
  72. self.settings[server.id]['output'] = [chan]
  73. self.save_json()
  74. return await self.bot.say("Channel set as output")
  75. await self.bot.say("I could not find a channel with that id")
  76.  
  77. @checks.admin_or_permissions(Manage_server=True)
  78. @appset.command(name="toggle", pass_context=True, no_pm=True)
  79. async def reg_toggle(self, ctx):
  80. """Toggles applications for the server"""
  81. server = ctx.message.server
  82. if server.id not in self.settings:
  83. self.initial_config(server.id)
  84. self.settings[server.id]['inactive'] = \
  85. not self.settings[server.id]['inactive']
  86. self.save_json()
  87. if self.settings[server.id]['inactive']:
  88. await self.bot.say("Registration disabled.")
  89. else:
  90. await self.bot.say("Registration enabled.")
  91.  
  92.  
  93. @commands.command(name="bugreport", pass_context=True, aliases=['reportbug'])
  94. async def application(self, ctx):
  95. """"make an application by following the prompts"""
  96. author = ctx.message.author
  97. server = ctx.message.server
  98. aprole = discord.utils.get(server.roles, name="Staff")
  99. if server.id not in self.settings:
  100. return await self.bot.say("Contact DerpDays!")
  101. if self.settings[server.id]['inactive']:
  102. return await self.bot.say("We are not currently accepting applications, Try again later")
  103. if aprole in author.roles:
  104. await self.bot.say("{} You cannot submit a bug".format(author.mention))
  105. else:
  106. while True:
  107. avatar = author.avatar_url if author.avatar \
  108. else author.default_avatar_url
  109. em = discord.Embed(timestamp=ctx.message.timestamp, title="ID: {}".format(author.id), color=0xff5357)
  110. em.set_author(name='Bug Report by {}'.format(author.name), icon_url=avatar)
  111. 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))
  112. while True:
  113. how = await self.bot.wait_for_message(channel=howmsg.channel, author=author, timeout=600)
  114. if how is None:
  115. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
  116. break
  117. else:
  118. em.add_field(name="Before: ", value=how.content, inline=True)
  119. break
  120. if how is None:
  121. break
  122. reproducemsg = await self.bot.send_message(author, embed=discord.Embed(title="Reproduce", description="Can you reproduce said bug/glitch? If so how", color=0xff5357))
  123. while True:
  124. reproduce = await self.bot.wait_for_message(channel=reproducemsg.channel, author=author, timeout=600)
  125. if reproduce is None:
  126. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
  127. break
  128. else:
  129. em.add_field(name="Reproducable:", value=reproduce.content, inline=True)
  130. break
  131. if reproduce is None:
  132. break
  133. modsmsg = await self.bot.send_message(author, embed=discord.Embed(title="Mods", description="What mods are involved in this bug/glitch?", color=0xff5357))
  134. while True:
  135. mods = await self.bot.wait_for_message(channel=modsmsg.channel, author=author, timeout=600)
  136. if mods is None:
  137. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
  138. break
  139. else:
  140. em.add_field(name="Mods Involved: ", value=mods.content, inline=True)
  141. break
  142. if mods is None:
  143. break
  144. dimmsg = await self.bot.send_message(author, embed=discord.Embed(title="Dimension", description="What dimension were you in?", color=0xff5357))
  145. while True:
  146. dim = await self.bot.wait_for_message(channel=dimmsg.channel, author=author, timeout=600)
  147. if dim is None:
  148. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
  149. break
  150. else:
  151. em.add_field(name="Dimension:", value=dim.content, inline=False)
  152. break
  153. if dim is None:
  154. break
  155. servermsg = await self.bot.send_message(author, embed=discord.Embed(title="Server", description="What server were you on?", color=0xff5357))
  156. while True:
  157. server = await self.bot.wait_for_message(channel=servermsg.channel, author=author, timeout=600)
  158. if server is None:
  159. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You have reached the time limit, please try again!", color=0xff5357))
  160. break
  161. else:
  162. em.add_field(name="Server:", value=server.content, inline=False)
  163. await self.bot.send_message(author, embed=discord.Embed(title="Finished", description="Thank you for reporting a bug!", color=0xff5357))
  164. break
  165. if server is None:
  166. break
  167. for output in self.settings[server.id]['output']:
  168. where = server.get_channel(output)
  169. if where != None:
  170. botmsg = await self.bot.send_message(where, embed=em)
  171. await self.bot.add_reaction(botmsg, "👍")
  172. await self.bot.add_reaction(botmsg, "👎")
  173. break
  174. break
  175. return
  176.  
  177. def check_folder():
  178. f = 'data/bugreport'
  179. if not os.path.exists(f):
  180. os.makedirs(f)
  181.  
  182.  
  183. def check_file():
  184. f = 'data/bugreport/settings.json'
  185. if dataIO.is_valid_json(f) is False:
  186. dataIO.save_json(f, {})
  187.  
  188. def setup(bot):
  189. check_folder()
  190. check_file()
  191. n = bugreport(bot)
  192. bot.add_cog(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement