identity per bot
This commit is contained in:
parent
4280ba5624
commit
0a30648495
3 changed files with 22 additions and 11 deletions
10
README.md
10
README.md
|
|
@ -38,4 +38,12 @@ def echo_msg(msg):
|
||||||
msg.reply(msg.content)
|
msg.reply(msg.content)
|
||||||
|
|
||||||
bot.run()
|
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>`
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from lxmfbot import LXMFBot
|
from lxmfbot import LXMFBot
|
||||||
|
|
||||||
bot = LXMFBot("NodeBot")
|
bot = LXMFBot("testbot")
|
||||||
|
|
||||||
@bot.received
|
@bot.received
|
||||||
def echo_msg(msg):
|
def echo_msg(msg):
|
||||||
|
|
|
||||||
21
lxmfbot.py
21
lxmfbot.py
|
|
@ -19,13 +19,15 @@ class LXMFBot:
|
||||||
# initialize identiy
|
# initialize identiy
|
||||||
self.name = name
|
self.name = name
|
||||||
dirs = AppDirs("LXMFBot", "randogoth")
|
dirs = AppDirs("LXMFBot", "randogoth")
|
||||||
idpath = os.path.join(dirs.user_data_dir, "identity")
|
self.config_path = os.path.join(dirs.user_data_dir, name)
|
||||||
self.announce_path = os.path.join(dirs.user_data_dir, "announce")
|
idfile = os.path.join(self.config_path, "identity")
|
||||||
if not os.path.isfile(idpath):
|
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)
|
RNS.log('No Primary Identity file found, creating new...', RNS.LOG_INFO)
|
||||||
id = RNS.Identity()
|
id = RNS.Identity(True)
|
||||||
id.to_file(idpath)
|
id.to_file(idfile)
|
||||||
self.id = RNS.Identity.from_file(idpath)
|
self.id = RNS.Identity.from_file(idfile)
|
||||||
RNS.log('Loaded identity from file', RNS.LOG_INFO)
|
RNS.log('Loaded identity from file', RNS.LOG_INFO)
|
||||||
|
|
||||||
# start RNS and LXMFRouter
|
# start RNS and LXMFRouter
|
||||||
|
|
@ -37,8 +39,9 @@ class LXMFBot:
|
||||||
self._announce()
|
self._announce()
|
||||||
|
|
||||||
def _announce(self):
|
def _announce(self):
|
||||||
if os.path.isfile(self.announce_path):
|
announce_path = os.path.join(self.config_path, "announce")
|
||||||
with open(self.announce_path, "r") as f:
|
if os.path.isfile(announce_path):
|
||||||
|
with open(announce_path, "r") as f:
|
||||||
announce = int(f.readline())
|
announce = int(f.readline())
|
||||||
else:
|
else:
|
||||||
RNS.log('failed to open announcepath', RNS.LOG_DEBUG)
|
RNS.log('failed to open announcepath', RNS.LOG_DEBUG)
|
||||||
|
|
@ -46,7 +49,7 @@ class LXMFBot:
|
||||||
if announce > int(time.time()):
|
if announce > int(time.time()):
|
||||||
RNS.log('Recent announcement', RNS.LOG_DEBUG)
|
RNS.log('Recent announcement', RNS.LOG_DEBUG)
|
||||||
else:
|
else:
|
||||||
with open(self.announce_path, "w+") as af:
|
with open(announce_path, "w+") as af:
|
||||||
next_announce = int(time.time()) + 1800
|
next_announce = int(time.time()) + 1800
|
||||||
af.write(str(next_announce))
|
af.write(str(next_announce))
|
||||||
self.local.announce()
|
self.local.announce()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue