2022-10-06 15:44:35 +02:00
|
|
|
# -*- 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.
|
|
|
|
"""
|
|
|
|
|
2016-04-21 21:55:31 +02:00
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
|
2022-10-06 15:44:35 +02:00
|
|
|
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__)
|
2016-04-21 21:55:31 +02:00
|
|
|
|
|
|
|
class FileBot(object):
|
|
|
|
|
|
|
|
def __init__(self, path):
|
|
|
|
super(FileBot, self).__init__()
|
|
|
|
self.tox = None
|
|
|
|
self.stop = False
|
|
|
|
self.profile = None
|
|
|
|
self.path = path
|
2022-10-06 15:44:35 +02:00
|
|
|
LOG.info('FileBot v0.1.2+')
|
2016-04-21 21:55:31 +02:00
|
|
|
|
|
|
|
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)
|
2022-10-06 15:44:35 +02:00
|
|
|
LOG.debug('Iterate')
|
2016-04-21 21:55:31 +02:00
|
|
|
try:
|
|
|
|
while not self.stop:
|
|
|
|
self.tox.iterate()
|
|
|
|
time.sleep(self.tox.iteration_interval() / 1000.0)
|
|
|
|
except KeyboardInterrupt:
|
2016-04-26 19:42:20 +02:00
|
|
|
settings.save()
|
|
|
|
data = self.tox.get_savedata()
|
|
|
|
ProfileHelper.save_profile(data)
|
|
|
|
del self.tox
|
2016-04-21 21:55:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-10-06 15:44:35 +02:00
|
|
|
if len(sys.argv) <= 1:
|
2016-04-21 21:55:31 +02:00
|
|
|
raise IOError('Path to save file not found')
|
2022-10-06 15:44:35 +02:00
|
|
|
path = sys.argv[1]
|
|
|
|
bot = FileBot(path)
|
|
|
|
bot.main()
|
2016-04-21 21:55:31 +02:00
|
|
|
|