Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. import asyncio
  4. import pickle
  5. import random
  6. import math
  7.  
  8. bot = commands.Bot(command_prefix='!')
  9.  
  10. class Data:
  11.  
  12. users = []
  13. stats = [[]]
  14.  
  15.  
  16.  
  17. @bot.command()
  18. async def resetstats(ctx):
  19.  
  20. if ctx.message.author == "214358195060080640":
  21. i()
  22.  
  23. def x():
  24. with open("users.pickle", 'rb') as f:
  25. data = pickle.load(f)
  26. f.close()
  27. return data
  28.  
  29. def i():
  30. data = Data
  31. with open("users.pickle", "wb") as f:
  32. pickle.dump(data, f)
  33. f.close()
  34.  
  35. @bot.command()
  36. async def profilesetup(ctx):
  37. username = str(ctx.message.author.id)
  38. with open("users.pickle", "rb") as f:
  39. data = pickle.load(f)
  40. f.close()
  41.  
  42. if (username in data.users):
  43. await ctx.send("Attempting to reroll your stats is cheating!")
  44. return
  45.  
  46. else:
  47. position = len(data.users)
  48. data.users.append(username)
  49. stats = []
  50. for i in range(0, 5):
  51. stats.append(roll4d6take3high())
  52. data.stats.append(stats)
  53. await ctx.send("```\n"
  54. "User: %s\n"
  55. "Strength = %d (%d)\n"
  56. "Agility = %d (%d)\n"
  57. "Accuracy = %d (%d)\n"
  58. "Perception = %d (%d)\n"
  59. "Stealth = %d (%d)\n"
  60. "```" % (ctx.message.author,
  61. addList(stats[0]), math.floor((addList(stats[0]) - 10) / 2),
  62. addList(stats[1]), math.floor((addList(stats[1]) - 10) / 2),
  63. addList(stats[2]), math.floor((addList(stats[2]) - 10) / 2),
  64. addList(stats[3]), math.floor((addList(stats[3]) - 10) / 2),
  65. addList(stats[4]), math.floor((addList(stats[4]) - 10) / 2)))
  66. with open("user.pickle", "wb") as f:
  67. pickle.dump(data, f)
  68. f.close()
  69.  
  70. def addList(list):
  71. tot = 0
  72. for i in list:
  73. tot += i
  74. return tot
  75.  
  76. def roll4d6take3high():
  77. rolls = [random.randrange(1, 6) for x in range(4)]
  78. lowest = 7
  79. lpos = 0
  80. for i in range(0, len(rolls) - 1):
  81. if (rolls[i] < lowest):
  82. lowest = i + 0
  83. lpos = i
  84. rolls.pop()
  85. return rolls
  86.  
  87. bot.run('token')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement