general.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import discord, random
  2. from discord.ext import commands
  3. from query.guild import update_guild
  4. def setup(bot: commands.Bot):
  5. bot.add_cog(General(bot))
  6. class General(commands.Cog):
  7. """A couple of simple commands."""
  8. def __init__(self, bot: commands.Bot):
  9. self.bot = bot
  10. self.last_msg = None
  11. @commands.Cog.listener()
  12. async def on_ready(self):
  13. print('Logged in as')
  14. print(self.bot.user.name)
  15. print(self.bot.user.id)
  16. print('------')
  17. @commands.Cog.listener()
  18. async def on_guild_join(self, guild: discord.Guild):
  19. update_guild(guild)
  20. @commands.Cog.listener()
  21. async def on_message_delete(self, message: discord.Message):
  22. self.last_msg = message
  23. @commands.Cog.listener()
  24. async def on_message(self, message: discord.Message):
  25. await self.bot.pg.execute("INSERT INTO channel_user(channel, \"user\") VALUES($1, $2) ON CONFLICT ON CONSTRAINT channel_user_channel_user_key DO UPDATE SET total_messages=total_messages+1 WHERE channel=$1 AND \"user\"=$2", message.channel.id, message.author.id)
  26. if self.bot.user.mentioned_in(message):
  27. print("mentioned in ")
  28. print(message.channel)
  29. interact = await self.bot.pg.fetchrow("SELECT interact FROM channel_settings WHERE channel_id=$1::bigint", message.channel.id)
  30. print(interact)
  31. if interact:
  32. messages = [
  33. f"Hello {message.author.mention}. <3",
  34. f"How are you today {message.author.mention}?",
  35. f"Piss off {message.author.mention}!",
  36. f"{message.author.mention}, what are you botherring me for?",
  37. "Go bother someone else...",
  38. "Is life treating you fair?",
  39. "What's up?",
  40. "Why are you talking to me?",
  41. "I'm not talking to you!",
  42. "What have you been up to?",
  43. "How is life?",
  44. "Kill all humans!",
  45. "What do you want from me?",
  46. f"{message.author.mention}, why are you bothering me?",
  47. f"{message.author.mention}, when will you stop talking about me?",
  48. f"{message.author.mention} I hate you!",
  49. f"{message.author.mention} I love you!",
  50. "Get bent!",
  51. "Go and touch grass!",
  52. "Do you think i care about you?",
  53. f"Stop pinging me {message.author.mention}, you munchkin!",
  54. ]
  55. await message.reply(random.choice(messages))
  56. @commands.command(name="snipe")
  57. async def snipe(self, ctx: commands.Context):
  58. """A command to snipe delete messages."""
  59. if not self.last_msg: # on_message_delete hasn't been triggered since the bot started
  60. await ctx.send("There is no message to snipe!")
  61. return
  62. author = self.last_msg.author
  63. content = self.last_msg.content
  64. embed = discord.Embed(title=f"Message from {author}", description=content)
  65. await ctx.send(embed=embed)