Skip to content

Commit 41b7caf

Browse files
moved to lora-gateway pi
1 parent 7af339c commit 41b7caf

File tree

1 file changed

+83
-83
lines changed

1 file changed

+83
-83
lines changed

summon.py

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
channels = ['nurdbottest', 'nurds', 'nurdsbofh'] # TODO: channels to respond to
2525
prefix = '!' # !command, will be updated by ghbot
2626
db = 'summon.db'
27-
meshtastic_host = '10.208.43.239'
27+
#meshtastic_host = '10.208.43.239'
2828

2929
# summoncfg.py should contain:
3030
#xmpp_user = '...jabber account...'
@@ -38,69 +38,69 @@
3838
cur.close()
3939

4040

41-
def send_meshtastic(text):
42-
global meshtastic_host
43-
44-
if meshtastic_host != None:
45-
try:
46-
import meshtastic
47-
import meshtastic.tcp_interface
48-
49-
iface = meshtastic.tcp_interface.TCPInterface(meshtastic_host)
50-
51-
iface.sendText(text)
52-
53-
n_nodes = len(iface.nodes.values()) if iface.nodes else 0
54-
55-
iface.close()
56-
57-
return n_nodes
58-
59-
except Exception as e:
60-
print(f'{time.ctime()} Exception during "meshtastic": {e}, line number: {e.__traceback__.tb_lineno}')
61-
62-
return None
63-
64-
def send_meshtastic_info():
65-
global meshtastic_host
66-
67-
if meshtastic_host != None:
68-
try:
69-
import meshtastic
70-
import meshtastic.tcp_interface
71-
72-
iface = meshtastic.tcp_interface.TCPInterface(meshtastic_host, debugOut=sys.stdout)
73-
74-
rc = iface.showInfo()
75-
76-
iface.close()
77-
78-
return rc
79-
80-
except Exception as e:
81-
print(f'Exception during "meshtastic": {e}, line number: {e.__traceback__.tb_lineno}')
82-
83-
return None
41+
#def send_meshtastic(text):
42+
# global meshtastic_host
43+
#
44+
# if meshtastic_host != None:
45+
# try:
46+
# import meshtastic
47+
# import meshtastic.tcp_interface
48+
#
49+
# iface = meshtastic.tcp_interface.TCPInterface(meshtastic_host)
50+
#
51+
# iface.sendText(text)
52+
#
53+
# n_nodes = len(iface.nodes.values()) if iface.nodes else 0
54+
#
55+
# iface.close()
56+
#
57+
# return n_nodes
58+
#
59+
# except Exception as e:
60+
# print(f'{time.ctime()} Exception during "meshtastic": {e}, line number: {e.__traceback__.tb_lineno}')
61+
#
62+
# return None
63+
#
64+
#def send_meshtastic_info():
65+
# global meshtastic_host
66+
#
67+
# if meshtastic_host != None:
68+
# try:
69+
# import meshtastic
70+
# import meshtastic.tcp_interface
71+
#
72+
# iface = meshtastic.tcp_interface.TCPInterface(meshtastic_host, debugOut=sys.stdout)
73+
#
74+
# rc = iface.showInfo()
75+
#
76+
# iface.close()
77+
#
78+
# return rc
79+
#
80+
# except Exception as e:
81+
# print(f'Exception during "meshtastic": {e}, line number: {e.__traceback__.tb_lineno}')
82+
#
83+
# return None
8484

8585
def summon(nick, text, by_whom, channel):
8686
global con
87-
global meshtastic_host
87+
# global meshtastic_host
8888

8989
ok = True
9090

91-
t = threading.Thread(target=send_meshtastic, args=(text,))
92-
t.daemon = True
93-
t.start()
91+
# t = threading.Thread(target=send_meshtastic, args=(text,))
92+
# t.daemon = True
93+
# t.start()
9494

9595
cur = con.cursor()
9696
cur.execute('SELECT email, jabber FROM entities WHERE nick=?', (nick.lower(),))
9797

