Advertisement
Dori_mon

Untitled

Jul 10th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. from test.test_nntplib import bypass_context
  4. from discord.ext.commands.core import command
  5. from discord import ChannelType
  6. import json
  7. import datetime
  8. import os.path
  9.  
  10. DEBUG = False
  11.  
  12. TOKEN = 'NDY1NjE0MTc2NzI3OTkwMjc0.DiQEmg.t-_CuKCS9-blBeBu_NsaluHz-Fo'
  13. PARTNER_CHANNEL_ID = '466029217969209346'
  14. COLOUR = 0x4286f4
  15.  
  16. partners = {}
  17.  
  18. questions = ['Please provide an invite link to your server.', 'Why do you want to partner?', 'How can we benefit from partnering with you?']
  19.  
  20. bot = commands.Bot(command_prefix = '-')
  21.  
  22. if not os.path.isfile('partners-data.json'):
  23. with open('partners-data.json', 'w+') as fp:
  24. json.dump({}, fp)
  25.  
  26. with open('partners-data.json', 'r') as fp:
  27. partners = json.load(fp)
  28.  
  29. async def send_embed(destination, embed, content = None, member = None):
  30. if member is None:
  31. embed.set_footer(text = bot.user.name, icon_url = bot.user.avatar_url)
  32. else:
  33. embed.set_footer(text = str(member), icon_url = member.avatar_url)
  34. embed.colour = COLOUR
  35. embed.timestamp = datetime.datetime.now()
  36. return await bot.send_message(destination, embed = embed, content = content)
  37.  
  38. @bot.event
  39. async def on_ready():
  40. await bot.change_presence(game = discord.Game(name = '{}partner | Made by Dori_mon#0001'.format(bot.command_prefix)))
  41. if DEBUG : print (discord.__version__)
  42. print('Bot is ready.')
  43.  
  44. @bot.event
  45. async def on_reaction_add(reaction, user):
  46. if DEBUG : print('reaction')
  47. if user.bot:
  48. return
  49.  
  50. message = reaction.message
  51.  
  52. if message.channel.type != ChannelType.private:
  53. return
  54.  
  55. if reaction.emoji == '✅':
  56. if DEBUG : print('emoji equals')
  57. if partners[user.id]['stage'] == message.id:
  58. if DEBUG : print('status equals')
  59. desc = ''
  60. for x in range(0, len(partners[user.id]['answers'])):
  61. question = list(partners[user.id]['answers'].keys())[x]
  62. answer = partners[user.id]['answers'][question]
  63. desc += '\n\n{}. {}'.format(x+1, question)
  64. desc += '\n**Your answer:** {}'.format(answer)
  65. await send_embed(bot.get_channel(PARTNER_CHANNEL_ID), content = 'New form submitted by {}.'.format(user.mention), member = user, embed = discord.Embed(title = 'Partnership', description = desc))
  66. await send_embed(user, member = user, embed = discord.Embed(title = 'Success!', description = 'Successfully submitted the form!'))
  67.  
  68. @bot.event
  69. async def on_message(message):
  70. if message.channel.type == ChannelType.private:
  71. member = message.author
  72. content = message.content
  73.  
  74. if content.lower() == 'cancel':
  75. if DEBUG : print('Cancelled')
  76. partners.pop(member.id, None)
  77. with open('partners-data.json', 'w+') as fp:
  78. json.dump(partners, fp)
  79. await send_embed(message.channel, embed = discord.Embed(title = 'Success!', description = 'Successfully cancelled! If you\'d like to submit another form do `{}partner` again.'.format(bot.command_prefix)))
  80. return
  81.  
  82. if member.id in partners:
  83. if DEBUG : print('member in partners')
  84. if partners[member.id]['stage'] in questions:
  85. if DEBUG : print('stage {}'.format(partners[member.id]['stage']))
  86. partners[member.id]['answers'][partners[member.id]['stage']] = content
  87. with open('partners-data.json', 'w+') as fp:
  88. json.dump(partners, fp)
  89. if len(partners[member.id]['answers']) < len(questions):
  90. partners[member.id]['stage'] = questions[len(partners[member.id]['answers'])]
  91. with open('partners-data.json', 'w+') as fp:
  92. json.dump(partners, fp)
  93. await send_embed(member, embed = discord.Embed(title = 'Partnership', description = partners[member.id]['stage']))
  94. else:
  95. desc = ''
  96. for x in range(0, len(partners[member.id]['answers'])):
  97. question = list(partners[member.id]['answers'].keys())[x]
  98. answer = partners[member.id]['answers'][question]
  99. desc += '\n\n{}. {}'.format(x+1, question)
  100. desc += '\n**Your answer:** {}'.format(answer)
  101. msg = await send_embed(member, member = member, content = 'We are done with the questions!\nTo submit the form please react with ✅ to this message.\nNOTE: Running the {}partner command again will override your current form!'.format(bot.command_prefix), embed = discord.Embed(title = 'Partnership', description = desc))
  102. partners[member.id]['status'] = 'waiting_for_reaction'
  103. partners[member.id]['stage'] = msg.id
  104. with open('partners-data.json', 'w+') as fp:
  105. json.dump(partners, fp)
  106. await bot.add_reaction(msg, '✅')
  107.  
  108. await bot.process_commands(message)
  109.  
  110. @bot.command(pass_context=True)
  111. async def partner(ctx, member: discord.Member = None):
  112. if member is None:
  113. member = ctx.message.author
  114. partners[member.id] = {}
  115. partners[member.id]['answers'] = {}
  116. partners[member.id]['stage'] = questions[0]
  117. with open('partners-data.json', 'w+') as fp:
  118. json.dump(partners, fp)
  119.  
  120. if ctx.message.channel.type != ChannelType.private:
  121. await send_embed(ctx.message.channel, embed = discord.Embed(title = 'Success!', description = 'Please check your DMs.'))
  122.  
  123. await send_embed(member, embed = discord.Embed(title = 'Partnership', description = partners[member.id]['stage']))
  124.  
  125. bot.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement