Browse Source

Added follow bot (UNSUPPORTED!@!!!!)

merge-requests/3/head
KemoNine 5 years ago
parent
commit
17bf6808ae
  1. 7
      botstreamlisteners.py
  2. 27
      toot_bot.py

7
botstreamlisteners.py

@ -208,11 +208,16 @@ CREATE TABLE IF NOT EXISTS follow_cache (
"""Method that follows unseen users."""
federated = '@' in status['account']['acct']
username = status['account']['acct']
instance = None
if federated:
instance = status['account']['acct'].split('@')[1]
timestamp = status['created_at']
visibility = status['visibility']
# Welcome any user who's posted publicly
if visibility == 'public' and federated: #TODO: Incorporate black lists here
if visibility == 'public' and federated \
and instance not in self.bot_config['follow']['blacklist']['instances'] \
and username not in self.bot_config['follow']['blacklist']['users']:
# Check if username has been seen for welcome
self.cursor.execute(
'select count(1) as found from follow_cache where username = ?',

27
toot_bot.py

@ -15,7 +15,7 @@ import feedparser
from mastodon import Mastodon
from ruamel.yaml import YAML
from botstreamlisteners import WelcomeBot
from botstreamlisteners import WelcomeBot, FollowBot
from toot import toot
@ -155,6 +155,15 @@ def welcome(config):
mastodon.public_stream(WelcomeBot(config))
def follow(config):
"""Follow new users flowing through public timeline that haven't been seen yet"""
mastodon = Mastodon(
client_id=config['config']['client_cred_file'],
access_token=config['config']['user_cred_file'],
api_base_url=config['config']['api_base_url']
)
mastodon.public_stream(FollowBot(config))
def handle_command_line():
"""Parse and act on the command line."""
@ -186,6 +195,7 @@ def handle_command_line():
subparsers.add_parser('toot', help='send configured toot')
subparsers.add_parser('rss', help='cross post articles from an rss feed')
subparsers.add_parser('welcome', help='Run the welcome bot (service)')
subparsers.add_parser('follow', help='Run the follow bot (service) - UNSUPPORTED DON\'T RUN !!!!!!!!!!!!')
# Parse CLI arguments
args = parser.parse_args()
@ -232,17 +242,24 @@ def handle_command_line():
if args.command == 'login':
login(config)
# Deal with welcome command
if args.command == 'welcome':
# Deal with streaming command caches
if args.command == 'welcome' or args.command == 'follow':
# Verify toot cache file folder exists
cache_file = pathlib.Path(config['stream']['cache_file'])
if not cache_file.parent.exists(): # pylint: disable=no-member
# Warn if welcome cache file doesn't exist
sys.exit('welcome cache_file directory does not exist')
sys.exit('cache_file directory does not exist')
if not cache_file.exists():
print('warning: welcome cache_file file will be created')
print('warning: cache_file file will be created')
# Deal with welcome command
if args.command == 'welcome':
welcome(config)
# Deal with follow command
if args.command == 'follow':
follow(config)
# Deal with toot command
if args.command == 'toot':
# Ensure main toot is <= 500 characters

Loading…
Cancel
Save