Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import discord
  2. import asyncio
  3. from discord.ext import commands
  4. from random import randint
  5. from random import choice
  6. from .utils.dataIO import dataIO
  7. from .utils import checks
  8. from .utils.chat_formatting import box
  9.  
  10. __author__ = "SinisterPyro"
  11.  
  12. DEFAULTS = {"CHANCE" : 300,}
  13.  
  14. class Supposedly:
  15. """Supposedly Addon"""
  16.  
  17. def __init__(self, bot):
  18. self.bot = bot
  19. self.file_path = "data/supposedly/settings.json"
  20. settings = dataIO.load_json(self.file_path)
  21. self.settings = defaultdict(lambda: DEFAULTS.copy(), settings)
  22.  
  23. @commands.group(pass_context=True, no_pm=True)
  24. @checks.mod_or_permissions(administrator=True)
  25. async def supposedlyset(self, ctx):
  26. """Change supposedly settings"""
  27. server = ctx.message.server
  28. if ctx.invoked_subcommand is None:
  29. settings = self.settings[server.id]
  30. msg = box("Supposedly chance 1 in {CHANCE}\n"
  31. "".format(**settings))
  32. msg += "\nSee {}help supposedlyset to edit the settings".format(ctx.prefix)
  33. await self.bot.say(msg)
  34.  
  35. @triviaset.command(pass_context=True)
  36. async def chance(self, ctx, chance):
  37. server = ctx.message.server
  38. self.settings[server.id]["CHANCE"] = chance
  39. self.save_settings()
  40. await self.bot.say("Chance set to 1 of {}".format(chance))
  41.  
  42.  
  43. async def on_message(self, message):
  44. server = message.server
  45. channel = message.channel
  46. author = message.author
  47. randomInt = randint(0, self.settings["CHANCE"])
  48. if message.server is None:
  49. return
  50. if author == self.bot.user:
  51. return
  52. if randomInt == 0:
  53. await self.bot.send_message(channel, "*Supposedly...*")
  54.  
  55.  
  56. def check_folders():
  57. folders = ("data", "data/supposedly/")
  58. for folder in folders:
  59. if not os.path.exists(folder):
  60. print("Creating " + folder + " folder...")
  61. os.makedirs(folder)
  62.  
  63.  
  64. def check_files():
  65. if not os.path.isfile("data/supposedly/settings.json"):
  66. print("Creating empty settings.json...")
  67. dataIO.save_json("data/supposedly/settings.json", {})
  68.  
  69.  
  70. def setup(bot):
  71. check_folders()
  72. check_files()
  73. bot.add_cog(Supposedly(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement