| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import discord, asyncpg, random
- from discord.ext import commands
- from query.guild import update_guild
- def setup(bot: commands.Bot):
- bot.add_cog(General(bot))
- class General(commands.Cog):
- """A couple of simple commands."""
- def __init__(self, bot: commands.Bot):
- self.bot = bot
- self.last_msg = None
- @commands.Cog.listener()
- async def on_ready(self):
- print('Logged in as')
- print(self.bot.user.name)
- print(self.bot.user.id)
- print('------')
- @commands.Cog.listener()
- async def on_guild_join(self, guild: discord.Guild):
- update_guild(guild)
- @commands.Cog.listener()
- async def on_message_delete(self, message: discord.Message):
- self.last_msg = message
- @commands.Cog.listener()
- async def on_message(self, message: discord.Message):
- # ActiveRPG
- await self.bot.pg.execute("INSERT INTO \"user\"(user_id) VALUES($1) ON CONFLICT DO NOTHING", message.author.id)
- try:
- 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=channel_user.total_messages+1", message.channel.id, message.author.id)
- except asyncpg.exceptions.ForeignKeyViolationError:
- try:
- await self.bot.pg.execute("INSERT INTO channel(channel_id, guild) VALUES($1, $2)", message.channel.id, message.guild.id)
- except asyncpg.exceptions.ForeignKeyViolationError:
- update_guild(message.guild.id)
-
- # Do not respond to one self.
- if self.bot.user == message.author:
- pass
- # Respond when mentioned
- if self.bot.user.mentioned_in(message):
- print("mentioned in ")
- print(message.channel)
- interact = await self.bot.pg.fetchrow("SELECT interact FROM channel_settings WHERE channel_id=$1::bigint", message.channel.id)
- print(interact)
- if interact:
- messages = [
- f"Hello {message.author.mention}. <3",
- f"How are you today {message.author.mention}?",
- f"I love you {message.author.mention}!",
- f"{message.author.mention}, would you like a hug?",
- "Is life treating you fair?",
- "What's up?",
- "Why are you talking to me?",
- "I'm not talking to you!",
- "What have you been up to?",
- "How is life?",
- "Kill all humans!",
- "What do you want from me?",
- f"{message.author.mention}, do you care for me?",
- f"{message.author.mention}, when will you stop talking about me?",
- f"{message.author.mention} I hate you!",
- f"{message.author.mention} I love you!",
- "Get bent!",
- "Go touch grass!",
- "Do you think i care about you?",
- f"Stop pinging me {message.author.mention}!",
- ]
- await message.reply(random.choice(messages))
- # Undelete last deleted message
- @commands.command(name="snipe")
- async def snipe(self, ctx: commands.Context):
- """A command to snipe delete messages."""
- if not self.last_msg: # on_message_delete hasn't been triggered since the bot started
- await ctx.send("There is no message to snipe!")
- return
- author = self.last_msg.author
- content = self.last_msg.content
- embed = discord.Embed(title=f"Message from {author}", description=content)
- await ctx.send(embed=embed)
|