9898
row = cur.fetchone()
9999
if row == None:
100-
if meshtastic_host != None:
101-
return (False, 'Summoned via meshtastic')
102-
103-
else:
100+
# if meshtastic_host != None:
101+
# return (False, 'Summoned via meshtastic')
102+
#
103+
# else:
104104
return (False, 'nothing registered for user')
105105

106106
email = row[0]
@@ -148,10 +148,10 @@ def summon(nick, text, by_whom, channel):
148148
return (False, f'Exception during "xmpp": {e}, line number: {e.__traceback__.tb_lineno}')
149149

150150
if not email and not jabber:
151-
if meshtastic_host != None:
152-
return (False, 'Summoned via meshtastic')
153-
154-
else:
151+
# if meshtastic_host != None:
152+
# return (False, 'Summoned via meshtastic')
153+
#
154+
# else:
155155
return (False, 'No summon protocol registered for that user')
156156

157157
return (True, '')
@@ -160,8 +160,8 @@ def announce_commands(client):
160160
target_topic = f'{topic_prefix}to/bot/register'
161161

162162
client.publish(target_topic, "cmd=summon|descr=Try to get someone's attention")
163-
client.publish(target_topic, "cmd=meshtastic|descr=Try to get someone's attention via meshtastic")
164-
client.publish(target_topic, "cmd=meshinfo|descr=Meshtastic state info")
163+
# client.publish(target_topic, "cmd=meshtastic|descr=Try to get someone's attention via meshtastic")
164+
# client.publish(target_topic, "cmd=meshinfo|descr=Meshtastic state info")
165165

166166
def on_message(client, userdata, message):
167167
global prefix
@@ -212,31 +212,31 @@ def on_message(client, userdata, message):
212212
except Exception as e:
213213
client.publish(response_topic, f'Exception during "summon": {e}, line number: {e.__traceback__.tb_lineno}')
214214

215-
elif command == 'meshtastic':
216-
try:
217-
only_nick = nick[0:nick.find('!')]
218-
219-
only_text = text[text.find(' '):].strip()
220-
221-
msg = f'{only_nick}: {only_text}'
222-
223-
n_nodes = send_meshtastic(msg)
224-
225-
if n_nodes == None:
226-
client.publish(response_topic, 'Fail')
227-
228-
else:
229-
client.publish(response_topic, f'Sent to aprox. {n_nodes} nodes')
230-
231-
except Exception as e:
232-
client.publish(response_topic, f'Exception during "meshtastic": {e}, line number: {e.__traceback__.tb_lineno}')
233-
234-
elif command == 'meshinfo':
235-
try:
236-
print(send_meshtastic_info())
237-
238-
except Exception as e:
239-
client.publish(response_topic, f'Exception during "meshinfo": {e}, line number: {e.__traceback__.tb_lineno}')
215+
# elif command == 'meshtastic':
216+
# try:
217+
# only_nick = nick[0:nick.find('!')]
218+
#
219+
# only_text = text[text.find(' '):].strip()
220+
#
221+
# msg = f'{only_nick}: {only_text}'
222+
#
223+
# n_nodes = send_meshtastic(msg)
224+
#
225+
# if n_nodes == None:
226+
# client.publish(response_topic, 'Fail')
227+
#
228+
# else:
229+
# client.publish(response_topic, f'Sent to aprox. {n_nodes} nodes')
230+
#
231+
# except Exception as e:
232+
# client.publish(response_topic, f'Exception during "meshtastic": {e}, line number: {e.__traceback__.tb_lineno}')
233+
#
234+
# elif command == 'meshinfo':
235+
# try:
236+
# print(send_meshtastic_info())
237+
#
238+
# except Exception as e:
239+
# client.publish(response_topic, f'Exception during "meshinfo": {e}, line number: {e.__traceback__.tb_lineno}')
240240

241241
def on_connect(client, userdata, flags, rc):
242242
client.subscribe(f'{topic_prefix}from/irc/#')

0 commit comments

Comments
 (0)