root 3 anni fa
parent
commit
f86e3ffc8f
2 ha cambiato i file con 36 aggiunte e 12 eliminazioni
  1. 21 8
      bot/events/general.py
  2. 15 4
      bot/query/initialise_database.py

+ 21 - 8
bot/events/general.py

@@ -1,4 +1,4 @@
-import discord, random
+import discord, asyncpg, random
 from discord.ext import commands
 from query.guild import update_guild
 
@@ -29,8 +29,21 @@ class General(commands.Cog):
 
 	@commands.Cog.listener()
 	async def on_message(self, message: discord.Message):
-		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)
+		# 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)
@@ -40,9 +53,8 @@ class General(commands.Cog):
 				messages = [
 					f"Hello {message.author.mention}. <3",
 					f"How are you today {message.author.mention}?",
-					f"Piss off {message.author.mention}!",
-					f"{message.author.mention}, what are you botherring me for?",
-					"Go bother someone else...",
+					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?",
@@ -51,17 +63,18 @@ class General(commands.Cog):
 					"How is life?",
 	                "Kill all humans!",
 					"What do you want from me?",
-					f"{message.author.mention}, why are you bothering 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 and touch grass!",
+					"Go touch grass!",
 					"Do you think i care about you?",
-					f"Stop pinging me {message.author.mention}, you munchkin!",
+					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."""

+ 15 - 4
bot/query/initialise_database.py

@@ -1,5 +1,16 @@
 async def init_db(pg):
-    await pg.execute("CREATE TABLE IF NOT EXISTS guild (id SERIAL PRIMARY KEY, guild_id BIGINT UNIQUE NOT NULL)")
-    await pg.execute("CREATE TABLE IF NOT EXISTS channel (id SERIAL PRIMARY KEY, channel_id BIGINT UNIQUE NOT NULL, guild BIGINT REFERENCES guild (guild_id))")
-    await pg.execute("CREATE TABLE IF NOT EXISTS channel_settings (id SERIAL PRIMARY KEY, channel BIGINT UNIQUE NOT NULL REFERENCES channel (channel_id), guild BIGINT REFERENCES guild (guild_id), interact BOOL DEFAULT FALSE)")
-    await pg.execute("CREATE TABLE IF NOT EXISTS channel_user (id SERIAL PRIMARY KEY, channel BIGINT NOT NULL REFERENCES channel (channel_id), \"user\" BIGINT NOT NULL, total_messages BIGINT DEFAULT 1, UNIQUE (channel, \"user\"))")
+    await pg.execute(
+        "CREATE TABLE IF NOT EXISTS guild (id SERIAL PRIMARY KEY, guild_id BIGINT UNIQUE NOT NULL)"
+    )
+    await pg.execute(
+        "CREATE TABLE IF NOT EXISTS channel (id SERIAL PRIMARY KEY, channel_id BIGINT UNIQUE NOT NULL, guild BIGINT REFERENCES guild (guild_id))"
+    )
+    await pg.execute(
+        "CREATE TABLE IF NOT EXISTS channel_settings (id SERIAL PRIMARY KEY, channel BIGINT UNIQUE NOT NULL REFERENCES channel (channel_id), guild BIGINT REFERENCES guild (guild_id), interact BOOL DEFAULT FALSE)"
+    )
+    await pg.execute(
+        "CREATE TABLE IF NOT EXISTS \"user\" (id SERIAL PRIMARY KEY, user_id BIGINT UNIQUE NOT NULL)"
+    )
+    await pg.execute(
+        "CREATE TABLE IF NOT EXISTS channel_user (id SERIAL PRIMARY KEY, channel BIGINT NOT NULL REFERENCES channel (channel_id), \"user\" BIGINT NOT NULL REFERENCES \"user\" (user_id), total_messages BIGINT DEFAULT 1, UNIQUE (channel, \"user\"))"
+    )