A Python bot. For SE chat.
Find a file
2016-12-12 01:24:23 +05:30
ChatExchange@3f5e5bcb2c Update ChatExchange. 2015-11-04 21:09:07 +05:30
credentials added //google and getpass, removed //lmgtfy 2015-08-20 09:52:16 -05:00
modules Revert "Merge remote-tracking branch 'origin/test'" 2015-08-23 00:21:03 +05:30
.gitignore Added //joke 2015-08-01 19:13:06 +05:30
.gitmodules Initial commit 2015-08-01 18:40:45 +05:30
__init__.py Fixed problem with get_creds 2015-08-05 14:53:04 +05:30
_config.yml Add _config.yml 2016-12-12 01:24:23 +05:30
Bot.py Added two more possible welcome messages 2015-08-09 21:54:33 -05:00
modules.json added //google and getpass, removed //lmgtfy 2015-08-20 09:52:16 -05:00
prime.py Revert "Merge remote-tracking branch 'origin/test'" 2015-08-23 00:21:03 +05:30
privileged-users.db Cleaned up the repo 2015-08-05 14:14:30 +05:30
README.md Hide emails 2016-01-30 18:02:01 +05:30

prime

A Python bot that runs on the StackExchange chatrooms. Inspired by michaelpris similar program, I used manishearths excellent ChatExchange Python library. To run the bot, first clone the repo:

$ git clone https://github.com/xrisk/prime --recursive

The bot is written for Python2, so make sure you have that. Then,

python prime.py

Itll ask for your StackExchange email and password. Remember that only accounts with 20 rep can speak in the chatrooms.

$ python prime.py
SET UP CREDENTIALS FOR PRIME
Enter your Stack Overflow email ID: (hidden)
Enter your Stack Overflow password: (hidden)
Enter the ID of the room you wish to enter: 85048
1 chat.exchange.com
2 chat.meta.stackoverflow.com
3 chat.stackoverflow.com
Enter the host site for Prime: 3
{'host': u'chat.stackoverflow.com', 'room': '85048', 'user': '(hidden)', 'pass': '(hidden)'}
PRIME HAS STARTED
>> 

Type die at the prompt there, to well, kill the bot. 😧 Anything else at the prompt will be echoed to the chatroom.

For your convenience, prime can set itself up from environment variables. You need to set ChatExchangeU, ChatExchangeP, RoomID, and HostSite in your env appropriately. Beware that HostSite must be one of the values (not keys) defined in hosts.json.

Extending prime

Want to add a new command to prime? Well, Ive made it ridiculously simple for you to do just that. You need to do two things:

  • Add a new key-value pair to modules.json. For example, "//echo": "echo.py". The key is what you need to type in the chatroom to trigger the command, and the value is the name of the python script that gets called by prime.

  • Create that same python script inside the modules folder. It should have a function called main which takes two arguments, and returns one string. Heres the contents of echo.py as I would write it;

def main(message, priv=False):
	return 'You said: ' + message

The first variable will contain the input to the command, as passed in the chatroom. So, if someone types

//echo Im batman!

in the chatroom, your script will receive Im batman! in message. priv will a bool depending on whether the user who typed that command is “privileged.” This feature is not implemented yet, and priv will always be False.

And thats it! prime will now respond to the echo command. Nice and modular, isnt it?