Browse Source

added room commands first structure

master
alpcentaur 10 months ago
parent
commit
3c71a07f6c
3 changed files with 83 additions and 11 deletions
  1. +1
    -0
      .gitignore
  2. +81
    -11
      fdb_spider_interface.py
  3. +1
    -0
      new_message_file.txt

+ 1
- 0
.gitignore View File

@ -1,2 +1,3 @@
config.ini
venv
rooms/*

+ 81
- 11
fdb_spider_interface.py View File

@ -32,11 +32,12 @@ if __name__ == '__main__':
api = RocketChatAPI(settings={'username': botname, 'password': botpassword, 'domain': server_url})
# api.send_message('Ciao, I am the fdb-spider', room_id)
# myinfo = api.get_my_info()
print(myinfo)
# print(myinfo)
# rooms = api.get_private_rooms()
# print(rooms)
@ -44,18 +45,35 @@ if __name__ == '__main__':
# api.send_message('Ole', room_id)
n = 0
'''
import time
import datetime
from datetime import timedelta
while True:
time.sleep(10)
time.sleep(4)
# get all the rooms
import os
room_list = []
rooms = os.listdir('rooms')
for room in rooms:
room_file = open('rooms/' + room, 'r')
room_file_raw = room_file.read()
room_file.close()
room_file_list = room_file_raw.split('§%§%')
room_list.append([room[:-3], room_file_list[0], room_file_list[1], room_file_list[2]])
#print(room_list)
n += 1
print(n)
try:
#print('getting the room history')
date = datetime.datetime.now() - timedelta(days=3)
room_history = api.get_private_room_history(room_id, oldest=date)
except Exception as e:
@ -73,10 +91,14 @@ if __name__ == '__main__':
for message in room_history['messages']:
messages_list.append(message)
if len(messages_list) > 1:
if len(messages_list) >= 1:
#print('blub', messages_list)
latest_message_user_id = messages_list[0]['u']['_id']
latest_message_user_username = messages_list[0]['u']['username']
latest_message = messages_list[0]['msg']
latest_message_id = messages_list[0]['_id']
@ -86,24 +108,72 @@ if __name__ == '__main__':
new_message_file.close()
new_message_list = new_message.split('§%§%')
#print(latest_message, new_message_list[0])
if new_message_list[0] != latest_message and new_message_list[1] != latest_message_id and latest_message_user_id != bot_user_id:
answer = 'Ich habe kein Kommando erhalten.'
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)
user_input_list = user_input.split(' ')
if user_input_list[0] == 'printrooms':
answer = str(room_list)
if user_input_list[0] == 'createroom':
try:
room_name = user_input_list[1]
except Exception as e:
room_name = 'NONE'
print(e)
try:
databases = user_input_list[2]
except Exception as e:
databases = 'NONE'
print(e)
try:
filters = user_input_list[3]
except Exception as e:
filters = 'NONE'
print(e)
if len(user_input_list) > 3:
answer = 'Die Syntax hat einen Fehler. Wahrscheinlich sind Leerzeichen in den Listen. Leerzeichen definieren die Syntax. Versuche es erneut, nach dem Muster -> createroom room1 ["fdb1","fdb2"] ["tag1","tag2"]'
if room_name == 'NONE' or databases == 'NONE' or filters == 'NONE':
answer = 'Um einen Raum zu erstellen, in dem neueste Einträge geteilt werden, lautet die Syntax: createroom <Raumname> <Liste-Datenbanken> <Liste-Filtertags>'
else:
new_room = api.create_public_room(room_name,
members=[latest_message_user_username],
read_only=True)
# The logic here is that a new room with the same name gets overwritten
new_room_id = new_room['channel']['_id']
room_file = open('rooms/' + new_room_id + '.txt', 'w')
room_file.write( room_name + '§%§%' + databases + '§%§%' + filters)
room_file.close()
answer = 'Der Command wurde übermittelt'
#print('oi', user_input)
api.send_message('Die Anfrage wird bearbeitet..', room_id)
# here comes the code interacting with the spiders output json
#answer = 'the up to date entries are: oi Oi Oi!'
api.send_message(answer, room_id)
time.sleep(4)
time.sleep(1)
api.send_message('Ich bin wieder bereit für Konfigurationsinput : )', room_id)
time.sleep(3)
time.sleep(1)
'''

+ 1
- 0
new_message_file.txt View File

@ -0,0 +1 @@
printrooms§%§%6DQP8M4wYhgWroAx7

Loading…
Cancel
Save