|
@@ -1,16 +1,40 @@
|
|
|
import pymumble_py3 as pymumble
|
|
|
+from pymumble_py3.constants import *
|
|
|
import subprocess as sp
|
|
|
import time
|
|
|
import sys
|
|
|
import os
|
|
|
import fcntl
|
|
|
import audioop
|
|
|
+import argparse
|
|
|
|
|
|
+def message_received(message):
|
|
|
+ global is_streaming
|
|
|
+ if message == "/start":
|
|
|
+ is_streaming = True
|
|
|
+ elif message == "/stop":
|
|
|
+ is_streaming = False
|
|
|
+
|
|
|
+parser = argparse.ArgumentParser(description='Regia pienamente automatizzata')
|
|
|
+parser.add_argument('--channel', help='Set channel')
|
|
|
+parser.add_argument('--name', help='Set bot nickname', default="RadioRobbot")
|
|
|
+parser.add_argument('--server', help='Set server', default="mumble.esiliati.org")
|
|
|
+parser.add_argument('--port', help='Set port', type=int)
|
|
|
+parser.add_argument('--stream', action='store_true', help='Ignore commands in chat and stream everything')
|
|
|
+sys.argv.pop(0)
|
|
|
+args = parser.parse_args(sys.argv)
|
|
|
+
|
|
|
+
|
|
|
pwd = "" # password
|
|
|
-server = "mumble.esiliati.org" # server address
|
|
|
-nick = "TubiaBot"
|
|
|
-channel = "radiospore"
|
|
|
-port = 64738 # port number
|
|
|
+server = args.server
|
|
|
+nick = args.name
|
|
|
+channel = args.channel
|
|
|
+port = args.port
|
|
|
+is_streaming=False
|
|
|
+stream_always= args.stream
|
|
|
+
|
|
|
+
|
|
|
+mumble.callbacks.set_callback(PYMUMBLE_CLBK_TEXTMESSAGERECEIVED, message_received)
|
|
|
|
|
|
# Spin up a client and connect to mumble server
|
|
|
mumble = pymumble.Mumble(server, nick, password=pwd, port=port)
|
|
@@ -46,12 +70,13 @@ while mumble.is_alive():
|
|
|
else:
|
|
|
base_sound = audioop.add(base_sound, stereo_pcm, 2)
|
|
|
except RuntimeError:
|
|
|
- eprint("ignored exception in stderr...")
|
|
|
-
|
|
|
- if base_sound:
|
|
|
- sys.stdout.buffer.write(base_sound)
|
|
|
- else:
|
|
|
- sys.stdout.buffer.write(silent)
|
|
|
+ print("ignored exception in stderr...", file=sys.stderr)
|
|
|
+
|
|
|
+ if is_streaming or stream_always:
|
|
|
+ if base_sound:
|
|
|
+ sys.stdout.buffer.write(base_sound)
|
|
|
+ else:
|
|
|
+ sys.stdout.buffer.write(silent)
|
|
|
|
|
|
cursor_time += FLOAT_RESOLUTION
|
|
|
else:
|