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.

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