|
|
@@ -1,6 +1,10 @@
|
|
|
import logging, discord, asyncpg, random
|
|
|
from discord.ext import commands
|
|
|
from query.guild import update_guild
|
|
|
+from query.channel import insert_channel
|
|
|
+from query.channel_settings import get_interact
|
|
|
+from query.channel_user import upsert_total_messages
|
|
|
+from query.user import create_user
|
|
|
|
|
|
def setup(bot: commands.Bot):
|
|
|
bot.add_cog(General(bot))
|
|
|
@@ -12,13 +16,14 @@ class General(commands.Cog):
|
|
|
self.bot = bot
|
|
|
self.last_msg = None
|
|
|
|
|
|
+
|
|
|
@commands.Cog.listener()
|
|
|
async def on_ready(self):
|
|
|
logging.info("Logged in as %s - %i", self.bot.user.name, self.bot.user.id)
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
async def on_guild_join(self, guild: discord.Guild):
|
|
|
- update_guild(guild)
|
|
|
+ await update_guild(self.bot.pg, guild.id)
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
async def on_message_delete(self, message: discord.Message):
|
|
|
@@ -27,14 +32,17 @@ class General(commands.Cog):
|
|
|
@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)
|
|
|
+ #await self.bot.pg.execute("INSERT INTO \"user\"(user_id) VALUES($1) ON CONFLICT DO NOTHING", message.author.id)
|
|
|
+ await create_user(self.bot.pg, 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)
|
|
|
+ #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)
|
|
|
+ await upsert_total_messages(self.bot.pg,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)
|
|
|
+ #await self.bot.pg.execute("INSERT INTO channel(channel_id, guild) VALUES($1, $2)", message.channel.id, message.guild.id)
|
|
|
+ await insert_channel(self.bot.pg, message.channel.id, message.guild.id)
|
|
|
except asyncpg.exceptions.ForeignKeyViolationError:
|
|
|
- update_guild(message.guild.id)
|
|
|
+ await update_guild(self.bot.pg, message.guild)
|
|
|
|
|
|
# Do not respond to one self.
|
|
|
if self.bot.user == message.author:
|
|
|
@@ -44,9 +52,10 @@ class General(commands.Cog):
|
|
|
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)
|
|
|
+ #interact = get_interact
|
|
|
print(interact)
|
|
|
- if interact:
|
|
|
+ #if interact:
|
|
|
+ if get_interact(self.bot.pg, message.channel.id):
|
|
|
messages = [
|
|
|
f"Hello {message.author.mention}. <3",
|
|
|
f"How are you today {message.author.mention}?",
|
|
|
@@ -83,4 +92,4 @@ class General(commands.Cog):
|
|
|
content = self.last_msg.content
|
|
|
|
|
|
embed = discord.Embed(title=f"Message from {author}", description=content)
|
|
|
- await ctx.send(embed=embed)
|
|
|
+ await ctx.send(embed=embed)
|