aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahiel@protonmail.ch>2015-12-07 00:36:04 +0100
committerRahiel Kasim <rahiel@protonmail.ch>2015-12-07 00:36:04 +0100
commitd74591c7701c2c1c4e49eba7c92eeeba77c628f0 (patch)
tree450aef866f97325625df536817ff60c07ca36a5a
parent94f0c8bcd16d36d1e52e3247f7bcc09181b11fe6 (diff)
implement feedback command
-rw-r--r--README.md5
-rw-r--r--bismillah.py28
2 files changed, 27 insertions, 6 deletions
diff --git a/README.md b/README.md
index 716edbc..aea5fa3 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@ In the same directory you should define a `secret.py` with the token you got
from the [BotFather](https://telegram.me/botfather):
```python
-TOKEN = "<your-token-here"
+TOKEN = "<your-token-here>"
```
Disable group chats for the bot by sending the BotFather the `/setjoingroups`
@@ -54,7 +54,8 @@ data:
```bash
wget "http://tanzil.net/trans/en.ahmedraza"
-wget "https://drive.google.com/uc?export=download&id=0B24P_FGD7V4jeTVaMXpaUFNiMlk" -O "Al_Jalalain_Eng.txt"
+wget "http://www.altafsir.com/Books/Al_Jalalain_Eng.pdf"
+pdftotext -nopgbrk Al_Jalalain_Eng.pdf
wget "http://www.everyayah.com/data/Husary_128kbps/000_versebyverse.zip"
unzip -d Husary 000_versebyverse.zip
wget "http://www.everyayah.com/data/quranpngs/000_images.zip"
diff --git a/bismillah.py b/bismillah.py
index bc1a4d0..9a129ed 100644
--- a/bismillah.py
+++ b/bismillah.py
@@ -61,8 +61,6 @@ def get_file(filename):
def main():
bot = telegram.Bot(token=TOKEN)
- # get the first pending update_id, this is so we can skip over it in case
- # we get an "Unauthorized" exception.
try:
update_id = bot.getUpdates()[0].update_id
except IndexError:
@@ -155,6 +153,9 @@ def serve(bot, update_id, data):
if chat_id < 0:
continue # bot should not be in a group
+ # "special:quran_type"
+ special_state = quran_type.split(':')
+
if message.startswith('/'):
command = message[1:]
if command in ("start", "help"):
@@ -166,13 +167,32 @@ def serve(bot, update_id, data):
"tanzil.net/trans/. The audio is a recitation by "
"Shaykh Mahmoud Khalil al-Husary from everyayah.com. "
"The tafsir is Tafsir al-Jalalayn from altafsir.com."
- "The source code of the bot is available at: "
+ "The source code of BismillahBot is available at: "
"https://github.com/rahiel/BismillahBot.")
+ elif command == "feedback":
+ text = ("Jazak Allahu khayran! Your feedback is highly "
+ "appreciated and will help us improve our services. "
+ "Your next message will be sent to the developers. "
+ "Send /cancel to cancel.")
+ save_user(chat_id, (s, a, "feedback:" + quran_type))
+ elif command == "cancel":
+ text = ("Cancelled.")
+ if len(special_state) > 1:
+ save_user(chat_id, (s, a, special_state[1]))
else:
text = "Invalid command"
bot.sendMessage(chat_id=chat_id, text=text)
continue
+ if len(special_state) > 1:
+ if special_state[0] == "feedback":
+ with open("feedback.txt", 'a') as f:
+ f.write("%d: %s\n" % (chat_id, message))
+ text = "Feedback saved " + telegram.Emoji.SMILING_FACE_WITH_SMILING_EYES
+ bot.sendMessage(chat_id=chat_id, text=text)
+ save_user(chat_id, (s, a, special_state[1]))
+ continue
+
match = re.match("(\d+)[ :\-;.,]*(\d*)", message)
if match is not None:
s = int(match.group(1))
@@ -193,5 +213,5 @@ def serve(bot, update_id, data):
return update_id
-if __name__ == '__main__':
+if __name__ == "__main__":
main()