forked from galacticwarrior9/IslamBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dua.py
101 lines (82 loc) · 3.16 KB
/
dua.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import discord
from discord.ext import commands
from discord.ext.commands import MissingRequiredArgument
import re
from utils import get_site_source
ICON = 'https://sunnah.com/images/hadith_icon2_huge.png'
class Dua(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.url = 'https://ahadith.co.uk/hisnulmuslim-dua-{}'
self.duas = {
'afflictions': 49,
'after eating': 66,
'after insulting': 105,
'after rain': 61,
'after sinning': 41,
'after sneezing': 72,
'angriness': 76,
'anxiety': 34,
'before eating': 65,
'breaking fast': 64,
'completing wudu': 9,
'delight': 115,
'distress': 35,
'doubts': 37,
'during adhan': 15,
'during rain': 60,
'entering home': 11,
'entering mosque': 13,
'entering toilet': 6,
'fear of people': 114,
'fear of shirk': 86,
'forgiveness': 127,
'hearing thunder': 58,
'in ruku': 17,
'leaving home': 10,
'leaving mosque': 14,
'leaving toilet': 7,
'pain': 117,
'returning from travel': 99,
'sorrow': 34,
'travel': 90,
'visiting grave': 56,
'visiting sick': 45
}
@staticmethod
def get_dua_id(self, subject):
return self.duas[subject]
@commands.command(name='dua')
async def dua(self, ctx, *, subject: str):
subject = subject.lower()
try:
dua_id = self.get_dua_id(self, subject)
except KeyError:
return await ctx.send("Could not find dua for this.")
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)", "ﷺ") \
.replace("Indeed ", "Indeed, ")
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 (Hisn al-Muslim)", icon_url=ICON)
await ctx.send(embed=em)
@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.")
@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 self.duas:
dua_list_message.append('\n' + dua.title())
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)
def setup(bot):
bot.add_cog(Dua(bot))