diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..579f19b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config.ini +venv diff --git a/README.md b/README.md index 3aa59d8..22f2869 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,25 @@ MM88MMM ,adPPYb,88 88,dPPYba, ,adPPYba, 8b,dPPYba, 88 ,adPPYb,88 ,a 88 88 ``` + + + +To use this spider, u need to have a Rocketchat Server. + +On your Rocketchat Server, create a new user with the role bot. +Put the right password and username in config.ini. +Create a private channel, add the bot to the channel, then run the code + +``` +api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url}) + +rooms = api.get_private_rooms() + +print(rooms) +``` + +From there, copy the room_id to +``` +config.ini +``` + diff --git a/README.md.save b/README.md.save deleted file mode 100644 index c93dc1e..0000000 --- a/README.md.save +++ /dev/null @@ -1,16 +0,0 @@ - - -``` - __ _ _ _ _ _ _ - / _| __| | |__ ___ _ __ (_) __| | ___ _ __ (_)_ __ | |_ ___ _ __ -| |_ / _` | '_ \ _____/ __| '_ \| |/ _` |/ _ \ '__|____| | '_ \| __/ _ \ '__| -| _| (_| | |_) |_____\__ \ |_) | | (_| | __/ | |_____| | | | | || __/ | -|_| \__,_|_.__/ |___/ .__/|_|\__,_|\___|_| |_|_| |_|\__\___|_| - |_| - __ - / _| __ _ ___ ___ -| |_ / _` |/ __/ _ \ -| _| (_| | (_| __/ -|_| \__,_|\___\___| - -``` diff --git a/config_example.ini b/config_example.ini new file mode 100644 index 0000000..5710420 --- /dev/null +++ b/config_example.ini @@ -0,0 +1,5 @@ +[Chat] +username = +password = +url = https://rocket.example.de +room_id = diff --git a/fdb_spider_interface.py b/fdb_spider_interface.py new file mode 100644 index 0000000..45391d2 --- /dev/null +++ b/fdb_spider_interface.py @@ -0,0 +1,104 @@ +import os +from rocketchat.api import RocketChatAPI +import configparser +import json +import requests + +config = configparser.ConfigParser() +config.read('/root/fdb-spider-interface/config.ini') + +botname = config['Chat']['username'] +botpassword = config['Chat']['password'] +server_url = config['Chat']['URL'] +room_id = config['Chat']['room_id'] + +# here comes the functions to talk to gpt + + +# For local streaming, the websockets are hosted without ssl - http:// +HOST = 'localhost:5000' +URI = f'http://{HOST}/api/v1/chat' +#URI = f'http://{HOST}/api' + +# http://192.168.9.197:5000/api/v1/chat + +# For reverse-proxied streaming, the remote will likely host with ssl - https:// +# URI = 'https://your-uri-here.trycloudflare.com/api/v1/chat' + + +if __name__ == '__main__': + + + api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url}) + + #api.send_message('Ciao, I am the fdb-spider', room_id) + + # rooms = api.get_private_rooms() + + # print(rooms) + + # api.send_message('Ole', room_id) + + n = 0 + + import time + import datetime + from datetime import timedelta + while True: + time.sleep(10) + + n += 1 + print(n) + + try: + + date = datetime.datetime.now() - timedelta(days=3) + room_history = api.get_private_room_history(room_id, oldest=date) + except Exception as e: + time.sleep(10) + api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url}) + time.sleep(5) + room_history = api.get_private_room_history(room_id, oldest=date) + print('got a connection error, original message is:',e) + + + + messages_list = [] + + + for message in room_history['messages']: + messages_list.append(message) + + if len(messages_list) > 1: + + latest_message_user_id = messages_list[0]['u']['_id'] + + latest_message = messages_list[0]['msg'] + + latest_message_id = messages_list[0]['_id'] + + new_message_file = open('new_message_file.txt', 'r') + new_message = new_message_file.read() + new_message_file.close() + + new_message_list = new_message.split('§%§%') + + + if new_message_list[0] != latest_message and new_message_list[1] != latest_message_id and latest_message_user_id != 'bb8EfPXrviu9yB9Ja': + + new_message_file = open('new_message_file.txt', 'w') + new_message_file.write(latest_message + '§%§%' + latest_message_id) + new_message_file.close() + + + user_input = latest_message + print('oi', user_input) + api.send_message('Salut, ich bearbeite die Anfrage..', room_id) + + # here comes the code interacting with the spiders output json + + api.send_message(answer, room_id) + time.sleep(4) + api.send_message('Ich bin wieder bereit für Konfigurationsinput : )', room_id) + time.sleep(3) + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..14c6dca --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +certifi==2023.7.22 +charset-normalizer==3.2.0 +idna==3.4 +requests==2.31.0 +rocket-python==1.3.4 +urllib3==2.0.4