async def start_(self, ctx: Context): """ Начало трансляции. Аналог resume но без подсчёта зрителей %%start """ if not self.bot.check_sender(ctx, 'iarspider'): asyncio.ensure_future( ctx.send('/timeout ' + ctx.author.name + ' 1')) return # self.get_player() # self.player_play_pause() if self.ws is not None: if self.vr: self.switch_to('VR Game') self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic2(), False)) else: self.switch_to('Game') self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic1(), False)) self.ws.call(obsws_requests.SetMute(True, 'Радио')) self.ws.call(obsws_requests.StartRecording())
def MuteSourceOff(Action): if "SourceName" in Action: try: ws.call(requests.SetMute(Action["SourceName"], False)) except: PrintError("Couldn't unmute " + Action["SourceName"]) else: PrintError("No SourceName argument in action config")
async def resume(self, ctx: Context): """ Отменяет перерыв %%resume """ if not self.bot.check_sender(ctx, 'iarspider'): asyncio.ensure_future( ctx.send('/timeout ' + ctx.author.name + ' 1')) return # self.logger.info("get_player()") # self.get_player() # self.logger.info("player_play_pause()") # self.player_play_pause() if self.ws is not None: if self.vr: self.switch_to('VR Game') self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic2(), False)) else: self.logger.info("switch to game") self.switch_to('Game') self.logger.info("unmute mic") self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic1(), False)) self.ws.call(obsws_requests.SetMute(True, 'Радио')) self.ws.call(obsws_requests.ResumeRecording()) try: self.logger.info("get stream") res = await self.bot.my_get_stream(self.bot.user_id) self.logger.info("got stream") viewers = numeral.get_plural(res['viewer_count'], ('зритель', 'зрителя', 'зрителей')) self.logger.info("prepared message") asyncio.ensure_future( ctx.send('Перепись населения завершена успешно! ' f'Население стрима составляет {viewers}')) self.logger.info("sent message") except (KeyError, TypeError) as exc: asyncio.ensure_future(ctx.send('Перепись населения не удалась :(')) self.logger.error(str(exc))
def do_pause(self, ctx: Context, is_dinner: bool): # self.get_player() # self.player_play_pause() if self.ws is not None: self.ws.call(obsws_requests.PauseRecording()) self.ws.call( obsws_requests.SetSceneItemProperties(scene_name="Paused", item="ужин", visible=is_dinner)) self.switch_to('Paused') if self.vr: self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic2(), True)) else: self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic1(), True)) self.ws.call(obsws_requests.SetMute(False, 'Радио')) # self.get_chatters() asyncio.ensure_future(ctx.send('Начать перепись населения!')) asyncio.ensure_future(self.bot.my_run_commercial(self.bot.user_id, 60))
def ToggleMuteSource(Action, ws, midi_out): if "SourceName" in Action: try: MuteState = ws.call(requests.GetMute(Action["SourceName"])) MuteState = MuteState.getMuted() except: print("Couldn't get mute state") else: try: ws.call(requests.SetMute(Action["SourceName"], not MuteState)) except: print("Couldn't toggle mute state of " + Action["SourceName"]) else: if MuteState == True: MidiLed(Action, "off", midi_out) else: MidiLed(Action, "on", midi_out) PrintWithTime("Toggled the mute state of " + Action["SourceName"]) else: print("No SourceName argument in action config")
def mute(bh, msg, mute=True): ws.connect() # Request everything be muted for mic in MICROPHONES: ws.call(requests.SetMute(mic, mute=mute)) # Go through again, verify that all the muting worked mute_status = [] for mic in MICROPHONES: ret = ws.call(requests.GetMute(mic)) print(ret) mute_status.append(ret.getMuted()) ws.disconnect() # React based on if everything was muted or not. React based on current # status (currently muted or not), not based on if it was successful or # not. if all(mute_status): bh.react(msg, 'mute_notifications') elif not any(mute_status): bh.react(msg, 'notifications') else: return "Mute statuses: %s" % ' '.join(str(x) for x in mute_status)
async def countdown(self, ctx: Context): def write_countdown_html(): args = ctx.message.content.split()[1:] parts = tuple(int(x) for x in args[0].split(':')) if len(parts) == 2: m, s = parts m, s = parts # noinspection PyShadowingNames delta = datetime.timedelta(minutes=m, seconds=s) dt = datetime.datetime.now() + delta elif len(parts) == 3: h, m, s = parts dt = datetime.datetime.now().replace(hour=h, minute=m, second=s) else: self.botlogger.error("Invalid call to countdown: {0}".format( args[0])) return self.bot.countdown_to = dt with codecs.open(self.htmlfile.replace('html', 'template'), encoding='UTF-8') as f: lines = f.read() lines = lines.replace('@@date@@', dt.isoformat()) with codecs.open(self.htmlfile, 'w', encoding='UTF-8') as f: f.write(lines) if not self.bot.check_sender(ctx, 'iarspider'): return if not self.ws: return res: obsws_requests.GetStreamingStatus = self.ws.call( obsws_requests.GetStreamingStatus()) if res.getStreaming(): self.logger.error('Already streaming!') return write_countdown_html() self.ws.call(obsws_requests.DisableStudioMode()) # Refresh countdown self.ws.call(obsws_requests.SetCurrentScene('Starting')) try: self.ws.call( obsws_requests.SetMute(self.aud_sources.getMic2(), True)) except KeyError: self.logger.warning("[WARN] Can't mute mic-2, please check!") self.ws.call(obsws_requests.SetMute(self.aud_sources.getMic1(), True)) self.ws.call(obsws_requests.EnableStudioMode()) self.ws.call(obsws_requests.StartStopStreaming()) time.sleep(1) self.ws.call(obsws_requests.PauseRecording()) # self.get_player() # self.player_play_pause() self.ws.call(obsws_requests.SetMute(False, 'Радио')) asyncio.ensure_future( ctx.send('Начат обратный отсчёт до {0}!'.format( self.bot.countdown_to.strftime('%X')))) asyncio.ensure_future(self.bot.my_run_commercial(self.bot.user_id)) self.logger.info("Getting Discord cog...") discord_bot = self.bot.get_cog('DiscordCog') if discord_bot: self.logger.info("Got it, requesting announce...") asyncio.ensure_future(discord_bot.announce()) else: self.logger.warning("Discord cog not found")
def audio_cb(values): self.osc.answer('/audio', [values]) self.client.call( requests.SetMute(self.audio_sources['desktop'], values < 1.0))
def mic_cb(values): self.osc.answer('/mic', [values]) self.client.call( requests.SetMute(self.audio_sources['mic'], values < 1.0))
def SetSourceMute(self, SourceName, muteBool): try: self.ws.call(requests.SetMute(SourceName, muteBool)) except Exception as e: print(e)
port = str(p).split(" - ")[0] break States = [] LayoutDir = os.getcwd()+"\\Layouts" with open("Setup.txt","r") as data: values = data.readlines() for i in range(0,len(values)): exec(values[i]) with open(LayoutDir+"\\"+CurrentLayout,"r") as json_data: States = json.load(json_data) try: client = obsws("localhost", 4444, obspswd) client.connect() client.call(requests.SetMute("Mic/Aux",False)) except: None ser = serial.Serial(port,9600,timeout=0) BaseTime = datetime.datetime.now().strftime('%M') curr_time = datetime.datetime.now().strftime('%H:%M') ser.write(ser.write(str(curr_time)+','+str('N/A')+','+str('N/A'))) try: while True: StreamDeck = ser.readline().rstrip() try: if(StreamDeck.isdigit()): Action = States["Button"+StreamDeck]["Action"] exec(Action["Name"]+"(client,Action)") except: None
def do_mic_unmute(self): self.ws.call(requests.SetMute(self.aud_sources.getMic1(), False)) self.load_volume_m(self.aud_sources.getMic1())
def audio_unmute(self, name): res = self._call(requests.SetMute(name, False)) return res.status
def SetMute(self, *args): arg = [] arg.append(args[0]) arg.append(int(args[1]) > 0) return self.ws.call(requests.SetMute(*arg))
def Sources_SetMute(self, muteStatus = True, SourceName="", *args, **kwargs): # Not tested try: self.ws.call(requests.SetMute(SourceName, muteStatus)) PrintWithTime(f"Set mute of source {SourceName} to {muteStatus}") except Exception as e: PrintWithTime(f"Couldn't set mute of source {SourceName} to {muteStatus}. Error : {e}")