ban league again

This commit is contained in:
aliasless 2020-04-14 07:23:11 +00:00
parent f32fabaa92
commit 4c5e130058
1 changed files with 44 additions and 23 deletions

View File

@ -10,17 +10,26 @@ import hashlib
import os.path
ROOT = "/home/bot/ticker"
# gulids
SEGUIS = 665399296522321942
GOONS = 499822662281854996
GOONS = 369294266905657345
# users
MATT = 150791815723876352
DAD = 509547108907614208
CHEW = 193919775007703040
# channels
SMOKEYS = 673203690672357422
RETARD = 695090043609415740
GHETTO = 699505527981473794
client = discord.Client()
c = CurrencyRates()
ticker_queue = asyncio.Queue()
tts_queue = asyncio.Queue()
# returns a file path from the cache
def to_tts(message, lang = 'ja'):
@ -28,6 +37,8 @@ def to_tts(message, lang = 'ja'):
message_hash = hashlib.md5(message.encode('utf-8')).hexdigest()
file_name = ROOT + "/cache/" + message_hash + ".mp3"
print(message)
# if the hash matches and existing file, well...
if not os.path.isfile(file_name):
print("file does not exist, cacheing")
@ -42,7 +53,7 @@ async def ticker_update():
await client.wait_until_ready()
# blocks until there is a message in the queue
announce_file, target_voice_channel = await ticker_queue.get()
announce_file, target_voice_channel, after = await ticker_queue.get()
print("ticker event has been removed from queue")
# there are three scenarios here
@ -73,6 +84,9 @@ async def ticker_update():
while voice_client.is_playing():
await asyncio.sleep(0.1)
if after:
await after(target_voice_channel)
# once all ticker events have completed, dc
if ticker_queue.empty():
await voice_client.disconnect()
@ -88,6 +102,9 @@ async def on_voice_state_update(member, before, after):
await asyncio.sleep(randint(3, 30))
await member.move_to(client.get_channel(RETARD))
if member.id == CHEW and not before.channel:
await add_event(to_tts("Hey everyone, the pineapple is here!", 'en'), after.channel)
# only run on moves
if before.channel and after.channel:
# moves to the afk channel
@ -95,25 +112,6 @@ async def on_voice_state_update(member, before, after):
file_name = to_tts(member.display_name + "はretard dimensionに移動しました")
await add_event(file_name, before.channel)
# ban league
@client.event
async def on_member_update(before, after):
# literally any of these fields might not exist and python has no safe navigation
# nor does it have pattern matching usable for this purpose
# guess i'll die
before_name = None
if before and before.activity and before.activity.type == discord.ActivityType.playing and before.activity.name:
before_name = before.activity.name
after_name = None
if after and after.activity and after.activity.type == discord.ActivityType.playing and after.activity.name:
after_name = after.activity.name
if before_name != after_name:
if after_name == "League of Legends" and after.voice:
file_name = to_tts("Stop playing League, " + after.display_name)
await add_event(file_name, after.voice.channel)
client.loop.create_task(ticker_update())
# either matts channel, or the most active channel
@ -126,9 +124,9 @@ def get_best_channel(guild_id):
top_channel = sorted(guild.voice_channels, key = lambda chan: len(chan.members), reverse = True)[0]
return matt_voice if matt_voice else top_channel
async def add_event(file_name, voice_channel):
async def add_event(file_name, voice_channel, after = None):
print("ticker event has been added to queue")
await ticker_queue.put((file_name, voice_channel))
await ticker_queue.put((file_name, voice_channel, after))
async def ticker():
voice_channel = get_best_channel(SEGUIS)
@ -145,10 +143,33 @@ async def cummies():
file_name = to_tts("くむづりっぽぷっししりっと")
await add_event(file_name, voice_channel)
# ban league
async def league_ghetto():
await client.wait_until_ready()
leaguers = filter(lambda member: member.activity and member.activity.type == discord.ActivityType.playing
and member.activity.name == 'League of Legends' and member.voice and member.voice.channel
and member.voice.channel.id != GHETTO, client.get_guild(SEGUIS).members)
for member in leaguers:
# using the id because i don't know the internals of this library and i dont care to check
# its entirely possible that the same object is used after the move_to and if before_channel
# referenced that then its in the bone zone.
before_channel = member.voice.channel.id
# why doesn't python have async lambdas yet?
async def move(_):
await member.move_to(client.get_channel(GHETTO))
file_name = to_tts(member.display_name + ", you have been found in violation of the No League Act of 2020. Administrative action will now be taken against your account.", lang = 'de')
await add_event(file_name, client.get_channel(before_channel), move)
s = AsyncIOScheduler(event_loop = client.loop)
s.add_job(ticker, CronTrigger(hour = '0-19,21-23'))
s.add_job(flatten, CronTrigger(hour = '20'))
s.add_job(cummies, CronTrigger(hour = '*', minute = '30'))
s.add_job(league_ghetto, CronTrigger(minute = '*'))
s.start()
with open(ROOT + "/priv/token") as file: