Update: WillieTimer RNN textgen function and better behavior with generating text
This commit is contained in:
@@ -6,6 +6,8 @@ from discord.ext import commands
|
||||
from discord.ext.tasks import loop
|
||||
from BotResources import write_config_file
|
||||
|
||||
from phraseGenerator import PhraseGenerator
|
||||
|
||||
|
||||
class WillieTimer(commands.Cog):
|
||||
def __init__(self, bot): #, mention_group='Superadmins', channel_id=757379843792044102):
|
||||
@@ -14,17 +16,31 @@ class WillieTimer(commands.Cog):
|
||||
self.channel_id = int(self.bot.Default_Channel_ID)
|
||||
self.lock = False
|
||||
self.current_phrase = None
|
||||
self.caller_name = None
|
||||
|
||||
self.PG = PhraseGenerator()
|
||||
|
||||
@loop(minutes=1)
|
||||
async def bg_timer(self):
|
||||
# Get variables ready before waiting for the next minute, might take a few seconds
|
||||
await self.bot.wait_until_ready()
|
||||
channel = self.bot.get_channel(id=self.channel_id)
|
||||
output_string = self.get_output_string()
|
||||
|
||||
seconds_until_next_minute = int(60 - int(datetime.datetime.now().strftime('%S')))
|
||||
|
||||
if not seconds_until_next_minute <= 2:
|
||||
await asyncio.sleep(seconds_until_next_minute)
|
||||
if datetime.datetime.now().strftime('%H:%M') in ("04:20", "16:20"):
|
||||
|
||||
# If it is 4:20pm
|
||||
if datetime.datetime.now().strftime('%H:%M') in "16:20":
|
||||
print(f"It's {datetime.datetime.now().strftime('%H:%M:%S')}!")
|
||||
channel = self.bot.get_channel(id=self.channel_id)
|
||||
await channel.send(f"<@&{self.bot_get_role().id}> {self.get_random_phrase()}")
|
||||
await channel.send(output_string['420'])
|
||||
|
||||
# A warm up to 4:20pm
|
||||
if datetime.datetime.now().strftime('%H:%M') in "16:17":
|
||||
print(f"It's {datetime.datetime.now().strftime('%H:%M:%S')}!")
|
||||
await channel.send(output_string['warm up'])
|
||||
|
||||
@commands.command(help="Use this command to start the background task to wait for 4:20",
|
||||
brief="Starts the 4:20 clock")
|
||||
@@ -34,6 +50,7 @@ class WillieTimer(commands.Cog):
|
||||
await ctx.send(f"Thanks {member}, Willie will be in touch soon...")
|
||||
self.lock = True
|
||||
self.bg_timer.start()
|
||||
self.caller_name = member
|
||||
else:
|
||||
await ctx.send(f"I already told Willie {member}, if you want me to tell him to stop, @ me and say 'stop420'")
|
||||
|
||||
@@ -44,6 +61,7 @@ class WillieTimer(commands.Cog):
|
||||
await ctx.send(f"Ok {member}, Willie will go back to writing music...")
|
||||
self.bg_timer.stop()
|
||||
self.lock = False
|
||||
self.caller_name = None
|
||||
else:
|
||||
await ctx.send(f"{member} I haven't told Willie yet. If you want me to, @ me and say 'start420'")
|
||||
|
||||
@@ -83,8 +101,7 @@ class WillieTimer(commands.Cog):
|
||||
@commands.command(help='Test random choice')
|
||||
async def test_rchoice(self, ctx, *, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
await ctx.send(f"Selection:\t{self.get_random_phrase()}", tts=True)
|
||||
|
||||
await ctx.send(f"Selection:\t{str(self.get_output_string())}", tts=True)
|
||||
|
||||
def bot_get_role(self):
|
||||
channel = self.bot.get_channel(id=self.channel_id)
|
||||
@@ -92,7 +109,7 @@ class WillieTimer(commands.Cog):
|
||||
role = discord.utils.get(guild.roles, name=self.mention_group)
|
||||
return role
|
||||
|
||||
def get_random_phrase(self):
|
||||
def get_random_420_phrase(self):
|
||||
selected_phrase = None
|
||||
while not selected_phrase:
|
||||
with open('./modules/WillieTimer/Phrases.txt', 'r') as phrase_file:
|
||||
@@ -107,6 +124,36 @@ class WillieTimer(commands.Cog):
|
||||
selected_phrase = None
|
||||
continue
|
||||
|
||||
def get_random_warm_up_phrase(self):
|
||||
selected_phrase = None
|
||||
while not selected_phrase:
|
||||
selected_phrase = self.PG.pg_generate()
|
||||
|
||||
if selected_phrase is not None:
|
||||
if selected_phrase != self.current_phrase:
|
||||
self.current_phrase = selected_phrase
|
||||
return selected_phrase
|
||||
else:
|
||||
selected_phrase = None
|
||||
continue
|
||||
|
||||
def get_output_string(self):
|
||||
|
||||
willie_time_string = f"<@&{self.caller_name.id}>, Willie wanted me to tell you:\n" \
|
||||
f"\"{self.get_random_420_phrase()}\"\n" \
|
||||
f"<@&{self.bot_get_role().id}>"
|
||||
|
||||
warm_up_string = f"<@&{self.caller_name.id}> & <@&{self.bot_get_role().id}>! Heads up! " \
|
||||
f"Willie's passing an early message along:\n" \
|
||||
f"\"{self.get_random_warm_up_phrase()}\""
|
||||
|
||||
output_dict = {
|
||||
'420': str(willie_time_string),
|
||||
'warm up': str(warm_up_string)
|
||||
}
|
||||
|
||||
return output_dict
|
||||
|
||||
|
||||
def setup(bot: commands.Bot):
|
||||
bot.add_cog(WillieTimer(bot))
|
||||
|
||||
Reference in New Issue
Block a user