start adding matrix bot stuff

This commit is contained in:
helican 2023-12-16 16:47:58 +01:00
parent 1d2439f25e
commit 5f9ce2966c

View file

@ -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,25 +141,61 @@ 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()
# parse command line
if args.c is not None:
inf = open(args.c)
if args.bot:
bot_main()
else:
inf = sys.stdin
# parse command line
if args.c is not None:
inf = open(args.c)
else:
inf = sys.stdin
conf = json.load(inf)
ppe.pprint(conf)
conf = json.load(inf)
ppe.pprint(conf)
auer_request(conf)
auer_request(conf)
if inf is not sys.stdin:
inf.close()
if inf is not sys.stdin:
inf.close()
if __name__ == "__main__":
main()