fix priorities
This commit is contained in:
parent
24164f19a0
commit
5bf40c7e5d
57
ticker.py
57
ticker.py
|
@ -8,6 +8,12 @@ import asyncio
|
|||
import hashlib
|
||||
import os.path
|
||||
|
||||
ROOT = "/home/bot/ticker"
|
||||
SEGUIS = 665399296522321942
|
||||
GOONS = 369294266905657345
|
||||
RETARD_DIMENSION = 695090043609415740
|
||||
MATT = 150791815723876352
|
||||
|
||||
client = discord.Client()
|
||||
s = AsyncIOScheduler(event_loop = client.loop)
|
||||
c = CurrencyRates()
|
||||
|
@ -16,6 +22,17 @@ c = CurrencyRates()
|
|||
async def on_ready():
|
||||
print(client.user.name)
|
||||
|
||||
async def say(filename, channel):
|
||||
source = discord.FFmpegOpusAudio(filename)
|
||||
voice_client = await 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()))
|
||||
|
||||
def update(trigger, guild_id):
|
||||
def decorator(func):
|
||||
async def wrapper():
|
||||
|
@ -25,33 +42,23 @@ def update(trigger, guild_id):
|
|||
|
||||
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
|
||||
matt_voice = next(filter(lambda member: member.id == MATT, guild.members)).voice
|
||||
top_channel = sorted(guild.voice_channels, key = lambda chan: len(chan.members), reverse = True)[0]
|
||||
channel = matt_voice.channel if matt_voice else top_channel
|
||||
|
||||
source = discord.FFmpegOpusAudio(filename)
|
||||
voice_client = await 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()))
|
||||
await say(filename, channel)
|
||||
|
||||
s.add_job(wrapper, trigger = trigger)
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
SEGUIS = 665399296522321942
|
||||
GOONS = 369294266905657345
|
||||
|
||||
def to_tts(message):
|
||||
def to_tts(message, lang = 'ja'):
|
||||
message_hash = hashlib.md5(message.encode('utf-8')).hexdigest()
|
||||
file_name = "./cache/" + message_hash + ".mp3"
|
||||
file_name = ROOT + "/cache/" + message_hash + ".mp3"
|
||||
if not os.path.isfile(file_name):
|
||||
print("file does not exist, cacheing")
|
||||
tts = gTTS(message)
|
||||
tts = gTTS(message, lang = lang)
|
||||
tts.save(file_name)
|
||||
return file_name
|
||||
|
||||
|
@ -69,25 +76,13 @@ async def drip():
|
|||
|
||||
@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()))
|
||||
|
||||
await say(to_tts(member.display_name + "はretard dimensionに移動しました"), before.channel)
|
||||
|
||||
s.start()
|
||||
|
||||
with open("./priv/token") as file:
|
||||
with open(ROOT + "/priv/token") as file:
|
||||
token = file.readline()
|
||||
client.run(token)
|
||||
|
|
Loading…
Reference in New Issue