Ejemplo n.º 1
0
    async def pl_append(self, ctx, name, *, links):
        """Appends a list of links to a playlist"""
        server = ctx.message.server
        author = ctx.message.author
        voice_channel = author.voice_channel

        if re.match(r'(https?://[^\s/$.?#].[^\s]*)', name):
            await send_cmd_help(ctx)

        file = self._find_playlist(server, name)
        if file == None:
            await self.bot.say("That playlist doesn't exist")
            return

        playlist = dataIO.load_json(file)

        if author.id != playlist["author"]:
            await self.bot.say("You are not the author of this playlist")
            return

        links = links.split()
        invalid_links = 0
        for link in links:
            if re.match(r'(https?://[^\s/$.?#].[^\s]*)', link) != None:
                playlist["playlist"].append(link)
            else:
                invalid_links += 1

        if invalid_links > 0:
            await self.bot.say(str(invalid_links) + " invalid links")

        dataIO.save_json(file, playlist)

        await self.bot.say("Added " + str(len(links) - invalid_links) +
                           " links to " + name)
Ejemplo n.º 2
0
 async def remove(self, ctx, *, role):
     """Remove a role to be self assignable"""
     if "<" in role and "&" in role and ">" in role and "@" in role:
         role = role.replace("<",
                             "").replace(">",
                                         "").replace("@",
                                                     "").replace("&", "")
         role = discord.utils.get(ctx.guild.roles, id=int(role))
     else:
         try:
             role = discord.utils.get(ctx.guild.roles, id=int(role))
         except:
             try:
                 role = list(
                     set(
                         filter(lambda r: r.name.lower() == role.lower(),
                                ctx.guild.roles)))[0]
             except:
                 return await ctx.send(
                     "I could not find that role :no_entry:")
     if not role:
         return await ctx.send("I could not find that role :no_entry:")
     server = ctx.message.guild
     if str(role.id) not in self.data[str(server.id)]["role"]:
         await ctx.send("That role isn't a self role :no_entry:")
         return
     del self.data[str(server.id)]["role"][str(role.id)]
     dataIO.save_json(self.file_path, self.data)
     await ctx.send(
         "Removed **{}** from the self roles list <:done:403285928233402378>"
         .format(role.name))
Ejemplo n.º 3
0
async def on_command_error(ctx, error):
    if isinstance(error, commands.NoPrivateMessage):
        await ctx.send(loc.load(dl, mn, "err_pm"))
    elif isinstance(error, commands.PrivateMessageOnly):
        await ctx.send(loc.get(ctx, mn, "err_pm_only"))
    elif isinstance(error, commands.DisabledCommand):
        await ctx.send(loc.get(ctx, mn, "err_disabled"))
    elif isinstance(error, commands.NSFWChannelRequired):
        await ctx.send(loc.load(dl, mn, "err_nsfw"))
    elif isinstance(error, commands.CommandOnCooldown):
        await ctx.send(loc.get(ctx, mn, "err_cd").format(error.retry_after))
    elif isinstance(error, commands.MissingRequiredArgument):
        await help.send_cmd_help(ctx, error=True)
    elif isinstance(error, commands.BadArgument):
        await help.send_cmd_help(ctx, error=True)
    elif isinstance(error, commands.CommandInvokeError):
        if isinstance(error.original, discord.Forbidden):
            await ctx.send(loc.get(ctx, mn, "err_missing_perm"))
        else:
            await ctx.send(loc.get(ctx, mn, "err_exec").format(error))
    elif isinstance(error, commands.CommandNotFound):
        pass
    elif isinstance(error, commands.CheckFailure):
        pass
    else:
        print(f"Uncaught exception {error}")
        dataIO.save_json("error.json", [error])
        await ctx.send(loc.get(ctx, mn, "err_uncaught"))
