how i made a ridiculously simple but fun bot — with fbchat
Hello hahaha.
It’s ridiculous I am writing a article about a very simple bot which just texts randomly yet so many people chatted with it and didn’t notice hahaha. Though, some people got triggered but who cares xd. Pornhub wouldn’t exist if he asked about his startup idea with his family, right? hahaha.
So, I talk with a lot of girls ( i mean, ofc ) and when i get bored all i text is hora and haina hola all the time. I wrote a pyautogui program which captures new text and types eh ok aru vana long ago. hahaha that was also so fun. i triggered many garals.
The idea was relatively simple I would capture the chatting person’s profile picture and check if new instance exists (because facebook renders avatar next to text) for every new message. the code was something like this….
But this was very simple and checking image was too redundant and boring. As I needed to register every new photos and my code broke when they change profile picture. So, I checked facebook docs to see if they offer any messaging api.
They did offer one but it was nodejs sdk. And I do javascript but ( i dont enjoy it) idc what you say. I just don’t enjoy writing cli scripts in nodejs. I prefer python.
So, I found this amazing module called fbchat hahaha with best docs for a personal project out there. ( Link in bottom )
I wrote a simple bot which just replied with hora and haina hola randomly.
Something like this and running it was so easy just pass and initialize your client and write some codes to secure your email and password as you dont wanna expose it on your github hahaha.
Then, I made a wordlist of like 200 words and it sent randomly from that list hahaha.
Let me add some screenshots.
hahahaha.
Then people said i should add some commands to this.
Then i first added -s- to start the bot and -x- to stop the bot. The mechanism now was. I would record the thread id and if it’s one of those command it would save / remove their id from thread id list and the bot will reply only to those who have their names on thread list something like this…
Pretty straight forward right hahaha. And my send texts code was just checking if incoming message belonged to my list.
Then, I took it one step further.
Now the bot sends kanda ( porn for nepali) hahaha. The mechanism is it justs forwards a kanda video from one kanda group. I ditched this later as i dont wanna get in any legal troubles.
I added meme, when the message is -meme it will scrap reddit and send you a mem.
I added joke, also when message is -joke it sends you a random joke from one random api i found on the internet.
I also added voice message if you message something like -say {hello} it will say hello in voice message using google tts.
So the code was like this now..
The code is dead simple in like 100/150 lines but it was so fun.
Github: https://github.com/geekyarthurs/chat-bot
Docs of fbchat: https://fbchat.readthedocs.io/en/stable/api.html