You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
misskey-ebooks-bot/rdbot.py

58 lines
1.8 KiB

3 years ago
import asyncio
import threading
3 years ago
from mi.ext import commands, tasks
from mi.framework import Note
from mi.framework.router import Router
3 years ago
from roboduck import *
3 years ago
# Load Misskey configuration
3 years ago
config = configparser.ConfigParser()
config.read(Path(__file__).parent.joinpath('bot.cfg'))
uri = "https://" + config.get("misskey", "instance_write")
token = config.get("misskey", "token")
3 years ago
class MyBot(commands.Bot):
text_model = None # Holds the markov object, so it won't be recreated everytime
def __init__(self):
super().__init__()
3 years ago
@tasks.loop(3600)
async def loop_1h(self):
text = create_sentence()
await bot.client.note.send(content=text, visibility="home")
3 years ago
@tasks.loop(43200)
async def loop_12h(self):
thread_update = threading.Thread(target=update)
thread_update.daemon = True
thread_update.start()
3 years ago
async def on_ready(self, ws):
await Router(ws).connect_channel(["global", "main"]) # Connect to global and main channels
await bot.client.note.send(content=datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " :roboduck: Bot started!",
visibility="specified")
self.loop_12h.start() # Launching renew posts every 12 hours
self.loop_1h.start() #
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " Roboduck Bot started!")
3 years ago
async def on_mention(self, note: Note):
if not note.author.is_bot:
text = note.author.action.get_mention() + " "
text += create_sentence()
await note.reply(content=text) # Reply to a note
3 years ago
if __name__ == "__main__":
databasepath = Path(__file__).parent.joinpath('roboduck.db')
if not (os.path.exists(databasepath) and os.stat(databasepath).st_size != 0):
init_bot()
bot = MyBot()
asyncio.run(bot.start(uri, token, timeout=600))