50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
import json
|
|
# from this import d
|
|
import discord
|
|
import time
|
|
import os
|
|
from discord.ext import commands
|
|
|
|
|
|
## Xeno Discord PY Bot
|
|
### same encoder
|
|
|
|
extname = f'SameEncoder'
|
|
|
|
initcurtime = time.localtime()
|
|
curtime = (f'{initcurtime.tm_hour}{initcurtime.tm_min}{initcurtime.tm_sec}')
|
|
curdate = (f'{initcurtime.tm_year}{initcurtime.tm_mon}{initcurtime.tm_mday}')
|
|
fnameformat = (f'XenoSAME_{curdate}_{curtime}.wav')
|
|
|
|
class SameEncoder(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
@commands.command(name='sameencode', pass_context=True)
|
|
async def sameencode(self, ctx, arg):
|
|
print(f"Cog_{extname}: encoding same message! {arg} for user {ctx.message.author.name}")
|
|
# await ctx.send(f"(for debugging only!!) Cog_{extname}: encoding same message! {arg} for user {ctx.message.author.name} (filename:")
|
|
os.system(f'python extensions/same.py --code "{arg}" --outfile "data/{extname}/{fnameformat}" >> data/{extname}/samepy_{curdate}_{curtime}.txt')
|
|
if not os.path.exists(f'data/{extname}/XenoSAME_{curdate}_{curtime}.wav'):
|
|
print(f'Cog_{extname}: same encoding failed! @ {curdate} {curtime}')
|
|
else:
|
|
print(f"Cog_{extname}: encoded at {curtime} on {curdate}, sending to channel user requested this in")
|
|
# await ctx.send(f"(for debugging only!!) Cog_{extname}: encoded at {curtime} on {curdate}, sending to channel user requested this in")
|
|
await ctx.reply(file=discord.File(f'data/{extname}/XenoSAME_{curdate}_{curtime}.wav'))
|
|
|
|
#encoder telemetry log
|
|
encodelog = open("data/SameEncoder/encoder.log", "a")
|
|
encodelog.write(f"Cog_{extname}: {curdate} @ {curtime}: {ctx.message.author} in {ctx.guild.name} ({ctx.guild.id}) encoded {arg}")
|
|
encodelog.close()
|
|
|
|
def initFolder():
|
|
if not os.path.exists(f"data/{extname}"):
|
|
print(f"Cog_{extname}: sameencode data folder wasn't found, creating it")
|
|
os.makedirs(f"data/{extname}")
|
|
else:
|
|
print(f"Cog_{extname}: {extname} data folder exists, we jud")
|
|
|
|
async def setup(bot):
|
|
initFolder()
|
|
print(f'Cog_SameEncoder was initialized')
|
|
await bot.add_cog(SameEncoder(bot)) |