async def tts(ctx): 'Lets chat use TTS w/o cheers or other events.' if tts_on is False: await ctx.send(f"@{ctx.author.name} => TTS is temporarily disabled.") return if tts_sub_only and (ctx.author.subscriber is False or ctx.author.is_mod is False): await ctx.send( f'@{ctx.author.name} => TTS is sub-only during IRL streams.') return print(ctx.content) token = ctx.content.split(' ', 1) await emit_tts(token[1]) log.debug(f'tts request detected in chat: {token[1]}')
async def sfx_func(ctx): if sfx_state is False: await ctx.send( f"@{ctx.author.name} => SFX are temporarily disabled.") return if sfx_sub_only and (ctx.author.subscriber is False or ctx.author.is_mod is False): await ctx.send( f'@{ctx.author.name} => SFX are sub-only at the moment.') return await emit_sfx(cmd_name_with_extenion ) # send the command to the server log.debug(f'SFX request detected in chat: {cmd_no_extension}')
""" Simple call/reponse commands w/o dependancies Commands w/o any integrations or external dependancies live here. Usually they are pretty simple commands. This is the place you'll wanna put 1-offs and your channel-unique stuff. """ from config.importer import bot, twitch_team, twitch_channel from server_interface import sio from utils.logger import loggymclogger as log from content import faq_info from utils.tools import list_commands from integrations.twitch.api_wrapper import interface log.debug(f"{__name__} loaded") ############################### CUSTOM COMMANDS ############################### """ Put your custom commands below!""" @bot.command(name='test', aliases=['t']) async def test_command(ctx): 'example command' log.info("test") # tests logging await ctx.send(f'Test passed, @{ctx.author.name}!') # tests chat ####################### CALL/RESPONSE COMMAND GENERATOR ####################### class CommandGenerator:
"""Checks filesystem for audio files that the bot app turns into SFX commands.""" import os from utils.logger import loggymclogger as log list_of_sfx_files = [] sfx_with_extentions = [] path = 'static/sfx/hooks/' for file in os.listdir(path): # create instance with attributes if file.endswith('.ogg') or file.endswith('.mp3') or file.endswith('.wav'): # add the file name to a list (including the extension) sfx_with_extentions.append(file) file = file[:-4] # removes the sextension list_of_sfx_files.append(file) log.debug(f"SFX Loaded: {list_of_sfx_files}")
async def on_repsponse(data): log.debug(f"[MSG RCVD] {data}")
async def on_connect(): log.debug(f"{__name__}.... CONNECTERD!") await sio.emit('connect', {'data': 'CONNECTERD!'})
def raid_event(methods=['GET', 'POST']): log.debug(f"RAID OCCURRRRRED") socketio.emit('raid triggered')
def get_sfx_event(methods=['GET', 'POST']): 'Sends list of SFX files so the bot can generate chat commands/objects.' log.debug(f"Bot application requested SFX files to generate commands.") # socketio.emit('send_sfx', list_of_sfx_files) # <- list serialized as json socketio.emit('send_sfx', sfx_with_extentions) # <- list serialized as json
def sfx_event(command, methods=['GET', 'POST']): 'Recievs SFX requests from bot app & triggers SFX on the Browser Source' sfx_command = str(command) socketio.emit('sfx trigger', sfx_command) log.debug(f"SFX Triggered => {sfx_command}")
def tts_event(data, methods=['GET', 'POST']): msg = str(data) socketio.emit('tts trigger', msg) log.debug(f"TTS Triggered => {msg}")
def handle_my_custom_event(json, methods=['GET', 'POST']): log.debug(f"RCVD: 'my event' // DATA: {str(json)}") socketio.emit('my response', json, callback=messageReceived)
async def emit_stream_event(event): # await sio.emit(event='stream event', data=event) log.debug(f"emitting {event} event") await sio.emit(event=event)
async def on_connect(): import tts # only import this if the websocket connection is made log.debug(f"{__name__}.... CONNECTERD!") await sio.emit('connect', {'data': 'CONNECTERD!'}) await sio.emit('get_sfx')