Ejemplo n.º 4
0
    async def pl_add(self, ctx, name, link):
        """Create a playlist from a playlist"""
        server = ctx.message.server
        author = ctx.message.author
        voice_channel = author.voice_channel

        if re.match(r'(https?://[^\s/$.?#].[^\s]*)', link) == None:
            await self.bot.say("That's not a valid link")
            return

        if re.match(r'(https?://[^\s/$.?#].[^\s]*)', name):
            await send_cmd_help(ctx)
            return

        path = os.path.join("data/audio/playlists", server.id)
        file = self._find_playlist(server, name)
        if file != None:
            await self.bot.say("That playlist already exists")
            return

        list = await self._parse_playlist(link)
        if list == None:
            await self.bot.say("Invalid playlist")
            return

        playlist = {"author": author.id, "playlist": list}

        if not os.path.exists(path):
            os.makedirs(path)
        dataIO.save_json(os.path.join(path, name + ".txt"), playlist)

        await self.bot.say("Created playlist")
Ejemplo n.º 5
0
    async def pl_create(self, ctx, name, *, links):
        """Create a playlist from a list of links"""
        server = ctx.message.server
        author = ctx.message.author
        voice_channel = author.voice_channel

        if re.match(r'(https?://[^\s/$.?#].[^\s]*)', name):
            await send_cmd_help(ctx)
            return

        path = os.path.join("data/audio/playlists", server.id)
        file = self._find_playlist(server, name)
        if file != None:
            await self.bot.say("That playlist already exists")
            return

        links = links.split()
        playlist = []
        invalid_links = 0
        for link in links:
            if re.match(r'(https?://[^\s/$.?#].[^\s]*)', link) != None:
                playlist.append(link)
            else:
                invalid_links += 1

        if invalid_links > 0:
            await self.bot.say(str(invalid_links) + " invalid links")

        playlist = {"author": author.id, "playlist": links}

        if not os.path.exists(path):
            os.makedirs(path)
        dataIO.save_json(os.path.join(path, name + ".txt"), playlist)

        await self.bot.say("Created playlist")
Ejemplo n.º 6
0
    async def _prefix(self, ctx, prefix:str):
        """Set the prefix for the Terminal"""

        self.prefix = prefix
        self.settings['prefix'] = self.prefix
        dataIO.save_json('data/terminal/settings.json', self.settings)
        await self.bot.say('`Changed max search results to {} `'.format(self.prefix))
Ejemplo n.º 7
0
 async def give(self, ctx, user: discord.Member, amount: int):
     """Give someone some money"""
     author = ctx.author
     if user.bot:
         await ctx.send("Bots can't make money :no_entry:")
         return
     await self._set_bank(author)
     await self._set_bank_user(user)
     if user == author:
         await ctx.send("You can't give yourself money :no_entry:")
         return
     if amount > self.settings["user"][str(author.id)]["balance"]:
         await ctx.send("You don't have that much money to give :no_entry:")
         return
     if amount < 1:
         await ctx.send(
             "You can't give them less than a dollar, too mean :no_entry:")
         return
     self.settings["user"][str(user.id)]["balance"] += round(amount * 0.9)
     self.settings["user"][str(author.id)]["balance"] -= amount
     dataIO.save_json(self.location, self.settings)
     s = discord.Embed(
         description=
         "You have gifted **${}** to **{}**\n\n{}'s new balance: **${}**\n{}'s new balance: **${}**"
         .format(round(amount * 0.9), user.name, author.name,
                 self.settings["user"][str(author.id)]["balance"],
                 user.name, self.settings["user"][str(user.id)]["balance"]),
         colour=author.colour)
     s.set_author(
         name="{} → {}".format(author.name, user.name),
         icon_url=
         "https://png.kisspng.com/20171216/8cb/5a355146d99f18.7870744715134436548914.png"
     )
     s.set_footer(text="10% Tax is taken per transaction")
     await ctx.send(embed=s)
