start adding matrix bot stuff
This commit is contained in:
parent
1d2439f25e
commit
5f9ce2966c
1 changed files with 52 additions and 9 deletions
43
auerbot.py
43
auerbot.py
|
@ -5,6 +5,13 @@ import sys
|
|||
import json
|
||||
import pprint
|
||||
from bs4 import BeautifulSoup
|
||||
from nio import AsyncClient, MatrixRoom, RoomMessageText
|
||||
import asyncio
|
||||
|
||||
|
||||
# for nio output
|
||||
import logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# Stuff
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
@ -134,12 +141,48 @@ def auer_calc_total(items):
|
|||
total = total + count * auer_item_getprice(item)
|
||||
return total
|
||||
|
||||
async def bot_main():
|
||||
# Initialize the Matrix client
|
||||
client = AsyncClient("https://matrix.org")
|
||||
|
||||
# Replace 'your_username', 'your_password', and 'room_id' with your actual Matrix credentials
|
||||
username = "your_username"
|
||||
password = "your_password"
|
||||
room_id = "room_id"
|
||||
|
||||
await login(client, username, password)
|
||||
|
||||
# Start the event listener in the background
|
||||
event_listener_task = asyncio.create_task(event_listener())
|
||||
|
||||
try:
|
||||
while True:
|
||||
# Send a periodic message every 60 seconds
|
||||
await send_periodic_message(room_id, "Hello, world!")
|
||||
|
||||
# Sleep for 60 seconds
|
||||
await asyncio.sleep(60)
|
||||
except KeyboardInterrupt:
|
||||
print("Bot stopped by the user.")
|
||||
finally:
|
||||
# Stop the event listener task
|
||||
event_listener_task.cancel()
|
||||
|
||||
# Close the Matrix client connection
|
||||
await client.close()
|
||||
|
||||
def main():
|
||||
used = {}
|
||||
needed = 0
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-c", help="Filename for json config instead of stdin")
|
||||
parser.add_argument('--bot', action=argparse.BooleanOptionalAction, help="Start in bot mode instead of standalone script")
|
||||
parser.add_argument("-m", help="Filename for matrix bot configuration")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.bot:
|
||||
bot_main()
|
||||
else:
|
||||
# parse command line
|
||||
if args.c is not None:
|
||||
inf = open(args.c)
|
||||
|
|
Loading…
Reference in a new issue