Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/HandcartCactus/nlp-bot
An interactive twitter bot that runs a variety of profile analysis commands. Used to be live at https://twitter.com/WhatDoITweetBot. Temporarily offline.
https://github.com/HandcartCactus/nlp-bot
bot python twitter twitter-bot
Last synced: 18 days ago
JSON representation
An interactive twitter bot that runs a variety of profile analysis commands. Used to be live at https://twitter.com/WhatDoITweetBot. Temporarily offline.
- Host: GitHub
- URL: https://github.com/HandcartCactus/nlp-bot
- Owner: HandcartCactus
- License: mit
- Created: 2021-03-23T10:58:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-04-08T15:03:24.000Z (over 3 years ago)
- Last Synced: 2024-07-30T20:57:12.016Z (3 months ago)
- Topics: bot, python, twitter, twitter-bot
- Language: Python
- Homepage: https://twitter.com/WhatDoITweetBot
- Size: 128 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TwitterBot
Code relating to my twitter bot, which can be found [here](https://twitter.com/WhatDoITweetBot).## Interacting with the bot
For more information on interacting with the bot, see `USERGUIDE.md`.## Setup
### Fork it!
Fork it.
### API Tokens
Get your [Twitter api tokens](https://developer.twitter.com/en/support/twitter-api).
### Config File
Create a copy of `configs/template.ini` as `configs/config.ini` and store your credentials in it.
### Conda Env
In the root directory of the project, create your conda env with `conda env create -f twitterbot.yml`.### Running The Code
```bash
conda activate twitterbot
python client.py --config configs/config.ini
```## Development
### The Command Class
To create commands for your bot:
1. Create a `Command` subclass using the `Command` Abstract Base Class.
2. Import the command into `client.py`
3. Add the command to the `commands_dict` in `client.py` along with a string alias for twitter users.Your `Command` subclass will recieve:
1. The Twitter API
2. The Tweet ID
3. The User ID
4. Any text following the command, for parameters.Your subclass should implement a `reply_tweet()` method that probably calls another method to do a thing, then prepares a response and tweets it back at the user.
For Example, you might make a class like this:
```python
class MyCommand (Command):
def _do_something(self):
#do something
return 100def _format_output(self, result):
# string format it or whatever
return str(result)
def reply_tweet(self):
something = self._do_something()
text = self._format_output(something)
self.api.PostUpdate(
status=text,
in_reply_to_status_id=self.tweet_id,
auto_populate_reply_metadata=True
)
```Then you can add it to `client.py`'s `commands_dict` like this:
```python
from my_commands import MyCommandcommands_dict = {
'my_command': MyCommand,
}```
And you should be good to go!
## Use
Tweet at your bot using the following format: "@bot command (params)"