The Interface of the fdb-spider, based on rocketchat
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.

104 lines
3.0 KiB

  1. import os
  2. from rocketchat.api import RocketChatAPI
  3. import configparser
  4. import json
  5. import requests
  6. config = configparser.ConfigParser()
  7. config.read('/root/fdb-spider-interface/config.ini')
  8. botname = config['Chat']['username']
  9. botpassword = config['Chat']['password']
  10. server_url = config['Chat']['URL']
  11. room_id = config['Chat']['room_id']
  12. # here comes the functions to talk to gpt
  13. # For local streaming, the websockets are hosted without ssl - http://
  14. HOST = 'localhost:5000'
  15. URI = f'http://{HOST}/api/v1/chat'
  16. #URI = f'http://{HOST}/api'
  17. # http://192.168.9.197:5000/api/v1/chat
  18. # For reverse-proxied streaming, the remote will likely host with ssl - https://
  19. # URI = 'https://your-uri-here.trycloudflare.com/api/v1/chat'
  20. if __name__ == '__main__':
  21. api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url})
  22. #api.send_message('Ciao, I am the fdb-spider', room_id)
  23. # rooms = api.get_private_rooms()
  24. # print(rooms)
  25. # api.send_message('Ole', room_id)
  26. n = 0
  27. import time
  28. import datetime
  29. from datetime import timedelta
  30. while True:
  31. time.sleep(10)
  32. n += 1
  33. print(n)
  34. try:
  35. date = datetime.datetime.now() - timedelta(days=3)
  36. room_history = api.get_private_room_history(room_id, oldest=date)
  37. except Exception as e:
  38. time.sleep(10)
  39. api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url})
  40. time.sleep(5)
  41. room_history = api.get_private_room_history(room_id, oldest=date)
  42. print('got a connection error, original message is:',e)
  43. messages_list = []
  44. for message in room_history['messages']:
  45. messages_list.append(message)
  46. if len(messages_list) > 1:
  47. latest_message_user_id = messages_list[0]['u']['_id']
  48. latest_message = messages_list[0]['msg']
  49. latest_message_id = messages_list[0]['_id']
  50. new_message_file = open('new_message_file.txt', 'r')
  51. new_message = new_message_file.read()
  52. new_message_file.close()
  53. new_message_list = new_message.split('§%§%')
  54. if new_message_list[0] != latest_message and new_message_list[1] != latest_message_id and latest_message_user_id != 'bb8EfPXrviu9yB9Ja':
  55. new_message_file = open('new_message_file.txt', 'w')
  56. new_message_file.write(latest_message + '§%§%' + latest_message_id)
  57. new_message_file.close()
  58. user_input = latest_message
  59. print('oi', user_input)
  60. api.send_message('Salut, ich bearbeite die Anfrage..', room_id)
  61. # here comes the code interacting with the spiders output json
  62. api.send_message(answer, room_id)
  63. time.sleep(4)
  64. api.send_message('Ich bin wieder bereit für Konfigurationsinput : )', room_id)
  65. time.sleep(3)