Ejemplo n.º 8
0
 async def joino(self, ctx, user: discord.Member):
     """Forces another person to join the ranking system."""
     if not user:
         if user.id not in self.leader_board:
             self.leader_board[user.id] = {"name": user.name, "rank": 0, "XP": 0}
             dataIO.save_json("data/levels/leader_board.json", self.leader_board)
             embed = discord.Embed(title='Rank', description="{} has joined the clopperboard!".format(user.mention))
             await self.bot.say(embed=embed)
         else:
             embed = discord.Embed(title='Rank',
                                   description="{} has already joined and is rank {}".format(user.mention, str(
                                       self.get_rank(user.id))))
             await self.bot.say(
                 embed=embed)
     else:
         if user.id not in self.leader_board:
             self.leader_board[user.id] = {"name": user.name, "rank": 0, "XP": 0}
             dataIO.save_json("data/levels/leader_board.json", self.leader_board)
             embed = discord.Embed(title='Rank', description="{} has joined the clopperboard!".format(user.mention))
             await self.bot.say(embed=embed)
         else:
             embed = discord.Embed(title='Rank',
                                   description="{} has already joined and is rank {}".format(user.mention, str(
                                       self.get_rank(user.id))))
             await self.bot.say(
                 embed=embed)
Ejemplo n.º 9
0
 async def channel(self, ctx, channel: discord.TextChannel):
     """Set the channel of where you want the bot to welcome people"""
     server = ctx.guild
     self.settings[str(server.id)]["channel"] = str(channel.id)
     dataIO.save_json(self.file_path, self.settings)
     await ctx.send("<#{}> has been set as the join-leave channel".format(
         channel.id))
Ejemplo n.º 10
0
 async def replset_print_file(self, ctx, choice=None):
     """write results to a file, optionally opening in subl/atom
     Choices: nothing | subl | subl.exe | atom | atom.exe"""
     author = ctx.message.author
     choices = ['subl', 'subl.exe', 'atom', 'atom.exe']
     if choice not in choices + [None, 'nothing']:
         await send_cmd_help(ctx)
         return
     if choice is None:
         msg = (
             "You chose to print to file. What would you like to open it with?\n"
             "Choose between:  {}".format(' | '.join(choices +
                                                     ['nothing'])))
         choice = await self.user_choice(author, msg, choices)
     msg = "repl overflow will now go to file and "
     if choice not in choices:
         msg += "I won't open it after writing to {}".format(
             self.output_file)
         choice = None
     else:
         msg += ("the output will be opened with: `{} "
                 "{}`".format(choice, self.output_file))
     self.settings['OPEN_CMD'] = choice
     self.settings["OUTPUT_REDIRECT"] = "file"
     dataIO.save_json("data/repl/settings.json", self.settings)
     await self.bot.say(msg)
Ejemplo n.º 11
0
 async def reset(self, ctx):
     """Reset all the selfroles"""
     server = ctx.message.guild
     self.data[str(server.id)] = {}
     dataIO.save_json(self.file_path, self.data)
     await ctx.send(
         "All self roles have been deleted <:done:403285928233402378>")
Ejemplo n.º 12
0
 async def check_giveaway(self):
     await self.bot.wait_until_ready()
     while not self.bot.is_closed():
         for serverid in self._giveaway:
             for x in list(self._giveaway[serverid]["giveaways"])[:len(list(self._giveaway[serverid]["giveaways"]))]:
                 for number in self._giveaway[serverid]["giveaways"][x]:
                     if number["endtime"] <= datetime.utcnow().timestamp():
                         try:
                             message = await self.bot.get_channel(int(number["channel"])).get_message(int(number["message"]))
                             reaction = [x for x in message.reactions if x.emoji == "🎉"][0]
                             try:
                                 winner = random.sample([x for x in await reaction.users().flatten() if x != self.bot.user], k=number["winners"])
                             except:
                                 winner = random.sample([x for x in await reaction.users().flatten() if x != self.bot.user], k=len([x for x in await reaction.users().flatten() if x != self.bot.user]))
                             if winner == []:
                                 await self.bot.get_channel(int(number["channel"])).send("No one entered the giveaway :no_entry:")
                                 await message.delete()
                                 del self._giveaway[serverid]["giveaways"][x]
                                 dataIO.save_json(self._giveaway_file, self._giveaway)
                                 return
                             s=discord.Embed(title=number["title"], description="**{}** has won **{}**".format(", ".join([str(x) for x in winner]), number["item"]))
                             s.set_footer(text="Giveaway Ended")
                             await message.edit(embed=s)
                             await self.bot.get_channel(int(number["channel"])).send("{}, Congratulations you won the giveaway for **{}**".format(", ".join([x.mention for x in winner]), number["item"]))
                             del self._giveaway[serverid]["giveaways"][x]
                             dataIO.save_json(self._giveaway_file, self._giveaway)
                         except:
                             pass
         await asyncio.sleep(120)
Ejemplo n.º 13
0
 async def role(self, ctx, role: discord.Role):
     """Set role for autorole to assign.
     Use quotation marks around the role if it contains spaces."""
     server = ctx.message.server
     self.settings[server.id]["ROLE"] = role.id
     await self.bot.say("Autorole set to " + role.name)
     dataIO.save_json(self.file_path, self.settings)
Ejemplo n.º 14
0
    async def autorole(self, ctx):
        """Change settings for autorole
        Requires the manage roles permission"""
        server = ctx.message.server
        if server.id not in self.settings:
            self.settings[server.id] = {}
            self.settings[server.id]["ENABLED"] = False
            self.settings[server.id]["ROLE"] = None
            self.settings[server.id]["AGREE_CHANNEL"] = None
            dataIO.save_json(self.file_path, self.settings)

        if ctx.invoked_subcommand is None:
            e = discord.Embed(description="""b!autorole

Change settings for autorole

Requires the manage roles permission

Commands:
  agreement Set the channel that will be used for accepting the rules.
  role      Set role for autorole to assign.
  toggle    Enables/Disables autorole

Type b!autorole command for more info on a command.
You can also type b!autorole category for more info on a category.""")
            e.set_author(name="Help for {}'s command group {}.".format(
                self.bot.user.name, ctx.command),
                         icon_url=ctx.message.server.me.avatar_url)
            e.set_thumbnail(url=ctx.message.server.me.avatar_url)
            await self.bot.say(embed=e)
            await self.bot.say("```Current autorole state: {}```".format(
                self.settings[server.id]["ENABLED"]))
Ejemplo n.º 15
0
 async def role(self, ctx, *, role: discord.Role):
     """Set the role to be added to a user whne they join"""
     server = ctx.guild
     self.data[str(server.id)]["role"] = role.id
     dataIO.save_json(self.JSON, self.data)
     await ctx.send(
         "The autorole role is now **{}** <:done:403285928233402378>".
         format(role.name))
Ejemplo n.º 16
0
 async def reset(self, ctx):
     """Reset all the selfroles"""
     server = ctx.message.guild
     self.data[str(server.id)] = {}
     dataIO.save_json(self.file_path, self.data)
     await ctx.send(
         f"All self roles have been deleted {self.bot.get_emoji(452709464546476034)}"
     )
Ejemplo n.º 17
0
 async def replset_print_pm(self, ctx, number_of_pages: int = 20):
     """send pages to pm. Defaults to 20"""
     number_of_pages = max(number_of_pages, 1)
     self.settings["OUTPUT_REDIRECT"] = "pm"
     self.settings["PM_PAGES"] = number_of_pages
     dataIO.save_json("data/repl/settings.json", self.settings)
     await self.bot.say("repl overflow will now go to pm with a maximum of "
                        "{} messages".format(number_of_pages))
Ejemplo n.º 18
0
def delete(table: str, sid: int, name: str):
    table = sanitize(table)
    d_rel = "/" + table + "/" + str(sid) + fe
    d_data = load_file(db_path + d_rel)
    if d_data is None:
        return
    d_data.pop(name)
    dataIO.save_json(db_path + d_rel, d_data)
Ejemplo n.º 19
0
Archivo: logs.py Proyecto: itspapi/Sx4
 async def channel(self, ctx, channel: discord.TextChannel=None):
     """Set the channel where you want stuff to be logged"""
     server = ctx.message.guild
     if not channel:
         channel = ctx.message.channel
     self.data[str(server.id)]["channel"] = str(channel.id)
     dataIO.save_json(self.JSON, self.data)
     await ctx.send("Logs will be recorded in <#{}> if toggled on <:done:403285928233402378>".format(channel.id))
