fixed missing folder, more instance options
This commit is contained in:
parent
95ec09a41b
commit
de29ddb054
2 changed files with 13 additions and 3 deletions
|
|
@ -10,7 +10,8 @@ $ pip install -r requirements.txt
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
- Instantiate the class with a name for the bot as parameter
|
- Instantiate the class with a `name` for the bot as parameter.
|
||||||
|
- Two additional options the class takes as parameters are `announce` to define the announce interval in seconds (defaults to `360`) and an `announce_immediately` boolean to define whether the bot should announce itself immediately after instantiation or not (defaults to `False`)
|
||||||
- Use the `received` decorator to define functions for parsing received messages
|
- Use the `received` decorator to define functions for parsing received messages
|
||||||
- Use the `<instance>.send(recipient_hash, message)` or `msg.reply(message)` methods to send messages
|
- Use the `<instance>.send(recipient_hash, message)` or `msg.reply(message)` methods to send messages
|
||||||
- Launch the bot using the `run` method
|
- Launch the bot using the `run` method
|
||||||
|
|
|
||||||
13
lxmfbot.py
13
lxmfbot.py
|
|
@ -13,14 +13,18 @@ class LXMFBot:
|
||||||
delivery_callbacks = []
|
delivery_callbacks = []
|
||||||
receipts = []
|
receipts = []
|
||||||
queue = Queue(maxsize = 5)
|
queue = Queue(maxsize = 5)
|
||||||
|
announce_time = 360
|
||||||
|
|
||||||
def __init__(self, name='LXMFBot'):
|
def __init__(self, name='LXMFBot', announce=360, announce_immediately=False):
|
||||||
|
|
||||||
# initialize identiy
|
# initialize identiy
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.announce_time = announce
|
||||||
dirs = AppDirs("LXMFBot", "randogoth")
|
dirs = AppDirs("LXMFBot", "randogoth")
|
||||||
self.config_path = os.path.join(dirs.user_data_dir, name)
|
self.config_path = os.path.join(dirs.user_data_dir, name)
|
||||||
idfile = os.path.join(self.config_path, "identity")
|
idfile = os.path.join(self.config_path, "identity")
|
||||||
|
if not os.path.isdir(dirs.user_data_dir):
|
||||||
|
os.mkdir(dirs.user_data_dir)
|
||||||
if not os.path.isdir(self.config_path):
|
if not os.path.isdir(self.config_path):
|
||||||
os.mkdir(self.config_path)
|
os.mkdir(self.config_path)
|
||||||
if not os.path.isfile(idfile):
|
if not os.path.isfile(idfile):
|
||||||
|
|
@ -29,6 +33,11 @@ class LXMFBot:
|
||||||
id.to_file(idfile)
|
id.to_file(idfile)
|
||||||
self.id = RNS.Identity.from_file(idfile)
|
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)
|
||||||
|
if announce_immediately:
|
||||||
|
af = os.path.join(self.config_path, "announce")
|
||||||
|
if os.path.isfile(af):
|
||||||
|
os.remove(af)
|
||||||
|
RNS.log('Announcing now. Timer reset.', RNS.LOG_INFO)
|
||||||
|
|
||||||
# start RNS and LXMFRouter
|
# start RNS and LXMFRouter
|
||||||
RNS.Reticulum(loglevel=RNS.LOG_VERBOSE)
|
RNS.Reticulum(loglevel=RNS.LOG_VERBOSE)
|
||||||
|
|
@ -50,7 +59,7 @@ class LXMFBot:
|
||||||
RNS.log('Recent announcement', RNS.LOG_DEBUG)
|
RNS.log('Recent announcement', RNS.LOG_DEBUG)
|
||||||
else:
|
else:
|
||||||
with open(announce_path, "w+") as af:
|
with open(announce_path, "w+") as af:
|
||||||
next_announce = int(time.time()) + 1800
|
next_announce = int(time.time()) + self.announce_time
|
||||||
af.write(str(next_announce))
|
af.write(str(next_announce))
|
||||||
self.local.announce()
|
self.local.announce()
|
||||||
RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO)
|
RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue