async def botban(self, ctx, user: discord.Member): """Bans the user from using commands""" if checks.is_owner_check(user): await ctx.send("Ya can't ban mah owner, man. 😠") return if checks.is_admin_check(ctx.message.channel, ctx, user): if not checks.is_owner_check(ctx.message.author): await ctx.send("Ya can't ban other admins") return if user.id == self.bot.user.id: await ctx.send("Lol you can't ban me, silly") return botdata.guildinfo(ctx.message.guild).botban(user) await ctx.send( "{} has henceforth been banned from using commands 😤".format( user.mention))
async def on_message(message): if message.author == bot.user: return mod = bot.get_cog('Mod') if mod is not None and not checks.is_owner_check(message): # check if the user is bot banned if message.author.id in mod.config.get('plonks', []): return # check if the channel is ignored # but first, resolve their permissions perms = message.channel.permissions_for(message.author) bypass_ignore = perms.manage_roles # if we don't have manage roles then we should # check if it's the owner of the bot or they have Bot Admin role. if not bypass_ignore: if not message.channel.is_private: bypass_ignore = discord.utils.get(message.author.roles, name='Bot Admin') is not None # now we can finally realise if we can actually bypass the ignore. if not bypass_ignore: if message.channel.id in mod.config.get('ignored', []): return await bot.process_commands(message)
async def setsteam(self, ctx, steam_id: int, user: discord.User = None): """Links a discord user to their steam/dota account *The user parameter can only be specified by the bot owner* You have to give this command either your steam32 or steam64 id. An easy way to find this is to look at the end of your dotabuff/opendota profile url. **Example:** If my dotabuff url is https://www.dotabuff.com/players/70388657 I would do: `{cmdpfx}setsteam 70388657` """ if user is None: user = ctx.message.author else: if not checks.is_owner_check(ctx.message.author): await ctx.send("You aint the boss of me 😠") return if steam_id > 76561197960265728: steam_id -= 76561197960265728 player = await opendota_query(f"/players/{steam_id}") if player.get("profile") is None: raise UserError( "Either thats a bad id, you don't play dota, or ya haven't enabled public match data" ) userinfo = botdata.userinfo(user.id) userinfo.steam32 = steam_id await ctx.send("Linked to {}".format(player['profile']['personaname']))
async def _prune(self, ctx, *, content: str = None): "Prunes stuff. Can take multiple user names in any order" if not ctx.message.author.server_permissions.manage_messages and not(checks.is_owner_check(ctx.message)): return if content is not None: content = content.split() num = 0 for x in content: try: num = int(x) break except: pass to_delete = [] count = 0 if ctx.message.mentions: for x in ctx.message.mentions: for y in reversed(self.bot.messages): if ctx.message.server == y.server and y.author == x: to_delete.append(y) count += 1 if count == num: break else: for x in reversed(self.bot.messages): if ctx.message.server == x.server: to_delete.append(x) count += 1 if count == num: break await self.bot.delete_messages(to_delete)
async def botunban(self, ctx, user: discord.Member): """Unbans the user, allowing them to use commands""" if checks.is_owner_check(user) or user == self.bot.user: await ctx.send("Ha ha. Very funny.") return botdata.guildinfo(ctx.message.guild).botunban(user) await ctx.send("{} is free of their restraints and may once again use commands".format(user.mention))
async def moderation(self, ctx): """Invoke with the specifc command you want.""" message = ctx.message authorize = False if message.channel.is_private: return if checks.is_owner_check(message): authorize = True cmd = ctx.invoked_with if message.mentions and not message.mention_everyone: for member in message.mentions: if cmd == "ban" and (authorize or message.author.server_permissions.ban_members): await self.bot.ban(member) if cmd == "kick" and (authorize or message.author.server_permissions.kick_members): await self.bot.kick(member) if cmd == "mute" and (authorize or message.author.server_permissions.manage_roles): if not "Muted" in [x.name for x in member.server.roles]: await self.bot.create_role(member.server, name="Muted", permissions=discord.Permissions.none()) await self.bot.send_message(member.server.owner, "The `Muted` role has been added to the server, please give it the required channel permissions") await self.bot.add_roles(member, [x for x in member.server.roles if x.name == "Muted"][0]) if cmd == "unmute" and (authorize or message.author.server_permissions.manage_roles): if not "Muted" in [x.name for x in member.roles]: await self.bot.say("This user is not Muted, so not unmuted") await self.bot.remove_roles(member, [x for x in member.roles if x.name == "Muted"][0])
async def on_message(message): admin = bot.get_cog('Admin') if admin is not None and not checks.is_owner_check(message): if message.author.id in admin.db.get('ignores', []): return await bot.process_commands(message)
async def on_message(message): admin = bot.get_cog('Admin') if admin is not None and not checks.is_owner_check(message): if message.author.id in admin.db.get('ignores', []): return await bot.process_commands(message)
async def on_message(message): if bot.get_cog("Owner"): global_ignores = bot.get_cog("Owner").global_ignores if not message.author.id in global_ignores or checks.is_owner_check( message): await bot.process_commands(message) else: await bot.process_commands(message)
async def setoutro(self, ctx, clipname: str = None, user: discord.User = None): """Sets your outro clip Calling this command without a clipname will tell you your current outro The argument is the name of the clip that will 'outroduce' you, for example: `{cmdpfx}setoutro math` **Note:** your outro clip cannot be longer than 4 seconds """ if user is None: user = ctx.message.author else: if not checks.is_owner_check(ctx.message.author): await ctx.send("You aint the boss of me 😠") return if clipname is None: outro = botdata.userinfo(user.id).outro if outro is None or outro == "": await ctx.send( "Yer outro isn't set. Try doin somethin' like `?setoutro dota:troll_lose_03`" ) return else: await ctx.send("Your outro is: {}".format(outro)) await self.play_clip("tts:your outro is", ctx) await self.play_clip(outro, ctx) return clip = await self.get_clip_try_types(clipname, "local|dota") audiolength = clip.audiolength if audiolength > 3.1: await ctx.send( f"Dat clip is {audiolength:.1f} seconds long, and outros gotta be less than 3." ) return botdata.userinfo(user.id).outro = clip.clipid await ctx.send("Yer outro is now " + clip.clipid)
async def on_message(message): mod = bot.get_cog('Mod') if mod is not None and not checks.is_owner_check(message): # check if the user is bot banned if message.author.id in mod.config.get('plonks', []): return # check if the channel is ignored # but first, resolve their permissions perms = message.channel.permissions_for(message.author) bypass_ignore = perms.manage_roles # if we don't have manage roles then we should # check if it's the owner of the bot or they have Bot Admin role. if not bypass_ignore: if not message.channel.is_private: bypass_ignore = discord.utils.get(message.author.roles, name='Bot Admin') is not None # now we can finally realise if we can actually bypass the ignore. if not bypass_ignore: if message.channel.id in mod.config.get('ignored', []): return # if someone private messages us with something that looks like a URL then # we should try to see if it's an invite to a discord server and join it if so. if message.channel.is_private and message.content.startswith('http'): try: invite = await bot.get_invite(message.content) await bot.accept_invite(invite) await bot.send_message(message.channel, 'Joined the server.') except: # if an error occurs at this point then ignore it and move on. pass finally: return await bot.process_commands(message)
def __check(self, ctx): msg = ctx.message if checks.is_owner_check(msg): return True # user is bot banned if msg.author.id in self.config.get('plonks', []): return False # check if the channel is ignored # but first, resolve their permissions perms = msg.channel.permissions_for(msg.author) bypass_ignore = perms.administrator # now we can finally realise if we can actually bypass the ignore. if not bypass_ignore and msg.channel.id in self.config.get( 'ignored', []): return False return True
async def on_message(self, message): if len(message.content) < 2 or message.channel.is_private: return server = message.server prefix = self.get_prefix(message) if not prefix: return samplectx = discord.ext.commands.context.Context(message=message, prefix=prefix) if server.id in self.c_commands and self.bot.user_allowed( message) and checks.is_owner_check(samplectx): cmdlist = self.c_commands[server.id] cmd = message.content[len(prefix):] if cmd in cmdlist: cmd = cmdlist[cmd] cmd = self.format_cc(cmd, message) await self.bot.send_message(message.channel, cmd) elif cmd.lower() in cmdlist: cmd = cmdlist[cmd.lower()] cmd = self.format_cc(cmd, message) await self.bot.send_message(message.channel, cmd)
async def complexout(self, ctx, channel_id: str): """ puts the output for the current server in another server. This takes a channel ID Be careful with managing this """ server = ctx.message.server if server.id not in self.settings: self.initial_config(server.id) chan = discord.utils.get(self.bot.get_all_channels(), id=channel_id) if not (checks.is_owner_check(ctx) or checks.role_or_permissions(lambda r: r.name.lower( ) == settings.get_server_admin(chan.server).lower(), manage_server=True)): return await self.bot.say( "You don't have the right permissions in the destination serverto do that!" ) if chan.type != discord.ChannelType.text: return await self.bot.say("That isn't a text channel") if chan.id in self.settings[server.id]['output']: return await self.bot.say("Channel already set as output") if self.settings[server.id]['multiout']: self.settings[server.id]['output'].append(chan.id) self.save_json() return await self.bot.say("Channel added to output list") else: self.settings[server.id]['output'] = [chan.id] self.save_json() return await self.bot.say("Channel set as output")
async def on_message(message): global respondToOwner deleteMessage = False # will use to make changes to the message so orignal message can still be used in func calls workingMessage = copy.copy(message) if message.author == bot.user: return if respondToOwner \ and checks.is_owner_check(message) \ and workingMessage.content.startswith(cmdPrefix): await bot.send_message(message.channel, random.choice(ownerResponses)) currentTime = message.timestamp if workingMessage.content.lower().endswith("-del"): deleteMessage = True workingMessage.content = message.content[:-4].strip() if workingMessage.content.startswith(cmdPrefix): botCommands = list(bot.commands.keys()) + list(aliasDict.keys()) msg = copy.copy(workingMessage) passedCMD = msg.content.split(' ')[0] passedCMD = passedCMD[len(cmdPrefix)::] roles = message.author.permissions_in(message.channel) if passedCMD in botCommands and message.channel.id not in whiteListedChannels and not roles.manage_channels: # command ran is an actual commands or alias if message.author in userLastCommand: timeStamps = userLastCommand[message.author] msg1 = timeStamps['msg1'] msg2 = timeStamps['msg2'] timeoutStart = timeStamps['timeoutStart'] if timeoutStart is not None: diff = currentTime - timeoutStart if diff.total_seconds() < 30: await bot.send_message(message.author, f"You're in timeout, no memes for {30 - diff.total_seconds():.1f} secs") return else: timeStamps.update({'timeoutStart': None}) userLastCommand.update({message.author: timeStamps}) # msg1, msg2 stuff if msg1 is None: # both will be none since msg2 will only have a time is msg1 is not none msg1 = currentTime elif msg2 is None: msg2 = currentTime elif (msg1 - msg2).total_seconds() > 0: # msg1 is newer msg2 = currentTime else: msg1 = currentTime timeStamps.update({'msg1': msg1, 'msg2': msg2}) # check diff of msg1 and msg2 to see if they were sent in under 3 secs if msg1 is not None and msg2 is not None: diff = abs(msg1 - msg2) if diff.total_seconds() < 3: timeStamps.update({'timeoutStart': currentTime}) userLastCommand.update({message.author: timeStamps}) else: timeStamps = {"msg1": None, "msg2": None, "timeoutStart": None} userLastCommand.update({message.author: timeStamps}) # 'real' command await bot.process_commands(workingMessage) msg = copy.copy(workingMessage) alias = msg.content.split(' ')[0] # remove prefix alias = alias[len(cmdPrefix)::] if alias in aliasDict: msg.content = cmdPrefix + aliasDict[alias][0] + " " + aliasDict[alias][1] await bot.process_commands(msg) elif workingMessage.content.lower().strip() in keyWords: response = keyWords[message.content.lower()] if type(response) is list: response = random.choice(response) print("Sending a response to ".format(workingMessage.content.lower())) await bot.send_message(message.channel, response) if deleteMessage: await bot.delete_message(message)
def cog_check(self, ctx): """Checks to make sure the user is the bot owner""" return checks.is_owner_check(ctx.message.author)
async def deck_add(self, ctx, card1=None, card2=None, card3=None, card4=None, card5=None, card6=None, card7=None, card8=None, deck_name=None): """Add a deck to a personal decklist. Example: !deck add bbd mm loon bt is fs gs lh "Lava Loon" For the full list of acceptable card names, type !deck cards """ author = ctx.message.author server = ctx.message.server if deck_name is None: decknum = 1 deck_name = 'Deck' if server.id in self.settings['Servers']: if author.id in self.settings['Servers'][server.id]['Members']: decknum = 1 + len(self.settings['Servers'][server.id] ['Members'][author.id]['Decks']) deck_name += ' ' + str(decknum) # convert arguments to deck list and name member_deck = [card1, card2, card3, card4, card5, card6, card7, card8] member_deck = self.normalize_deck_data(member_deck) if not all(member_deck): await self.bot.say("Please enter 8 cards.") await send_cmd_help(ctx) elif len(set(member_deck)) < len(member_deck): await self.bot.say("Please enter 8 unique cards.") else: await self.deck_upload(ctx, member_deck, deck_name) decks = self.settings["Servers"][server.id]["Members"][ author.id]["Decks"] if self.deck_is_valid: # creates sets with decks.values # decks_sets = [set(d) for d in decks.values()] # if set(member_deck) in decks_sets: # # existing deck # await self.bot.say("Deck exists already") # else: # new deck await self.bot.say("Deck added.") deck_key = str(datetime.datetime.utcnow()) decks[deck_key] = {"Deck": member_deck, "DeckName": deck_name} # If user has more than allowed by max, remove older decks timestamp = decks.keys() timestamp = sorted(timestamp) while len(decks) > (max_deck_per_user if not checks.is_owner_check(ctx) else max_deck_for_owner): t = timestamp.pop(0) decks.pop(t, None) self.save_settings()
async def crclip(self, ctx, filename=None, times=1,user:discord.User=None): ''' syntax: filename must be a filename in my folder or filenames in my folder, separated by a / times must be a number or it will just do it once user must be a mention, id, username and it will find the voice channel in the server where the user is, and play it to them. specifying user only works for mods. ''' # print('checking') # print(await ctx.invoke(self.perm_to_join_to_user)) server = ctx.message.server mod_role = settings.get_server_mod(server) admin_role = settings.get_server_admin(server) mod_or_admin = False roles = list(map(lambda x: x.name, ctx.message.author.roles)) mod_or_admin = admin_role in roles or mod_role in roles or checks.is_owner_check(ctx) if user == None or not mod_or_admin: user = ctx.message.author filenames = [] if filename == None: await self.bot.say("You must specify a filename to play") return if '/' in filename: filenames = filename.split('/') else: filenames = [filename] for name in filenames: if name + self.exten not in os.listdir(AUDIOPATH) and name + self.exten not in os.listdir(TTSPATH): await self.bot.say("The file, `{}` is not saved in the audio folder.".format(name+self.exten)) return try: client = await self.connect_with_user(ctx,user) except UserNotConnected as e: await self.bot.say(e.msg) return filenames = list(map(lambda filename:os.path.join(AUDIOPATH if filename +self.exten in os.listdir(AUDIOPATH) else TTSPATH, filename + self.exten), filenames)) try: times = int(times) except: times = 1 if times>5: times=5 elif times<1: times=1 self.is_playing = dataIO.load_json(SETTINGS_JSON)['playing'] if self.is_playing: await self.bot.say("You may not play anything if it is already playing something.") return self.set_play(True) dataIO.save_json(SETTINGS_JSON, self.settings) n = 0 if times==1: for name in filenames: if n>0: while player.is_playing(): await asyncio.sleep(.2) player = client.create_ffmpeg_player(name) player.start() n += 1 else: for x in range(times): for name in filenames: if n>0: while player.is_playing(): await asyncio.sleep(.2) player = client.create_ffmpeg_player(name) player.start() n += 1 while player.is_playing(): await asyncio.sleep(.2) self.set_play(False)
async def on_message(message): global respondToOwner deleteMessage = False # will use to make changes to the message so orignal message can still be used in func calls workingMessage = copy.copy(message) if message.author == bot.user: return if respondToOwner \ and checks.is_owner_check(message) \ and workingMessage.content.startswith(cmdPrefix): await bot.send_message(message.channel, random.choice(ownerResponses)) currentTime = message.timestamp if workingMessage.content.lower().endswith("-del"): deleteMessage = True workingMessage.content = message.content[:-4].strip() if workingMessage.content.startswith(cmdPrefix): botCommands = list(bot.commands.keys()) + list(aliasDict.keys()) msg = copy.copy(workingMessage) passedCMD = msg.content.split(' ')[0] passedCMD = passedCMD[len(cmdPrefix)::] roles = message.author.permissions_in(message.channel) if passedCMD in botCommands and message.channel.id not in whiteListedChannels and not roles.manage_channels: # command ran is an actual commands or alias if message.author in userLastCommand: timeStamps = userLastCommand[message.author] msg1 = timeStamps['msg1'] msg2 = timeStamps['msg2'] timeoutStart = timeStamps['timeoutStart'] if timeoutStart is not None: diff = currentTime - timeoutStart if diff.total_seconds() < 30: await bot.send_message( message.author, f"You're in timeout, no memes for {30 - diff.total_seconds():.1f} secs" ) return else: timeStamps.update({'timeoutStart': None}) userLastCommand.update({message.author: timeStamps}) # msg1, msg2 stuff if msg1 is None: # both will be none since msg2 will only have a time is msg1 is not none msg1 = currentTime elif msg2 is None: msg2 = currentTime elif (msg1 - msg2).total_seconds() > 0: # msg1 is newer msg2 = currentTime else: msg1 = currentTime timeStamps.update({'msg1': msg1, 'msg2': msg2}) # check diff of msg1 and msg2 to see if they were sent in under 3 secs if msg1 is not None and msg2 is not None: diff = abs(msg1 - msg2) if diff.total_seconds() < 3: timeStamps.update({'timeoutStart': currentTime}) userLastCommand.update({message.author: timeStamps}) else: timeStamps = {"msg1": None, "msg2": None, "timeoutStart": None} userLastCommand.update({message.author: timeStamps}) # 'real' command await bot.process_commands(workingMessage) msg = copy.copy(workingMessage) alias = msg.content.split(' ')[0] # remove prefix alias = alias[len(cmdPrefix)::] if alias in aliasDict: msg.content = cmdPrefix + aliasDict[alias][0] + " " + aliasDict[ alias][1] await bot.process_commands(msg) elif workingMessage.content.lower().strip() in keyWords: response = keyWords[message.content.lower()] if type(response) is list: response = random.choice(response) print("Sending a response to ".format(workingMessage.content.lower())) await bot.send_message(message.channel, response) if deleteMessage: await bot.delete_message(message)
async def cogs_menu(self, ctx, cog_list: list, message: discord.Message = None, page=0, timeout: int = 30, edata=None): """menu control logic for this taken from https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/menu/menu.py""" cog = cog_list[page] is_owner_or_co = is_owner_check(ctx) if is_owner_or_co: expected = ["➡", "✅", "⬅", "❌"] else: expected = ["➡", "⬅", "❌"] if not message: message =\ await self.bot.send_message(ctx.message.channel, embed=cog) await self.bot.add_reaction(message, "⬅") await self.bot.add_reaction(message, "❌") if is_owner_or_co: await self.bot.add_reaction(message, "✅") await self.bot.add_reaction(message, "➡") else: message = await self.bot.edit_message(message, embed=cog) react = await self.bot.wait_for_reaction(message=message, user=ctx.message.author, timeout=timeout, emoji=expected) if react is None: try: try: await self.bot.clear_reactions(message) except: await self.bot.remove_reaction(message, "⬅", self.bot.user) await self.bot.remove_reaction(message, "❌", self.bot.user) if is_owner_or_co: await self.bot.remove_reaction(message, "✅", self.bot.user) await self.bot.remove_reaction(message, "➡", self.bot.user) except: pass return None reacts = {v: k for k, v in numbs.items()} react = reacts[react.reaction.emoji] if react == "next": page += 1 next_page = page % len(cog_list) try: await self.bot.remove_reaction(message, "➡", ctx.message.author) except: pass return await self.cogs_menu(ctx, cog_list, message=message, page=next_page, timeout=timeout, edata=edata) elif react == "back": page -= 1 next_page = page % len(cog_list) try: await self.bot.remove_reaction(message, "⬅", ctx.message.author) except: pass return await self.cogs_menu(ctx, cog_list, message=message, page=next_page, timeout=timeout, edata=edata) elif react == "install": if not is_owner_or_co: await self.bot.say( "This function is only available to the bot owner.") return await self.cogs_menu(ctx, cog_list, message=message, page=page, timeout=timeout, edata=edata) else: INSTALLER = self.bot.get_cog('Downloader') if not INSTALLER: await self.bot.say( "The downloader cog must be loaded to use this feature." ) return await self.cogs_menu(ctx, cog_list, message=message, page=page, timeout=timeout, edata=edata) repo1, repo2 = edata['results']['list'][page]['repo'][ 'name'], edata['results']['list'][page]['links']['github'][ 'repo'] cog1, cog2 = edata['results']['list'][page]['repo'][ 'name'], edata['results']['list'][page]['name'] await ctx.invoke(INSTALLER._repo_add, repo1, repo2) await ctx.invoke(INSTALLER._install, cog1, cog2) return await self.bot.delete_message(message) else: try: return await self.bot.delete_message(message) except: pass