async def warn(self, ctx, member: discord.Member): perms = await util.check_perms(self, ctx) if not perms: return serverWarnList = util.load_js( os.path.join("warns", "{}.json".format(ctx.message.server.id))) if member.id not in serverWarnList: serverWarnList[member.id] = 0 serverWarnList[member.id] += 1 if self.MAXWARNS - serverWarnList[member.id] > 1: await self.bot.say( "<@!{}>, you have been given a warning. You have {} warnings left." .format(member.id, self.MAXWARNS - serverWarnList[member.id])) elif serverWarnList[member.id] >= self.MAXWARNS: pass else: await self.bot.say( "<@!{}>, this is your final warning. One more warn and you will be banned." .format(member.id)) util.save_js( os.path.join("warns", "{}.json".format(ctx.message.server.id)), serverWarnList) if serverWarnList[member.id] >= self.MAXWARNS: await self.bot.ban(member) await self.bot.say( "<@!{}> has been banned from the server for getting {} warnings." .format(member.id, self.MAXWARNS))
async def addHug(self, ctx, *, url: str = ""): util.nullifyExecute() perms = await util.check_perms(self, ctx) if not perms: return pics = util.load_js(os.path.join("assets", "hug.json")) if url == "": await self.bot.say("Please provide a url.") elif not url.startswith("http"): await self.bot.say("Please provide a valid url.") elif url.startswith("https://i.imgur.com/"): pics.append(url) util.save_js("assets/hug.json", pics) await self.bot.say("Successfully added " + link + " to hugs.json") else: try: payload = {"image": url, "type": "URL"} headers = {"Authorization": "Client-ID 2397de93cc488b8"} r = requests.post("https://api.imgur.com/3/image", headers=headers, data=payload) link = r.json()["data"]["link"] pics.append(link) util.save_js("assets/hug.json", pics) await self.bot.say("Successfully added " + link + " to hugs.json") except: await self.bot.say("nope")
async def blacklist(self, ctx, member: discord.Member, *, reason: str = "None given."): perms = await util.check_perms(self, ctx) if not perms: return if len(self.blacklistList) == 0: self.blacklistList = [] for user in self.blacklistList: if str(member.id) == str(user["id"]): await self.bot.say( "{} is already in the bot's blacklist.".format(member.name) ) return self.blacklistList.append({"id": member.id, "reason": reason}) util.save_js("blacklist.json", self.blacklistList) await self.bot.say( "**{}**, you have been blacklisted from using the bot. Reason: {}" .format(member.mention, reason))
async def disableCommand(self, ctx, passedCommand: str): util.nullifyExecute() perms = await util.check_perms(self, ctx) if not perms: return disabledCommands = util.load_js("disabled-commands.json") if len(disabledCommands) == 0: disabledCommands = [] if passedCommand == "disableCommand" or passedCommand == "enableCommand": await self.bot.say("That command cannot be disabled.") return for command in self.bot.commands: if command == passedCommand: disabledCommands.append({ "command": passedCommand, "server-id": ctx.message.server.id }) util.save_js("disabled-commands.json", disabledCommands) await self.bot.say("{}{} has been disabled.".format( self.bot.command_prefix, passedCommand)) return await self.bot.say("The {}{} command does not exist!".format( self.bot.command_prefix, passedCommand))
async def enableExplanations(self, ctx): """Enable explanations when doing Tarot Readings.""" if ctx.message.server.id not in self.server_decks: self.server_decks[ctx.message.server.id] = {} self.server_decks[ctx.message.server.id]["explanations-enabled"] = True util.save_js("server-deck-tarot.json", self.server_decks) await self.bot.say(":thumbsup: OK, explanations will be enabled when doing tarot readings.")
async def disableLogging(self, ctx): perms = await util.check_perms(self, ctx) if not perms: return logLog = util.load_js("logs/server-list.json") logLog.remove(ctx.message.server.id) util.save_js("logs/server-list.json", logLog) await self.bot.say("Logging for this server has been disabled.")
async def deleteNote(self, ctx, member: discord.Member, *, note: str = None): perms = await util.check_perms(self, ctx) if not perms: return if ctx.message.author.id == self.bot.user.id: return await self.bot.delete_message(ctx.message) if note == None: await self.bot.say("Please provide a note number.") return serverNoteList = util.load_js( os.path.join("notes", "{}.json".format(ctx.message.server.id))) if member.id not in serverNoteList or serverNoteList[ member.id]["noteNum"] == 0: await self.bot.say("That user doesn't have any notes.") return noteNum = str(serverNoteList[member.id]["noteNum"]) if note > noteNum: await self.bot.say("That user doesn't have that many notes.") return if serverNoteList[member.id]["noteNum"] <= 1: serverNoteList.pop(member.id, None) for i in range(int(note), serverNoteList[member.id]["noteNum"]): for key, item in serverNoteList[member.id].items(): if key == "noteNum": continue if serverNoteList[member.id]["noteNum"] == 1: serverNoteList[member.id][key].pop(str(i), None) else: serverNoteList[member.id][key][str(i)] = serverNoteList[ member.id][key][str(i + 1)] """ try: serverNoteList[member.id]["note"][str(i)]=serverNoteList[member.id]["note"][str(i+1)] serverNoteList[member.id]["name"][str(i)]=serverNoteList[member.id]["name"][str(i+1)] serverNoteList[member.id]["time"][str(i)]=serverNoteList[member.id]["time"][str(i+1)] serverNoteList[member.id]["issuer"][str(i)]=serverNoteList[member.id]["issuer"][str(i+1)] serverNoteList[member.id]["issuerName"][str(i)]=serverNoteList[member.id]["issuerName"][str(i+1)] except KeyError: serverNoteList[member.id]["noteNum"]-=1 util.save_js(os.path.join("notes", "{}.json".format(ctx.message.server.id)), serverNoteList) return """ util.save_js( os.path.join("notes", "{}.json".format(ctx.message.server.id)), serverNoteList)
async def disableExplanations(self, ctx): util.nullifyExecute() """Disable explanations when doing Tarot Readings.""" if ctx.message.server.id not in self.server_decks: self.server_decks[ctx.message.server.id] = {} self.server_decks[ ctx.message.server.id]["explanations-enabled"] = False util.save_js("server-deck-tarot.json", self.server_decks) await self.bot.say( ":thumbsup: OK, explanations will be disabled when doing tarot readings." )
async def enableLogging(self, ctx): perms = await util.check_perms(self, ctx) if not perms: return logLog = util.load_js("logs/server-list.json") if len(logLog) == 0: logLog = [] logLog.append(ctx.message.server.id) util.save_js("logs/server-list.json", logLog) await self.bot.say("Logging for this server has been enabled.")
async def beanRegister(self, ctx): util.nullifyExecute() if os.path.isfile(os.path.join("assets", "bean.json")): beanlist = util.load_js(os.path.join("assets", "bean.json")) else: beanlist = [] for user in beanlist: if str(ctx.message.author.id) == str(user["id"]): await self.bot.say("{} is already in the beanlist.".format( ctx.message.author.name)) return beanlist.append({"id": ctx.message.author.id}) util.save_js("assets/bean.json", beanlist) await self.bot.say( "**{}**, you have been added to the beanlist.".format( ctx.message.author.mention))
async def noOneCaresDisable(self, ctx): """Getting annoyed? No one cares, but are you?""" perms = util.check_perms(self, ctx) if not perms: return conf = util.load_js("config.json") try: conf["noOneCaresDisabled"].append(ctx.message.server.id) except KeyError: conf["noOneCaresDisabled"] = [] conf["noOneCaresDisabled"].append(ctx.message.server.id) util.save_js("config.json", conf) await self.bot.say( "The 'no one cares' reaction has been disabled for this server.")
async def fDisable(self, ctx): "Don't want SpongeBob's ugly mug staring you down every time you pay your respects? Use this. Requires special perms." perms = await util.check_perms(self, ctx) if not perms: return conf = util.load_js("config.json") try: conf["fDisabled"].append(ctx.message.server.id) except KeyError: conf["fDisabled"] = [] conf["fDisabled"].append(ctx.message.server.id) util.save_js("config.json", conf) await self.bot.say("F Reactions have been disabled.")
async def unblacklist(self, ctx, member: discord.Member): perms = await util.check_perms(self, ctx) if not perms: return for user in self.blacklistList: if str(member.id) == str(user["id"]): self.blacklistList.remove(user) util.save_js("blacklist.json", self.blacklistList) await self.bot.say( "**{}**, you have been removed from the bot's blacklist". format(member.mention)) return await self.bot.say("{} is not in the bot's blacklist".format( member.name))
async def wlsRemoveRole(self, ctx, role: discord.Role): perms = await util.check_perms(self, ctx) if not perms: return if role.id in self.whitelist["roles"]: self.whitelist["roles"].remove(role.id) util.save_js("whitelist.json", self.whitelist) await self.bot.say( "Members with the **{}** have been removed from the bot's whitelist." .format(role.mention)) return else: await self.bot.say( "The {} role isn't in this bot's whitelist.".format(role.name)) return
async def wlsRemoveUser(self, ctx, member: discord.Member): perms = await util.check_perms(self, ctx) if not perms: return if member.id in self.whitelist["users"]: self.whitelist["users"].remove(member.id) util.save_js("whitelist.json", self.whitelist) await self.bot.say( "**{}**, you have been removed from the bot's whitelist.". format(member.mention)) return else: await self.bot.say("{} isn't in this bot's whitelist.".format( member.name)) return
async def setDeck(self, ctx, deckName): """Set the Tarot Deck to use in readings (Rider-Waite only for now)""" # simple formatting origDeckName = deckName deckName = deckName.lower() deckName = deckName.replace(" ", "-") if os.path.exists(os.path.join("assets", "tarot", "{}.json".format(deckName))): if ctx.message.server.id not in self.server_decks: self.server_decks[ctx.message.server.id] = {} self.server_decks[ctx.message.server.id]["deck"] = "{}.json".format(deckName) util.save_js("server-deck-tarot.json", self.server_decks) await self.bot.say(":thumbsup: Set readings in this server to use the {} deck.".format(origDeckName)) else: await self.bot.say(":thumbsdown: That deck doesn't seem to exist. You'll be able to create and upload your own deck soon, though! Type '{}makeDeck' for more info.".format(self.bot.command_prefix))
async def unwarn(self, ctx, member : discord.Member, amount : int = 1): util.nullifyExecute() perms = await util.check_perms(self, ctx) if not perms: return serverWarnList = util.load_js(os.path.join("warns", "{}.json".format(ctx.message.server.id))) if member.id not in serverWarnList or serverWarnList[member.id] <= 0: await self.bot.say("{} does not currently have any warns".format(member.name)) return if amount > self.MAXWARNS: amount = self.MAXWARNS serverWarnList[member.id] -= amount await self.bot.say("<@!{}>, you have had {} warns removed. {} warnings remain.".format(member.id, amount, self.MAXWARNS - serverWarnList[member.id])) util.save_js(os.path.join("warns", "{}.json".format(ctx.message.server.id)), serverWarnList)
async def wlsAddUser(self, ctx, member: discord.Member): """Adds a user to the whitelist. This requires special perms""" perms = await util.check_perms(self, ctx) if not perms: return if str(member.id) in self.whitelist["users"]: await self.bot.say("{} is already in the bot's whitelist.".format( member.name)) return self.whitelist["users"].append(member.id) util.save_js("whitelist.json", self.whitelist) await self.bot.say( "**{}**, you have been added to the bot's whitelist! You now have access to special commands!" .format(member.mention)) return
async def beanUnregister(self, ctx): util.nullifyExecute() if os.path.isfile(os.path.join("assets", "bean.json")): beanlist = util.load_js(os.path.join("assets", "bean.json")) else: await self.bot.say("**{}**, you aren't on the beanlist.".format( ctx.message.author.mention)) return for user in beanlist: if str(ctx.message.author.id) == str(user["id"]): beanlist.remove(user) util.save_js("assets/bean.json", beanlist) await self.bot.say( "**{}**, you have been removed from beanlist.".format( ctx.message.author.mention)) return await self.bot.say("{}, you aren't on the beanlist.".format( ctx.message.author.name))
async def wipeNote(self, ctx, *, confirm : str = None): util.nullifyExecute() perms = await util.check_perms(self, ctx) if not perms: return if ctx.message.author.id == self.bot.user.id: return serverNoteList = util.load_js(os.path.join("notes", "{}.json".format(ctx.message.server.id))) key=hashlib.sha256(str(serverNoteList).encode("utf-8")).hexdigest() if confirm==key: await self.bot.say("Emergency note backup.") await self.bot.upload(os.path.join("notes", "{}.json".format(ctx.message.server.id))) serverNoteList={} util.save_js(os.path.join("notes", "{}.json".format(ctx.message.server.id)), serverNoteList) await self.bot.say("All notes have been wiped.") return else: await self.bot.say("To wipe the notes, you must enter the correct key.") return
async def wlsAddRole(self, ctx, role: discord.Role): """Adds a role to the whitelist. This requires special perms.""" perms = await util.check_perms(self, ctx) if not perms: return if str(role.id) in self.whitelist["roles"]: await self.bot.say( "The {} role is already in the bot's whitelist.".format( role.name)) return self.whitelist["roles"].append(role.id) util.save_js("whitelist.json", self.whitelist) await self.bot.say( "All members with the **{}** role now have access to this bot's special commands!" .format(role.mention)) return
async def fEnable(self, ctx): "Enables the bot to react accordingly whenever you pay your respects. Requires special perms." perms = await util.check_perms(self, ctx) if not perms: return conf = util.load_js("config.json") try: conf["fDisabled"].remove(ctx.message.server.id) except KeyError: await self.bot.say("F Reactions are already enabled.") return except ValueError: await self.bot.say("F Reactions are already enabled.") return util.save_js("config.json", conf) await self.bot.say("F Reactions have been enabled.")
async def note(self, ctx, member: discord.Member, *, note: str = None): perms = await util.check_perms(self, ctx) if not perms: return if ctx.message.author.id == self.bot.user.id: return await self.bot.delete_message(ctx.message) if note == None: await self.bot.say("You didn't make a note.") return serverNoteList = util.load_js( os.path.join("notes", "{}.json".format(ctx.message.server.id))) if member.id not in serverNoteList: serverNoteList[member.id] = { 'noteNum': 0, 'name': { '1': '' }, 'note': { '1': '' }, 'time': { '1': '' }, 'issuer': { '1': '' }, 'issuerName': { '1': '' } } serverNoteList[member.id]["noteNum"] += 1 noteNum = str(serverNoteList[member.id]["noteNum"]) serverNoteList[member.id]["note"][noteNum] = note serverNoteList[member.id]["name"][noteNum] = member.name serverNoteList[member.id]["time"][noteNum] = str(datetime.now()) serverNoteList[member.id]["issuer"][noteNum] = ctx.message.author.id serverNoteList[ member.id]["issuerName"][noteNum] = ctx.message.author.name util.save_js( os.path.join("notes", "{}.json".format(ctx.message.server.id)), serverNoteList) await self.bot.say("Your note has been recorded")
async def noOneCaresEnable(self, ctx): perms = util.check_perms(self, ctx) if not perms: return conf = util.load_js("config.json") try: conf["noOneCaresDisabled"].remove(ctx.message.server.id) except KeyError: await self.bot.say( "The reaction is already enabled for this server.") return except ValueError: await self.bot.say( "The reaction is already enabled for this server.") return util.save_js("config.json", conf) await self.bot.say( "The 'no one cares' reaction has been enabled for this server.")
async def enableCommand(self, ctx, passedCommand: str): perms = await util.check_perms(self, ctx) if not perms: return disabledCommands = util.load_js("disabled-commands.json") index = 0 for d in disabledCommands: if d["command"] == passedCommand and d[ "server-id"] == ctx.message.server.id: del d del disabledCommands[index] util.save_js("disabled-commands.json", disabledCommands) await self.bot.say("{}{} has been re-enabled.".format( self.bot.command_prefix, passedCommand)) return index += 1 await self.bot.say( "{}{} either isn't a valid command, or is not currently disabled.". format(self.bot.command_prefix, passedCommand))