fixed scheduled events
This commit is contained in:
parent
a16e10c075
commit
367e5a5772
40
ticker.py
40
ticker.py
|
@ -34,6 +34,8 @@ def to_tts(message, lang = 'ja'):
|
|||
# coroutine responsible for handling the queue as events come in
|
||||
async def ticker_update():
|
||||
while True:
|
||||
await client.wait_until_ready()
|
||||
|
||||
# blocks until there is a message in the queue
|
||||
announce_file, target_voice_channel = await ticker_queue.get()
|
||||
print("ticker event has been removed from queue")
|
||||
|
@ -85,35 +87,25 @@ async def on_voice_state_update(member, before, after):
|
|||
|
||||
client.loop.create_task(ticker_update())
|
||||
|
||||
def update(guild_id):
|
||||
def decorator(func):
|
||||
async def wrapper():
|
||||
filename = await func()
|
||||
# either matts channel, or the most active channel
|
||||
def get_best_channel(guild_id):
|
||||
guild = client.get_guild(guild_id)
|
||||
matt = discord.utils.find(lambda m: m.id == MATT, guild.members)
|
||||
|
||||
await client.wait_until_ready()
|
||||
# why the fuck does python still not have safe navigation operators?
|
||||
matt_voice = ((matt.voice.channel if matt.voice.channel else None) if matt.voice else None) if matt else None
|
||||
top_channel = sorted(guild.voice_channels, key = lambda chan: len(chan.members), reverse = True)[0]
|
||||
return matt_voice if matt_voice else top_channel
|
||||
|
||||
guild = client.get_guild(guild_id)
|
||||
matt = discord.utils.find(lambda m: m.id == MATT, guild.members)
|
||||
|
||||
# why the fuck does python still not have safe navigation operators?
|
||||
matt_voice = ((matt.voice.channel if matt.voice.channel else None) if matt.voice else None) if matt else None
|
||||
|
||||
top_channel = sorted(guild.voice_channels, key = lambda chan: len(chan.members), reverse = True)[0]
|
||||
channel = matt_voice if matt_voice else top_channel
|
||||
|
||||
ticker_queue.put((filename, channel))
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
@update(SEGUIS)
|
||||
async def ticker():
|
||||
return to_tts("The current JPY exchange rate is " + str(c.get_rate('USD', 'JPY')) + " yen to a dollar")
|
||||
print("ticker event has been added to queue")
|
||||
file_name = to_tts("The current JPY exchange rate is " + str(c.get_rate('USD', 'JPY')) + " yen to a dollar")
|
||||
await ticker_queue.put((file_name, get_best_channel(SEGUIS)))
|
||||
|
||||
@update(SEGUIS)
|
||||
async def flatten():
|
||||
return to_tts("Matt, it is time for your 4 PM dick flattening")
|
||||
print("ticker event has been added to queue")
|
||||
file_name = to_tts("Matt, it is time for your 4 PM dick flattening")
|
||||
await ticker_queue.put((file_name, get_best_channel(SEGUIS)))
|
||||
|
||||
s = AsyncIOScheduler(event_loop = client.loop)
|
||||
s.add_job(ticker, CronTrigger(hour = '0-19,21-23'))
|
||||
|
|
Loading…
Reference in New Issue