Ejemplo n.º 20
0
 async def role(self, ctx, *, role: discord.Role):
     """Set the role to be added to a user when they join"""
     server = ctx.guild
     self.data[str(server.id)]["role"] = role.name
     dataIO.save_json(self.JSON, self.data)
     await ctx.send(
         f"The autorole role is now **{role.name}** {self.bot.get_emoji(470063310386233344)}"
     )
Ejemplo n.º 21
0
 async def role(self, ctx, *, role: discord.Role):
     """Set the role to be added to a user when they join"""
     server = ctx.guild
     self.data[str(server.id)]["role"] = role.name
     dataIO.save_json(self.JSON, self.data)
     await ctx.send(
         "The autorole role is now **{}** :white_check_mark:".format(
             role.name))
Ejemplo n.º 22
0
 async def rps(self, ctx, your_choice):
     """Play rock paper scissors with the bot"""
     author = ctx.message.author
     if your_choice == "rock" or your_choice == "scissors" or your_choice == "paper" or your_choice == "r" or your_choice == "s" or your_choice == "p":
         if your_choice == "rock" or your_choice == "r":
             your_choice = 1
         if your_choice == "paper" or your_choice == "p":
             your_choice = 2
         if your_choice == "scissors" or your_choice == "s":
             your_choice = 3
     else:
         await ctx.send(
             "You have to choose rock, paper or scissors :no_entry:")
         return
     bot_choice = randint(1, 3)
     if bot_choice == your_choice:
         end = "Draw, let's go again!"
     if bot_choice == 1 and your_choice == 2:
         end = "You win! :trophy:"
     if bot_choice == 1 and your_choice == 3:
         end = "You lose, better luck next time."
     if bot_choice == 2 and your_choice == 1:
         end = "You lose, better luck next time."
     if bot_choice == 2 and your_choice == 3:
         end = "You win! :trophy:"
     if bot_choice == 3 and your_choice == 1:
         end = "You win! :trophy:"
     if bot_choice == 3 and your_choice == 2:
         end = "You lose, better luck next time."
     if bot_choice == 1:
         bot_choice = f"**Rock {self.bot.get_emoji(469959614583013386)}**"
     if bot_choice == 2:
         bot_choice = "**Paper :page_facing_up:**"
     if bot_choice == 3:
         bot_choice = "**Scissors :scissors:**"
     if your_choice == 1:
         your_choice = f"**Rock {self.bot.get_emoji(469959614583013386)}**"
     if your_choice == 2:
         your_choice = "**Paper :page_facing_up:**"
     if your_choice == 3:
         your_choice = "**Scissors :scissors:**"
     await ctx.send("{}: {}\nSensei: {}\n\n{}".format(
         author.name, your_choice, bot_choice, end))
     if end == "You lose, better luck next time.":
         self.rpssettings[str(
             author.id)]["rps_losses"] = self.rpssettings[str(
                 author.id)]["rps_losses"] + 1
     if end == "Draw, let's go again!":
         self.rpssettings[str(
             author.id)]["rps_draws"] = self.rpssettings[str(
                 author.id)]["rps_draws"] + 1
     if end == "You win! :trophy:":
         self.rpssettings[str(
             author.id)]["rps_wins"] = self.rpssettings[str(
                 author.id)]["rps_wins"] + 1
     dataIO.save_json(self.JSON, self.rpssettings)
Ejemplo n.º 23
0
 async def channel(self, ctx, channel: discord.TextChannel = None):
     """Set the channel where you want stuff to be logged"""
     server = ctx.message.guild
     if not channel:
         channel = ctx.message.channel
     self.data[str(server.id)]["channel"] = str(channel.id)
     dataIO.save_json(self.JSON, self.data)
     await ctx.send(
         f"Logs will be recorded in {channel.mention} if toggled on {self.bot.get_emoji(452709464546476034)}"
     )
