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.65 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.  
  7.  
  8. class staffapp:
  9. """Custom Cog for applications"""
  10. def __init__(self, bot):
  11. self.bot = bot
  12. self.settings = dataIO.load_json('data/staffapp/settings.json')
  13. for s in self.settings:
  14. self.settings[s]['usercache'] = []
  15. def save_json(self):
  16. dataIO.save_json("data/staffapp/settings.json", self.settings)
  17.  
  18. @commands.group(name="staffset", 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 Applicant")
  50. if aprole not in server.roles:
  51. await self.bot.create_role(server, name="Staff Applicant")
  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. @commands.command(name="apply", pass_context=True)
  93. async def application(self, ctx):
  94. """"make an application by following the prompts"""
  95. author = ctx.message.author
  96. server = ctx.message.server
  97. aprole = discord.utils.get(server.roles, name="Staff Applicant")
  98. if server.id not in self.settings:
  99. return await self.bot.say("Contact DerpDays!")
  100. if self.settings[server.id]['inactive']:
  101. return await self.bot.say("We are not currently accepting applications, Try again later")
  102. if aprole in author.roles:
  103. await self.bot.say("{} You have already applied!".format(author.mention))
  104. else:
  105. while True:
  106. avatar = author.avatar_url if author.avatar \
  107. else author.default_avatar_url
  108. em = discord.Embed(timestamp=ctx.message.timestamp, title="ID: {}".format(author.id), color=0xff5357)
  109. em.set_author(name='Staff Application for {}'.format(author.name), icon_url=avatar)
  110. agemsg = await self.bot.send_message(author, embed=discord.Embed(title="Age", description="What is your age?", color=0xff5357))
  111. while True:
  112. age = await self.bot.wait_for_message(channel=agemsg.channel, author=author, timeout=600)
  113. if age is None:
  114. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You ran out of time try again!", color=0xff5357))
  115. break
  116. else:
  117. em.add_field(name="Age: ", value=age.content, inline=True)
  118. break
  119. if age is None:
  120. break
  121. timemsg = await self.bot.send_message(author, embed=discord.Embed(title="Timezone", description="What timezone are you in? (Google is your friend!)", color=0xff5357))
  122. while True:
  123. time = await self.bot.wait_for_message(channel=timemsg.channel, author=author, timeout=600)
  124. if time is None:
  125. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You ran out of time try again!", color=0xff5357))
  126. break
  127. else:
  128. em.add_field(name="Timezone:", value=time.content, inline=True)
  129. break
  130. if time is None:
  131. break
  132. nationmsg = await self.bot.send_message(author, embed=discord.Embed(title="Country", description="What country are you from?", color=0xff5357))
  133. while True:
  134. nation = await self.bot.wait_for_message(channel=nationmsg.channel, author=author, timeout=600)
  135. if nation is None:
  136. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You ran out of time try again!", color=0xff5357))
  137. break
  138. else:
  139. em.add_field(name="Country: ", value=nation.content, inline=True)
  140. em.add_field(name='Join Date', value=author.joined_at.__format__('%A, %d. %B %Y @ %H:%M:%S'))
  141. break
  142. if nation is None:
  143. break
  144. activemsg = await self.bot.send_message(author, embed=discord.Embed(title="Contribution", description="How many hours can you put into the server a day?", color=0xff5357))
  145. while True:
  146. active = await self.bot.wait_for_message(channel=activemsg.channel, author=author, timeout=600)
  147. if active is None:
  148. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You ran out of time try again!", color=0xff5357))
  149. break
  150. else:
  151. em.add_field(name="Active Hours per Day:", value=active.content, inline=False)
  152. break
  153. if active is None:
  154. break
  155. whymsg = await self.bot.send_message(author, embed=discord.Embed(title="Why you?", description="Explain why we should choose you!", color=0xff5357))
  156. while True:
  157. why = await self.bot.wait_for_message(channel=whymsg.channel, author=author, timeout=600)
  158. if why is None:
  159. await self.bot.send_message(author, embed=discord.Embed(title="Time", description="You ran out of time try again!", color=0xff5357))
  160. break
  161. else:
  162. em.add_field(name="Why do you want to be staff", value=why.content, inline=False)
  163. await self.bot.send_message(author, embed=discord.Embed(title="Finished", description="Thank you for applying for staff!", color=0xff5357))
  164. break
  165. if why is None:
  166. break
  167. for output in self.settings[server.id]['output']:
  168. where = server.get_channel(output)
  169. if where is not 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/staffapp'
  179. if not os.path.exists(f):
  180. os.makedirs(f)
  181.  
  182.  
  183. def check_file():
  184. f = 'data/staffapp/settings.json'
  185. if dataIO.is_valid_json(f) is False:
  186. dataIO.save_json(f, {})
  187.  
  188.  
  189. def setup(bot):
  190. check_folder()
  191. check_file()
  192. n = staffapp(bot)
  193. bot.add_cog(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement