identity per bot

This commit is contained in:
randogoth 2023-05-24 00:41:10 +03:00
parent 4280ba5624
commit 0a30648495
3 changed files with 22 additions and 11 deletions

View file

@ -39,3 +39,11 @@ def echo_msg(msg):
bot.run()
```
### Identity & Announce Files
The bots' identity and announce files are stored in
Linux: `~/.local/share/LXMFBot/<botname>`
MacOS: `~/Library/Application Support/LXMFBot/<botname>`
Windows: `C:\Users\<username>\AppData\Local\LXMFBot\<botname>`

View file

@ -1,6 +1,6 @@
from lxmfbot import LXMFBot
bot = LXMFBot("NodeBot")
bot = LXMFBot("testbot")
@bot.received
def echo_msg(msg):

View file

@ -19,13 +19,15 @@ class LXMFBot:
# initialize identiy
self.name = name
dirs = AppDirs("LXMFBot", "randogoth")
idpath = os.path.join(dirs.user_data_dir, "identity")
self.announce_path = os.path.join(dirs.user_data_dir, "announce")
if not os.path.isfile(idpath):
self.config_path = os.path.join(dirs.user_data_dir, name)
idfile = os.path.join(self.config_path, "identity")
if not os.path.isdir(self.config_path):
os.mkdir(self.config_path)
if not os.path.isfile(idfile):
RNS.log('No Primary Identity file found, creating new...', RNS.LOG_INFO)
id = RNS.Identity()
id.to_file(idpath)
self.id = RNS.Identity.from_file(idpath)
id = RNS.Identity(True)
id.to_file(idfile)
self.id = RNS.Identity.from_file(idfile)
RNS.log('Loaded identity from file', RNS.LOG_INFO)
# start RNS and LXMFRouter
@ -37,8 +39,9 @@ class LXMFBot:
self._announce()
def _announce(self):
if os.path.isfile(self.announce_path):
with open(self.announce_path, "r") as f:
announce_path = os.path.join(self.config_path, "announce")
if os.path.isfile(announce_path):
with open(announce_path, "r") as f:
announce = int(f.readline())
else:
RNS.log('failed to open announcepath', RNS.LOG_DEBUG)
@ -46,7 +49,7 @@ class LXMFBot:
if announce > int(time.time()):
RNS.log('Recent announcement', RNS.LOG_DEBUG)
else:
with open(self.announce_path, "w+") as af:
with open(announce_path, "w+") as af:
next_announce = int(time.time()) + 1800
af.write(str(next_announce))
self.local.announce()