예제 #1
0
파일: dua.py 프로젝트: hope4soul/IslamBot
class Dua(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.url = 'https://ahadith.co.uk/hisnulmuslim-dua-{}'

    @staticmethod
    def get_dua_id(subject):
        return DUAS[subject]

    async def _dua(self, ctx, subject: str):
        subject = subject.title()
        dua_id = self.get_dua_id(subject)

        site_source = await get_site_source(self.url.format(dua_id))
        dua_text = []
        for dua in site_source.findAll("div", {"class": 'search-item'}):
            text = dua.get_text(separator=" ").strip()\
                .replace("(saw)", "ﷺ")
            text = '\n' + text
            dua_text.append(text)
        dua_text = ''.join(dua_text)
        dua_text = re.sub(r'\d+', '', dua_text)

        em = discord.Embed(title=f'Duas for {subject.title()}', colour=0x467f05, description=dua_text)
        em.set_author(name="Fortress of the Muslim", icon_url=ICON)
        await ctx.send(embed=em)

    @commands.command(name='dua')
    async def dua(self, ctx, *, subject: str):
        await self._dua(ctx, subject)

    @dua.error
    async def on_dua_error(self, ctx, error):
        if isinstance(error, MissingRequiredArgument):
            await ctx.send(f"**You need to provide a dua topic**. Type `{ctx.prefix}dualist` for a list of dua topics.")
        if isinstance(error, KeyError):
            await ctx.send(f"**Could not find dua for this topic.** Type `{ctx.prefix}dualist` for a list of dua topics.")

    @cog_ext.cog_slash(name="dua", description="Send ʾadʿiyah by topic.",
                       options=[
                           create_option(
                               name="topic",
                               description="The topic of the dua.",
                               option_type=3,
                               required=True,
                               choices=generate_choices_from_list(list(DUAS.keys())))])
    async def slash_dua(self, ctx: SlashContext, subject: str):
        await ctx.defer()
        await self._dua(ctx, subject)

    @commands.command(name='dualist')
    async def dualist(self, ctx):
        dua_list_message = ['**Type {0}dua <topic>**. Example: `{0}dua breaking fast`\n'.format(ctx.prefix)]

        for dua in DUAS:
            dua_list_message.append('\n' + dua)

        em = discord.Embed(title=f'Dua List', colour=0x467f05, description=''.join(dua_list_message))
        em.set_footer(text="Source: Fortress of the Muslim (Hisn al-Muslim)")
        await ctx.send(embed=em)
예제 #2
0
파일: utility.py 프로젝트: msabur/IslamBot
class Utility(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    async def _reload(self, ctx, cog_name: str):
        if cog_name in self.bot.extensions.keys():
            await ctx.send(
                f":white_check_mark: **Reloaded the cog `{cog_name}`.**")
            await self.bot.reload_extension(cog_name)
        else:
            await ctx.send(
                f":warning: **Invalid extension**. Valid extensions: `{list(self.bot.extensions.keys())}`"
            )

    @commands.is_owner()
    @commands.command(name='ireload')
    async def reload(self, ctx, cog_name: str):
        await self._reload(ctx, cog_name)

    @cog_ext.cog_slash(name="ireload",
                       description="🔒 Owner only command. Reloads a cog",
                       options=[
                           create_option(name="cog_name",
                                         description="The name of the cog.",
                                         option_type=3,
                                         required=True,
                                         choices=generate_choices_from_list(
                                             list(cog_list)))
                       ])
    async def slash_reload(self, ctx: SlashContext, cog_name: str):
        await ctx.defer()
        app = await self.bot.application_info()
        if ctx.author.id == app.owner.id:
            # hard code this because @commands.is_owner raises exceptions that can't be dealt with
            # probably can be in on_command_error though
            await self._reload(ctx, cog_name)
        else:
            await ctx.send(
                "🔒 **You do not have permission to use this command**.")

    @reload.error
    async def reload_error(self, ctx, error):
        if isinstance(error, CheckFailure):
            await ctx.send(
                "🔒 **You do not have permission to use this command**.")
예제 #3
0
class Help(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    async def _help(self, ctx, pre, section):
        section = section.lower()

        if section == "main":
            em = discord.Embed(title='IslamBot Help / أمر المساعدة', colour=0xdeb949, description="**Type -ihelp <category>**, e.g. `-ihelp quran`\n")
            em.add_field(name="Categories", value='\n» Quran\n» Hadith\n» Tafsir\n» Prayer Times\n» Dua\n» Calendar\n» Settings' ,
                         inline=False)
            em.add_field(name="Links", value="• [Vote / تصويت](https://top.gg/bot/352815253828141056/vote)\n"
                                             "• [Support Server / سيرفر المساعدة](https://discord.gg/Ud3MHJR)\n"
                                             "• [Documentation / لتوثيق](https://github.com/galacticwarrior9/islambot/blob/master/README.md)\n"
                                             "• [Contributors / المساعدين](https://github.com/galacticwarrior9/IslamBot/graphs/contributors)\n"
                                             "• [GitHub / غيت هاب](https://github.com/galacticwarrior9/islambot)\n"
                                             "• [Iqra / اقرأ بوت](https://top.gg/bot/706134327200841870)"
                         , inline=False)
            em.set_thumbnail(url='https://images-na.ssl-images-amazon.com/images/I/71CYXRJdY4L.png')
            await ctx.send(embed=em)

        elif section == "quran":
            em = discord.Embed(title="Qurʼān", colour=0x0a519c, description='[Click here for the translations list.](https://github.com/galacticwarrior9/IslamBot/wiki/Qur%27an-Translation-List)')
            em.add_field(name=f"{pre}quran", inline=True, value="Gets Qur'anic verses."
                                              f"\n\n`{pre}quran <surah>:<ayah> <optional translation>`"
                                              f"\n\nExample: `{pre}quran 1:1`"
                                              f"\n\n`{pre}quran <surah:<first ayah>-<last ayah> <optional translation>`"
                                              f"\n\nExample: `{pre}quran 1:1-7 turkish`")

            em.add_field(name=f"{pre}aquran", inline=True, value="Gets Qur'anic verses in Arabic."
                                              f"\n\n`{pre}aquran <surah>:<ayah>`"
                                              f"\n\nExample: `{pre}aquran 1:1`"
                                              f"\n\n`{pre}quran <surah>:<first ayah>-<last ayah>`"
                                              f"\n\nExample: `{pre}aquran 1:1-7`")

            em.add_field(name=f"{pre}morphology", inline=True, value="View the morphology of a Qur'anic word."
                                              f"\n\n`{pre}morphology <surah>:<ayah>:<word number>`"
                                              f"\n\nExample: `{pre}aquran 2:255:1`")

            em.add_field(name=f"{pre}mushaf", inline=True, value="View a Qur'anic verse on a *mushaf*."
                                              f"\n\n`{pre}mushaf <surah>:<ayah>`"
                                              f"\n\nExample: `{pre}mushaf 1:1`"
                                              "\n\nAdd 'tajweed' to the end of the command for color-coded tajweed rules."
                                              f"\n\nExample: `{pre}mushaf 1:1 tajweed`")

            em.add_field(name=f"{pre}surah", inline=True, value="Get information about a surah."
                                              f"\n\n`{pre}surah <surah number>`"
                                              f"\n\nExample: `{pre}surah 1`")

            em.add_field(name=f"{pre}settranslation", inline=True, value="Changes the default Qur'an translation."
                                              f"\n\n`{pre}settranslation <translation>`"
                                              f"\n\nExample: `{pre}settranslation khattab`"
                                              "\n\nYou must have the **Administrator** permission to use this command.")

            await ctx.send(embed=em)

        elif section == "tafsir":
            em = discord.Embed(title="Tafsīr", colour=0x0a519c, description='[Click here for the tafsir list.](https://github.com/galacticwarrior9/IslamBot/wiki/Tafsir-List)')

            em.add_field(name=f"{pre}tafsir", inline=True, value="Gets tafsīr in English."
                                              f"\n\n`{pre}tafsir <surah>:<ayah> <optional tafsir name>`"
                                              f"\n\nExample: `{pre}tafsir 1:1`"
                                              f"\n\nExample 2: `{pre}tafsir 1:1 ibnkathir`")

            em.add_field(name=f"{pre}atafsir", inline=True, value="Gets tafsīr in Arabic."
                                              f"\n\n`{pre}atafsir <surah>:<ayah> <optional tafsir name>`"
                                              f"\n\nExample: `{pre}atafsir 1:1`"
                                              f"\n\nExample 2: `{pre}atafsir 1:1 zamakhshari`")

            await ctx.send(embed=em)

        elif section == "hijri_calendar":
            em = discord.Embed(title="Hijri Calendar", colour=0x0a519c)

            em.add_field(name=f"{pre}hijridate", inline=True, value="Gets the current Hijri date (in the US)")

            em.add_field(name=f"{pre}converttohijri", inline=True, value="Converts a Gregorian date to its Hijri counterpart."
                                              f"\n\n`{pre}converttohijri DD-MM-YYYY`"
                                              f"\n\nExample: `{pre}converttohijri 15-01-2020`")

            em.add_field(name=f"{pre}convertfromhijri", inline=True, value="Converts a Hijri date to its Gregorian counterpart."
                                              f"\n\n`{pre}convertfromhijri DD-MM-YYYY`"
                                              f"\n\nExample: `{pre}convertfromhijri 15-06-1441`")
            await ctx.send(embed=em)

        elif section == "hadith":
            em = discord.Embed(title="Hadith", colour=0x0a519c, description="These commands fetch hadith from *sunnah.com*.")

            em.add_field(name=f"{pre}hadith", inline=True, value="Gets a sunnah.com hadith in English."
                                                            f"\n\n `{pre}hadith <collection> <hadith number>`"
                                                            f"\n\nExample: `{pre}hadith muslim 1051` for https://sunnah.com/muslim:1051")

            em.add_field(name=f"{pre}ahadith", inline=True, value="Gets a sunnah.com hadith in Arabic. " 
                                                                  "The usage is the same as `-hadith`.")

            em.add_field(name=f"{pre}biography", inline=True, value="Gets the biography of a hadith transmitter "
                                                                    "or early Muslim from al-Dhahabi's *Siyar A'lam al-"
                                                                    "al-Nubala*."
                                                            f"\n\n`{pre}biography <name of person in Arabic>`"
                                                            f"\n\nExample: `{pre}biography عبد الله بن عباس`")

            await ctx.send(embed=em)

        elif section == "prayer times":
            em = discord.Embed(title="Prayer Times", colour=0x0a519c)

            em.add_field(name=f"{pre}prayertimes", inline=True, value="Gets prayer times for a specified location."
                                                                 f"\n\n`{pre}prayertimes <location>`"
                                                                 f"\n\nExample: `{pre}prayertimes Burj Khalifa, Dubai`")

            em.add_field(name=f"{pre}setcalculationmethod", inline=True, value=f"Changes your personal calculation method for `{pre}prayertimes`")

            em.add_field(name=f"{pre}addprayerreminder", inline=True, value=f"Starts the prayer time reminders setup.")

            em.add_field(name=f"{pre}removeprayerreminder", inline=True, value=f"Removes prayer time reminders from a channel.")

            em.add_field(name=f"{pre}removepersonalprayerreminder", inline=True, value=f"Ends personal prayer time reminders.")

            await ctx.send(embed=em)

        elif section == "dua":
            em = discord.Embed(title="Dua", colour=0x0a519c)
            em.add_field(name=f"{pre}dualist", inline=True, value="Shows a list of duas.")
            em.add_field(name=f"{pre}dua", inline=True, value="Gets a dua for a topic."
                                                         "\n\n__Usage__"
                                                         f"\n\n`{pre}dua <topic>`"
                                                         f"\n\nExample: `{pre}dua forgiveness`"
                                                         "\n\nSee `-dualist` for a list of topics.")
            await ctx.send(embed=em)

        elif section == "settings":
            em = discord.Embed(title="Settings", colour=0x0a519c, description='🔒 You need the **Administrator** '
                                                                              'permission to use these commands.')
            em.add_field(name=f"{pre}prefix set", inline=True, value="Sets a custom prefix for the server."
                                                        "\n\n__Usage__"
                                                        f"\n\n`{pre}prefix set <new_prefix>`"
                                                        f"\n\nExample: `{pre}prefix set +`")
            em.add_field(name=f"{pre}prefix remove", inline=True, value="Removes any custom prefix that was set."
                                                         "\n\n__Usage__"
                                                         f"\n\n`{pre}prefix remove`")
            await ctx.send(embed=em)

    @commands.command(name="ihelp")
    async def help(self, ctx, *, section: str = "main"):
        await self._help(ctx, ctx.prefix, section)

    @cog_ext.cog_slash(name="help", description="The help command for the bot.",
                       options=[
                           create_option(
                               name="section",
                               description="NOTE: Not all commands have slash equivalents yet!",
                               option_type=3,
                               choices=generate_choices_from_list(SECTIONS),
                               required=False)])
    async def slash_help(self, ctx: SlashContext, section: str = "Main"):
        await ctx.send()
        await self._help(ctx, '/', section)
예제 #4
0
class Tafsir(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    async def send(self, ctx, tafsir):
        await tafsir.fetch_text()
        em = tafsir.make_embed()
        num_pages = len(tafsir.pages)
        if num_pages == 1:
            return await ctx.send(embed=em)

        # If there are multiple pages, construct buttons for their navigation.
        buttons = [
            manage_components.create_button(style=ButtonStyle.green,
                                            label="الصفحة التالية",
                                            emoji="⬅",
                                            custom_id="atafsir_next_page"),
            manage_components.create_button(style=ButtonStyle.red,
                                            label="الصفحة السابقة",
                                            emoji="➡",
                                            custom_id="atafsir_previous_page"),
            manage_components.create_button(style=ButtonStyle.URL,
                                            label="tafsir.app",
                                            url=tafsir.url)
        ]
        action_row = manage_components.create_actionrow(*buttons)
        await ctx.send(embed=em, components=[action_row])
        while True:
            try:
                button_ctx = await manage_components.wait_for_component(
                    self.bot, components=action_row, timeout=600)
                if not hasattr(button_ctx, 'custom_id'):
                    pass
                if button_ctx.custom_id == 'atafsir_previous_page':
                    if tafsir.page > 1:
                        tafsir.page -= 1
                    else:
                        tafsir.page = num_pages
                    em = tafsir.make_embed()
                    await button_ctx.edit_origin(embed=em)
                elif button_ctx.custom_id == 'atafsir_next_page':
                    if tafsir.page < num_pages:
                        tafsir.page += 1
                    else:
                        tafsir.page = 1
                    em = tafsir.make_embed()
                    await button_ctx.edit_origin(embed=em)

            except asyncio.TimeoutError:
                break

    @commands.command(name="atafsir")
    async def atafsir(self, ctx, ref: str, tafsir: str = "tabari"):
        quran_reference = QuranReference(ref, False)
        tafsir = ArabicTafsir(quran_reference.surah, quran_reference.ayat_list,
                              tafsir)
        await self.send(ctx, tafsir)
        # TODO: Re-add error handling

    @cog_ext.cog_slash(
        name="atafsir",
        description="تبعث تفسير أي آية, يوجد 56 تفسير متاح بالعربية",
        options=[
            create_option(name="تفسير",
                          description="اسم التفسير.",
                          option_type=3,
                          required=True,
                          choices=generate_choices_from_list(
                              list(names.values()))),
            create_option(
                name="السورة_و_الآية",
                description="رقم السورة:رقم الآية - على سبيل المثال: 2:255",
                option_type=3,
                required=True)
        ])
    async def slash_atafsir(self, ctx: SlashContext, ref: str, tafsir: str):
        await ctx.defer()
        quran_reference = QuranReference(ref, False)
        tafsir = ArabicTafsir(quran_reference.surah, quran_reference.ayat_list,
                              tafsir)
        await self.send(ctx, tafsir)