Skip to content

Commit de29ddb

Browse files
committed
fixed missing folder, more instance options
1 parent 95ec09a commit de29ddb

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ $ pip install -r requirements.txt
1010

1111
## Usage
1212

13-
- Instantiate the class with a name for the bot as parameter
13+
- Instantiate the class with a `name` for the bot as parameter.
14+
- 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`)
1415
- Use the `received` decorator to define functions for parsing received messages
1516
- Use the `<instance>.send(recipient_hash, message)` or `msg.reply(message)` methods to send messages
1617
- Launch the bot using the `run` method

lxmfbot.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ class LXMFBot:
1313
delivery_callbacks = []
1414
receipts = []
1515
queue = Queue(maxsize = 5)
16+
announce_time = 360
1617

17-
def __init__(self, name='LXMFBot'):
18+
def __init__(self, name='LXMFBot', announce=360, announce_immediately=False):
1819

1920
# initialize identiy
2021
self.name = name
22+
self.announce_time = announce
2123
dirs = AppDirs("LXMFBot", "randogoth")
2224
self.config_path = os.path.join(dirs.user_data_dir, name)
2325
idfile = os.path.join(self.config_path, "identity")
26+
if not os.path.isdir(dirs.user_data_dir):
27+
os.mkdir(dirs.user_data_dir)
2428
if not os.path.isdir(self.config_path):
2529
os.mkdir(self.config_path)
2630
if not os.path.isfile(idfile):
@@ -29,6 +33,11 @@ def __init__(self, name='LXMFBot'):
2933
id.to_file(idfile)
3034
self.id = RNS.Identity.from_file(idfile)
3135
RNS.log('Loaded identity from file', RNS.LOG_INFO)
36+
if announce_immediately:
37+
af = os.path.join(self.config_path, "announce")
38+
if os.path.isfile(af):
39+
os.remove(af)
40+
RNS.log('Announcing now. Timer reset.', RNS.LOG_INFO)
3241

3342
# start RNS and LXMFRouter
3443
RNS.Reticulum(loglevel=RNS.LOG_VERBOSE)
@@ -50,7 +59,7 @@ def _announce(self):
5059
RNS.log('Recent announcement', RNS.LOG_DEBUG)
5160
else:
5261
with open(announce_path, "w+") as af:
53-
next_announce = int(time.time()) + 1800
62+
next_announce = int(time.time()) + self.announce_time
5463
af.write(str(next_announce))
5564
self.local.announce()
5665
RNS.log('Announcement sent, expr set 1800 seconds', RNS.LOG_INFO)

0 commit comments

Comments
 (0)