Advertisement
qspitzer

joshua liu code v2

Dec 27th, 2017
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. import discord
  2. from discord.ext.commands import Bot
  3. import asyncio
  4. import random
  5. import json
  6. import os
  7.  
  8. bot = Bot(command_prefix='//')
  9.  
  10. @bot.event
  11. async def on_ready():
  12.         print('Logged in as')
  13.         print(bot.user.name)
  14.         print(bot.user.id)
  15.        
  16. @bot.command()
  17. async def test():
  18.     await bot.say("Successful")
  19.    
  20. @bot.command()
  21. async def applications(user=None):
  22.     userType = None
  23.     try:
  24.         user = int(user)
  25.         userType = 'number'
  26.     except:
  27.         userType = 'name'
  28.  
  29.     if user != None:
  30.         with open("apply_file.txt",'r') as apply_file:
  31.             dict = json.load(apply_file)
  32.         keyValues = dict.keys()
  33.         dictValues = dict.values()
  34.  
  35.         if userType == 'name':
  36.             application_list = list(dict.values())
  37.             for x in application_list:
  38.                 xValue = x
  39.                 list2 = x.partition("': '")
  40.                 list2 = list(list2)
  41.                 list2.remove("': '")
  42.                 #for y, z in list2:
  43.                 y = list2[0]
  44.                 z = list2[1]
  45.                 a = (y[2:])
  46.                 a1 = (z[:-2])
  47.                 if a == user:
  48.                     break
  49.             for x, y in zip(keyValues, dictValues):
  50.                 if y == xValue:
  51.                     keyValue = x
  52.  
  53.             e = discord.Embed(title="Application {0}".format(keyValue))
  54.             e.add_field(name="User", value=a)
  55.             e.add_field(name="Reason", value=a1)
  56.             await bot.say(embed=e)
  57.            
  58.  
  59.         elif userType == 'number':
  60.             keyValue = user
  61.             try:
  62.                 dictValue = dict[str(keyValue)]
  63.                 list2 = dictValue.partition("': '")
  64.                 list2 = list(list2)
  65.                 list2.remove("': '")
  66.                 #for y, z in list2:
  67.                 y = list2[0]
  68.                 z = list2[1]
  69.                 a = (y[2:])
  70.                 a1 = (z[:-2])
  71.                
  72.                 e = discord.Embed(title="Application {0}".format(keyValue))
  73.                 e.add_field(name="User", value=a)
  74.                 e.add_field(name="Reason", value=a1)
  75.                 await bot.say(embed=e)
  76.             except:
  77.                 await bot.say("{0} is not a valid ID".format(keyValue))
  78.                
  79.     else:
  80.         await bot.say("You need to specify a user or id!")
  81.        
  82.        
  83. @bot.command(pass_context=True)
  84. async def apply(ctx, *reason):
  85.     Reason = (' '.join(reason))
  86.     if Reason == '':
  87.         Reason = "No reason given"
  88.     #"id":["user":"reason"]
  89.     apply_list = {}
  90.     if os.path.isfile("apply_file.txt"):
  91.         with open("apply_file.txt",'r') as apply_file:
  92.             apply_list = json.load(apply_file)
  93.     ID = (len(apply_list) + 1)
  94.     info = str({ctx.message.author.name : Reason})
  95.     apply_list[ID] = info
  96.     with open("apply_file.txt", 'w') as apply_file:
  97.         json.dump(apply_list, apply_file)
  98.     await bot.say('Thank you, {0}. Your application has been submitted and will be reviewed later.'.format(ctx.message.author.mention))
  99.  
  100. bot.run('token')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement