daily pastebin goal
21%
SHARE
TWEET

Untitled

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