cacheing
This commit is contained in:
parent
4d305a8172
commit
24164f19a0
|
@ -1,2 +1,2 @@
|
|||
*.mp3
|
||||
token
|
||||
priv
|
||||
cache
|
||||
|
|
57
ticker.py
57
ticker.py
|
@ -5,6 +5,8 @@ from forex_python.converter import CurrencyRates
|
|||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
import asyncio
|
||||
import hashlib
|
||||
import os.path
|
||||
|
||||
client = discord.Client()
|
||||
s = AsyncIOScheduler(event_loop = client.loop)
|
||||
|
@ -14,14 +16,14 @@ c = CurrencyRates()
|
|||
async def on_ready():
|
||||
print(client.user.name)
|
||||
|
||||
def update(trigger):
|
||||
def update(trigger, guild_id):
|
||||
def decorator(func):
|
||||
async def wrapper():
|
||||
filename = await func()
|
||||
|
||||
await client.wait_until_ready()
|
||||
|
||||
guild = client.get_guild(665399296522321942) # id of seguis III
|
||||
guild = client.get_guild(guild_id) # id of seguis III
|
||||
|
||||
channels = sorted(guild.voice_channels, key = lambda x: len(x.members), reverse = True)
|
||||
channel = channels[0] if len(channels) else client.get_channel(673203690672357422) # main channel of seguis III
|
||||
|
@ -41,20 +43,51 @@ def update(trigger):
|
|||
|
||||
return decorator
|
||||
|
||||
@update(CronTrigger(hour = '0-19,21-23'))
|
||||
async def ticker():
|
||||
tts = gTTS("The current JPY exchange rate is " + str(c.get_rate('USD', 'JPY')) + " yen to a dollar")
|
||||
tts.save('rate.mp3')
|
||||
return "rate.mp3"
|
||||
SEGUIS = 665399296522321942
|
||||
GOONS = 369294266905657345
|
||||
|
||||
@update(CronTrigger(hour = '20'))
|
||||
def to_tts(message):
|
||||
message_hash = hashlib.md5(message.encode('utf-8')).hexdigest()
|
||||
file_name = "./cache/" + message_hash + ".mp3"
|
||||
if not os.path.isfile(file_name):
|
||||
print("file does not exist, cacheing")
|
||||
tts = gTTS(message)
|
||||
tts.save(file_name)
|
||||
return file_name
|
||||
|
||||
@update(CronTrigger(hour = '0-19,21-23'), SEGUIS)
|
||||
async def ticker():
|
||||
return to_tts("The current JPY exchange rate is " + str(c.get_rate('USD', 'JPY')) + " yen to one dollar")
|
||||
|
||||
@update(CronTrigger(hour = '20'), SEGUIS)
|
||||
async def flatten():
|
||||
tts = gTTS("matt, it is time for your 4pm dick flattening")
|
||||
tts.save('flatten.mp3')
|
||||
return "flatten.mp3"
|
||||
return to_tts("Matt, it is time for your 4 PM dick flattening")
|
||||
|
||||
@update(CronTrigger(hour = '*/2', minute = '30'), GOONS)
|
||||
async def drip():
|
||||
return to_tts("Cum drip, pussy slit")
|
||||
|
||||
@client.event
|
||||
async def on_voice_state_update(member, before, after):
|
||||
RETARD_DIMENSION = 695090043609415740
|
||||
|
||||
await client.wait_until_ready()
|
||||
|
||||
if after.channel == client.get_channel(RETARD_DIMENSION):
|
||||
filename = to_tts(member.display_name + " has moved to the Retard Dimension")
|
||||
source = discord.FFmpegOpusAudio(filename)
|
||||
voice_client = await before.channel.connect()
|
||||
voice_client.play(source)
|
||||
|
||||
while voice_client.is_playing():
|
||||
await asyncio.sleep(0.1)
|
||||
await voice_client.disconnect()
|
||||
|
||||
print(filename + " played at " + str(datetime.now()))
|
||||
|
||||
|
||||
s.start()
|
||||
|
||||
with open("token") as file:
|
||||
with open("./priv/token") as file:
|
||||
token = file.readline()
|
||||
client.run(token)
|
||||
|
|
Loading…
Reference in New Issue