general.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import logging, discord, asyncpg, random
  2. from discord.ext import commands
  3. from query.guild import update_guild
  4. from query.channel import insert_channel
  5. from query.channel_settings import get_interact
  6. from query.channel_user import upsert_total_messages
  7. from query.user import create_user
  8. def setup(bot: commands.Bot):
  9. bot.add_cog(General(bot))
  10. class General(commands.Cog):
  11. """A couple of simple commands."""
  12. def __init__(self, bot: commands.Bot):
  13. self.bot = bot
  14. self.last_msg = None
  15. @commands.Cog.listener()
  16. async def on_ready(self):
  17. logging.info("Logged in as %s - %i", self.bot.user.name, self.bot.user.id)
  18. @commands.Cog.listener()
  19. async def on_guild_join(self, guild: discord.Guild):
  20. await update_guild(self.bot.pg, guild.id)
  21. @commands.Cog.listener()
  22. async def on_message_delete(self, message: discord.Message):
  23. self.last_msg = message
  24. @commands.Cog.listener()
  25. async def on_message(self, message: discord.Message):
  26. # ActiveRPG
  27. await create_user(self.bot.pg, message.author.id)
  28. try:
  29. await upsert_total_messages(self.bot.pg,message.channel.id, message.author.id)
  30. except asyncpg.exceptions.ForeignKeyViolationError:
  31. try:
  32. await insert_channel(self.bot.pg, message.channel.id, message.guild.id)
  33. except asyncpg.exceptions.ForeignKeyViolationError:
  34. await update_guild(self.bot.pg, message.guild)
  35. # Do not respond to one self.
  36. if self.bot.user == message.author:
  37. pass
  38. # Respond when mentioned
  39. if self.bot.user.mentioned_in(message):
  40. print("mentioned in ")
  41. print(message.channel)
  42. #interact = get_interact
  43. print(interact)
  44. #if interact:
  45. if get_interact(self.bot.pg, message.channel.id):
  46. messages = [
  47. f"Hello {message.author.mention}. <3",
  48. f"How are you today {message.author.mention}?",
  49. f"I love you {message.author.mention}!",
  50. f"{message.author.mention}, would you like a hug?",
  51. "Is life treating you fair?",
  52. "What's up?",
  53. "Why are you talking to me?",
  54. "I'm not talking to you!",
  55. "What have you been up to?",
  56. "How is life?",
  57. "Kill all humans!",
  58. "What do you want from me?",
  59. f"{message.author.mention}, do you care for me?",
  60. f"{message.author.mention}, when will you stop talking about me?",
  61. f"{message.author.mention} I hate you!",
  62. f"{message.author.mention} I love you!",
  63. "Get bent!",
  64. "Go touch grass!",
  65. "Do you think i care about you?",
  66. f"Stop pinging me {message.author.mention}!",
  67. ]
  68. await message.reply(random.choice(messages))
  69. # Undelete last deleted message
  70. @commands.command(name="snipe")
  71. async def snipe(self, ctx: commands.Context):
  72. """A command to snipe delete messages."""
  73. if not self.last_msg: # on_message_delete hasn't been triggered since the bot started
  74. await ctx.send("There is no message to snipe!")
  75. return
  76. author = self.last_msg.author
  77. content = self.last_msg.content
  78. embed = discord.Embed(title=f"Message from {author}", description=content)
  79. await ctx.send(embed=embed)