filebot/main.py
2022-10-06 13:44:35 +00:00

76 lines
2.7 KiB
Python

# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
"""
help - list of commands\n
rights - get access rights\n
files - show list of files (get access)\n
id - get bot's id (get access)\n
share <ToxID> <file_name> - send file to friend (get access)\n
share --all <file_name> - send file to all friends (get access)\n
size <file_name> - get size of file (get access)\n
get <file_name> - get file with specified filename (get access)\n
get --all - get all files (get access)\n
stats - show statistics (write access)\n
del <file_name> - remove file with specified filename (delete access)\n
rename <file_name> --new <new_file_name> - rename file (delete access)\n
user <ToxID> <rights> - new rights (example: rwdm) for user (masters only)\n
status <new_status> - new status message (masters only)\n
name <new_name> - new name (masters only)\n
message <ToxID> <message_text> - send message to friend (masters only)\n
message --all <message_text> - send message to all friends (masters only)\n
stop - stop bot (masters only)\n
fsize <folder_size_in_MB> - set folder size in MB (masters only)\n
Users with write access can send files to bot.
"""
import time
import sys
from bootstrap import node_generator
from bot import Bot, tox_factory, ProfileHelper
from callbacks import init_callbacks
from settings import Settings
global LOG
import logging
logging.basicConfig(level=10)
LOG = logging.getLogger(__name__)
class FileBot(object):
def __init__(self, path):
super(FileBot, self).__init__()
self.tox = None
self.stop = False
self.profile = None
self.path = path
LOG.info('FileBot v0.1.2+')
def main(self):
self.tox = tox_factory(ProfileHelper.open_profile(self.path))
init_callbacks(self.tox)
# bootstrap
for data in node_generator():
self.tox.bootstrap(*data)
settings = Settings()
self.profile = Bot(self.tox)
LOG.debug('Iterate')
try:
while not self.stop:
self.tox.iterate()
time.sleep(self.tox.iteration_interval() / 1000.0)
except KeyboardInterrupt:
settings.save()
data = self.tox.get_savedata()
ProfileHelper.save_profile(data)
del self.tox
if __name__ == '__main__':
if len(sys.argv) <= 1:
raise IOError('Path to save file not found')
path = sys.argv[1]
bot = FileBot(path)
bot.main()