Ejemplo n.º 24
0
 async def leave(self, ctx, user: discord.Member = None):
     """Leave the ranking system. This will erase your progress."""
     user = ctx.message.author
     if user.id in self.leader_board:
         del self.leader_board[user.id]
         dataIO.save_json("data/levels/leader_board.json", self.leader_board)
         await self.bot.say(embed=discord.Embed(title='Rank', description="{} has left in the clopperboard!".format(user.mention)))
     else:
         await self.bot.say(
             embed=discord.Embed(title='Rank', description="{} has not yet joined in the clopperboard! Do `{}rank join`!".format(user.mention, ctx.prefix)))
Ejemplo n.º 25
0
 async def unload(self, ctx, ext, store=None):
     try:
         self.bot.unload_extension(ext)
         await ctx.send(loc.get(ctx, mn, "ext_unloaded").format(ext))
     except commands.ExtensionNotLoaded:
         await ctx.send(loc.get(ctx, mn, "ext_notloaded").format(ext))
     finally:
         if ext in config["loadPlugins"] and store == "-config":
             config["loadPlugins"].remove(ext)
             dataIO.save_json("data/config.json", config)
Ejemplo n.º 26
0
 async def replset_pagelength(self, ctx, length: int = 1500):
     """Sets the page length when using the [p]replset print pages option
     length must be between 300 and 1700.
     length defaults to 1500"""
     if not (300 <= length <= 1700):
         return await send_cmd_help(ctx)
     old_length = self.settings["PAGES_LENGTH"]
     self.settings["PAGES_LENGTH"] = length
     dataIO.save_json("data/repl/settings.json", self.settings)
     await self.bot.say("each page will now break at {} characters "
                        "(was {})".format(length, old_length))
Ejemplo n.º 27
0
 async def remove(self, ctx, *, role: discord.Role):
     """Remove a role to be self assignable"""
     server = ctx.message.guild
     if str(role.id) not in self.data[str(server.id)]["role"]:
         await ctx.send("That role isn't a self role :no_entry:")
         return
     del self.data[str(server.id)]["role"][str(role.id)]
     dataIO.save_json(self.file_path, self.data)
     await ctx.send(
         f"Removed **{role.name}** from the self roles list {self.bot.get_emoji(452709464546476034)}"
     )
Ejemplo n.º 28
0
 async def selfrole(self, ctx):
     """Make it so users can self assign roles without perms"""
     server = ctx.message.guild
     if ctx.invoked_subcommand is None:
         await arghelp.send(self.bot, ctx)
     else:
         if str(server.id) not in self.data:
             self.data[str(server.id)] = {}
             dataIO.save_json(self.file_path, self.data)
         if "role" not in self.data[str(server.id)]:
             self.data[str(server.id)]["role"] = {}
             dataIO.save_json(self.file_path, self.data)
Ejemplo n.º 29
0
 async def replset_print_pages(self, ctx, add_pages: bool = False):
     """navigable pager in the current channel..
     set add_pages to true if you prefer the bot sending a new message for every new page"""
     msg = "repl overflow will now go to pages in the channel and "
     if add_pages:
         msg += "you will be given the option to page via adding new pages"
     else:
         msg += "regular single-message paging will be used"
     self.settings['MULTI_MSG_PAGING'] = add_pages
     self.settings["OUTPUT_REDIRECT"] = "pages"
     dataIO.save_json("data/repl/settings.json", self.settings)
     await self.bot.say(msg)
Ejemplo n.º 30
0
 async def load(self, ctx, ext, store=None):
     try:
         self.bot.load_extension(ext)
         await ctx.send(loc.get(ctx, mn, "ext_loaded").format(ext))
     except commands.ExtensionNotFound:
         await ctx.send(loc.get(ctx, mn, "ext_notfound").format(ext))
     except commands.ExtensionAlreadyLoaded:
         await ctx.send(loc.get(ctx, mn, "ext_alreadyloaded").format(ext))
     finally:
         if ext not in config["loadPlugins"] and store == "-config":
             config["loadPlugins"].append(ext)
             dataIO.save_json("data/config.json", config)