~fkfd/mastobot

34fc7cf23088993a9ee349bea8e70b06e0df4701 — Frederick Yin 1 year, 10 months ago 292742d master
Add example: OEIS Bot
1 files changed, 26 insertions(+), 0 deletions(-)

A examples/oeisbot.py
A examples/oeisbot.py => examples/oeisbot.py +26 -0
@@ 0,0 1,26 @@
from mastobot import *
from oeis.client import entry
from os import environ
from datetime import datetime
import re

bot = Bot(environ.get("INSTANCE"), environ.get("ACCESS_TOKEN"), websocket_mode=True)


@bot.on_mention("A[0-9]{6}", validation=REGEX)
def get_sequence(status):
    serial = re.search("(A[0-9]{6})", status.text).group()
    sequence = entry(serial)
    if sequence:
        created = datetime.fromisoformat(sequence.created)
        return (
            f"OEIS {serial}: {sequence.name}\n\n"
            + sequence.data
            + f"\n\nCreated at {created.year}-{created.month}-{created.day}\n\n"
            f"https://oeis.org/{serial}"
        )
    else:
        return f"OEIS {serial} not found."


bot.run()