Closed abdhan closed 8 years ago
Hi,
I have something like this done for my bot to rate soccer player in our group, when you type /rate you get presented a playername and text that says to rate the player type /rate 1..6
I can show you the code if you want but iam sure its dirty i am also new to python ;)
Regards X23
Am 11.02.2016 um 22:33 schrieb abdhan notifications@github.com:
Hi there,
I am a novice to python. I have been able to create simple views. But I am not sure how to create a poll like view.
For example:
Bot: Here's a question. Choose the right answer
- Choice1
- Choice2
- Choice3
I: 3
Bot: That is the right answer.
So now I was thinking to make like a new thread for the question. So that thread is only looking for a choice 1,2 or 3 while at the same time being able to listen to other commands from other users. Any help is appreciated.
Thanks in advance.
— Reply to this email directly or view it on GitHub.
Hi,
it's not really a poll but goes in the right direction.
this is the code:
def rate(self, message=None, match=None, to=None): if message.isGroupMessage() == True: return TextMessageProtocolEntity("Die Spielerbewertung ist in der Gruppe nicht erlaubt, bitte durch Direktkonversation bewerten.", to=message.getFrom()) else: if len(message.getBody()) == 7: try: float(int(message.getBody()[6:])) except ValueError: return TextMessageProtocolEntity("Es sollten schon eine Zahl zwischen 0 und 6 sein Dumbo!", to=message.getFrom()) if os.path.exists(rank + message.getFrom()): for filename in os.listdir(user): if not os.path.exists(rank + message.getFrom() + "/" + filename): spielername = open(user + filename, "r") text_file = open(rank + message.getFrom() + "/" + filename, "w") text_file.write(message.getBody()[6:]) text_file.close() return TextMessageProtocolEntity("Du hast " + spielername.read() + " mit " + message.getBody()[6:] + " Punkte(n) bewertet. Sende /rate für die nächste Bewertung.", to=message.getFrom()) else: if os.path.exists(rank + message.getFrom()): for filename in os.listdir(user): if not os.path.exists(rank + message.getFrom() + "/" + filename): spielername = open(user + filename, "r") if os.path.exists(player + message.getFrom() + ".jpg"): playerpic = message.getFrom() + ".jpg" else: playerpic = "unknown.jpg" return self.image_sender.send_by_path(jid=message.getFrom(), path="/opt/whatsapp-bot-seed-master/media/player/" + playerpic, caption="Sende /rate (0..6) um " + spielername.read() + " zu bewerten.\r\n\r\n/rate 0 keine Wertung\r\n/rate 1 sehr gut\r\n/rate 2 gut\r\n/rate 3 befriedigend\r\n/rate 4 ausreichend\r\n/rate 5 mangelhaft\r\n/rate 6 ungenügend")
Hi, on the last commit I added a QuizView, and a simple session storage. https://github.com/joaoricardo000/whatsapp-bot-seed/commit/3a8880c773cd9dbac84170a265391099cbdc3d4b
check out: https://github.com/joaoricardo000/whatsapp-bot-seed/blob/master/src/views/quiz.py and https://github.com/joaoricardo000/whatsapp-bot-seed/blob/master/src/utils/session.py
Thanks @x23piracy I will try it out. @joaoricardo000 I did not know about the shelf module, so I will check that and try it out. Thanks a lot for the code! Cheers!
Hi there,
I am a novice to python. I have been able to create simple views. But I am not sure how to create a poll like view.
For example:
Bot: Here's a question. Choose the right answer
I: 3
Bot: That is the right answer.
So now I was thinking to make like a new thread for the question. So that thread is only looking for a choice 1,2 or 3 while at the same time being able to listen to other commands from other users. Any help is appreciated.
Thanks in advance.