modifications to existing commands

added latency measurement to ping command, added typing event to ai command
This commit is contained in:
NodeStorm 2020-08-16 22:28:40 +03:00 committed by GitHub
parent 5eab1393da
commit c5f5c17a37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 21 deletions

View File

@ -9,7 +9,7 @@ class Basic(commands.Cog):
@commands.command()
async def ping(self, ctx):
await ctx.send("pong!")
await ctx.send(f"Pong! **{round(self.client.latency*1000, 1)}ms**")
@commands.command(aliases=["cp"], brief="Change the guild-wide bot prefix", usage="<prefix>")
@commands.guild_only()

View File

@ -14,33 +14,34 @@ class Lydia(commands.Cog):
@commands.command(aliases=["lydia"], brief="Have a chat with Lydia", usage="<chat>")
async def ai(self, ctx, *, quest):
self.cur.execute(f'SELECT * FROM sessions WHERE user_id="{ctx.author.id}"')
query = self.cur.fetchone()
async with ctx.channel.typing():
self.cur.execute(f'SELECT * FROM sessions WHERE user_id="{ctx.author.id}"')
query = self.cur.fetchone()
if query == None:
session = self.lydia.create_session()
self.cur.execute(f"INSERT INTO sessions VALUES ('{ctx.author.id}','{session.id}','{session.expires}')")
self.conn.commit()
await ctx.send(session.think_thought(quest))
else:
#give it a 50 second margin to avoid possible errors
if query[2]-50 < int(time.time()):
self.cur.execute(f'DELETE FROM sessions WHERE session_id = "{query[1]}"')
if query == None:
session = self.lydia.create_session()
self.cur.execute(f"INSERT INTO sessions VALUES ('{ctx.author.id}','{session.id}','{session.expires}')")
self.conn.commit()
await ctx.send(session.think_thought(quest))
#or alternatively
#reply = session.think_thought(quest)
#await ctx.send(reply)
else:
await ctx.send(self.lydia.think_thought(query[1], quest))
#or alternatively
#reply = self.lydia.think_thought(query[1], quest)
#await ctx.send(reply)
#give it a 50 second margin to avoid possible errors
if query[2]-50 < int(time.time()):
self.cur.execute(f'DELETE FROM sessions WHERE session_id = "{query[1]}"')
session = self.lydia.create_session()
self.cur.execute(f"INSERT INTO sessions VALUES ('{ctx.author.id}','{session.id}','{session.expires}')")
self.conn.commit()
await ctx.send(session.think_thought(quest))
#or alternatively
#reply = session.think_thought(quest)
#await ctx.send(reply)
else:
await ctx.send(self.lydia.think_thought(query[1], quest))
#or alternatively
#reply = self.lydia.think_thought(query[1], quest)
#await ctx.send(reply)
#uncomment this if you use the alternatives
#print(f"[<]{ctx.message.author}: {quest}\n[>]{reply}")