LearnedBot/bot.py

43 lines
1 KiB
Python
Raw Normal View History

from mastodon import Mastodon
import config
import memory
import time
secret_file = config.user + '.secret'
def register():
Mastodon.create_app(
config.user,
api_base_url = config.instance,
to_file = secret_file
)
def connect(password):
api = Mastodon(
client_id = secret_file,
api_base_url = config.instance
)
api.log_in(
)
def scalar(a, b):
return len(a.intersection(b))
def answer(db, notifications):
for notification in notifications:
if notification.type == 'mention':
indexed_input = db.index(notification.status.content)
reply = memory.find_best_quote(db, indexed_input)
def main():
api = connect(???)
db = memory.init('pratchett')
last = None
while True:
notifications = api.notifications(since_id=last)
if len(notifications) > 0:
last = notifications[0]
answer(db, notifications)
else:
time.sleep(config.delay)