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 hashlib
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
ROOT = "/home/bot/ticker"
|
||||||
|
SEGUIS = 665399296522321942
|
||||||
|
GOONS = 369294266905657345
|
||||||
|
RETARD_DIMENSION = 695090043609415740
|
||||||
|
MATT = 150791815723876352
|
||||||
|
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
s = AsyncIOScheduler(event_loop = client.loop)
|
s = AsyncIOScheduler(event_loop = client.loop)
|
||||||
c = CurrencyRates()
|
c = CurrencyRates()
|
||||||
|
@ -16,6 +22,17 @@ c = CurrencyRates()
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(client.user.name)
|
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 update(trigger, guild_id):
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
async def wrapper():
|
async def wrapper():
|
||||||
|
@ -25,33 +42,23 @@ def update(trigger, guild_id):
|
||||||
|
|
||||||
guild = client.get_guild(guild_id) # 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)
|
matt_voice = next(filter(lambda member: member.id == MATT, guild.members)).voice
|
||||||
channel = channels[0] if len(channels) else client.get_channel(673203690672357422) # main channel of seguis III
|
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)
|
await say(filename, channel)
|
||||||
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()))
|
|
||||||
|
|
||||||
s.add_job(wrapper, trigger = trigger)
|
s.add_job(wrapper, trigger = trigger)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
SEGUIS = 665399296522321942
|
def to_tts(message, lang = 'ja'):
|
||||||
GOONS = 369294266905657345
|
|
||||||
|
|
||||||
def to_tts(message):
|
|
||||||
message_hash = hashlib.md5(message.encode('utf-8')).hexdigest()
|
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):
|
if not os.path.isfile(file_name):
|
||||||
print("file does not exist, cacheing")
|
print("file does not exist, cacheing")
|
||||||
tts = gTTS(message)
|
tts = gTTS(message, lang = lang)
|
||||||
tts.save(file_name)
|
tts.save(file_name)
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
|
@ -69,25 +76,13 @@ async def drip():
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_voice_state_update(member, before, after):
|
async def on_voice_state_update(member, before, after):
|
||||||
RETARD_DIMENSION = 695090043609415740
|
|
||||||
|
|
||||||
await client.wait_until_ready()
|
await client.wait_until_ready()
|
||||||
|
|
||||||
if after.channel == client.get_channel(RETARD_DIMENSION):
|
if after.channel == client.get_channel(RETARD_DIMENSION):
|
||||||
filename = to_tts(member.display_name + " has moved to the Retard Dimension")
|
await say(to_tts(member.display_name + "はretard dimensionに移動しました"), before.channel)
|
||||||
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()
|
s.start()
|
||||||
|
|
||||||
with open("./priv/token") as file:
|
with open(ROOT + "/priv/token") as file:
|
||||||
token = file.readline()
|
token = file.readline()
|
||||||
client.run(token)
|
client.run(token)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user