|
|
@ -3,7 +3,7 @@ import asyncio
|
|
|
|
import discord
|
|
|
|
import discord
|
|
|
|
import mariadb
|
|
|
|
import mariadb
|
|
|
|
from decouple import config
|
|
|
|
from decouple import config
|
|
|
|
from discord import Embed
|
|
|
|
from discord import Embed, DMChannel
|
|
|
|
from discord.ext import commands
|
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
|
|
|
|
import db
|
|
|
|
import db
|
|
|
@ -33,49 +33,53 @@ async def on_message(message):
|
|
|
|
if message.author.bot:
|
|
|
|
if message.author.bot:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Set up the connection to the database
|
|
|
|
if not isinstance(message.channel, DMChannel):
|
|
|
|
conn = db.connection()
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
|
|
|
# With the connection
|
|
|
|
|
|
|
|
with conn:
|
|
|
|
# Set up the connection to the database
|
|
|
|
|
|
|
|
conn = db.connection()
|
|
|
|
# Make sure that mariaDB errors are handled properly
|
|
|
|
|
|
|
|
try:
|
|
|
|
# With the connection
|
|
|
|
msg_name = message.author.name
|
|
|
|
with conn:
|
|
|
|
msg_discrim = message.author.discriminator
|
|
|
|
|
|
|
|
time = message.created_at
|
|
|
|
# Make sure that mariaDB errors are handled properly
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Get:
|
|
|
|
msg_name = message.author.name
|
|
|
|
guild_id = message.guild.id # Guild of the message
|
|
|
|
msg_discrim = message.author.discriminator
|
|
|
|
msg_time = time.strftime('%Y-%m-%d %H:%M:%S') # Time of the Message
|
|
|
|
time = message.created_at
|
|
|
|
msg_author = f"{msg_name}#{msg_discrim}" # DiscordID
|
|
|
|
|
|
|
|
msg_content = f"{message.content}" # Content of the message
|
|
|
|
# Get:
|
|
|
|
|
|
|
|
guild_id = message.guild.id # Guild of the message
|
|
|
|
# Store the variables
|
|
|
|
msg_time = time.strftime('%Y-%m-%d %H:%M:%S') # Time of the Message
|
|
|
|
val = guild_id, msg_time, msg_author, msg_content
|
|
|
|
msg_author = f"{msg_name}#{msg_discrim}" # DiscordID
|
|
|
|
|
|
|
|
msg_content = f"{message.content}" # Content of the message
|
|
|
|
attach = ""
|
|
|
|
|
|
|
|
# If an attachment (link) has been sent
|
|
|
|
# Store the variables
|
|
|
|
if message.attachments:
|
|
|
|
val = guild_id, msg_time, msg_author, msg_content
|
|
|
|
# Loop through all attachments
|
|
|
|
|
|
|
|
for attachment in message.attachments:
|
|
|
|
attach = ""
|
|
|
|
# Get the message content and the link that was used
|
|
|
|
# If an attachment (link) has been sent
|
|
|
|
attach += f"Message: {message.content} Link: {attachment.url}"
|
|
|
|
if message.attachments:
|
|
|
|
# Define the new variables to send
|
|
|
|
# Loop through all attachments
|
|
|
|
val = guild_id, msg_time, msg_author, attach
|
|
|
|
for attachment in message.attachments:
|
|
|
|
else:
|
|
|
|
# Get the message content and the link that was used
|
|
|
|
pass
|
|
|
|
attach += f"Message: {message.content} Link: {attachment.url}"
|
|
|
|
|
|
|
|
# Define the new variables to send
|
|
|
|
# Define the Insert Into Statement inserting into the database
|
|
|
|
val = guild_id, msg_time, msg_author, attach
|
|
|
|
insert_query = """INSERT INTO messages (guildID, messageTime, discordID, messageContent) VALUES (?, ?, ?, ?)"""
|
|
|
|
else:
|
|
|
|
cursor = conn.cursor()
|
|
|
|
pass
|
|
|
|
# Execute the SQL Query
|
|
|
|
|
|
|
|
cursor.execute(insert_query, val)
|
|
|
|
# Define the Insert Into Statement inserting into the database
|
|
|
|
conn.commit()
|
|
|
|
insert_query = """INSERT INTO messages (guildID, messageTime, discordID, messageContent) VALUES (?, ?, ?, ?)"""
|
|
|
|
print(cursor.rowcount, "Record inserted successfully into Logs")
|
|
|
|
cursor = conn.cursor()
|
|
|
|
|
|
|
|
# Execute the SQL Query
|
|
|
|
except mariadb.Error as ex:
|
|
|
|
cursor.execute(insert_query, val)
|
|
|
|
print("Parameterized Query Failed: {}".format(ex))
|
|
|
|
conn.commit()
|
|
|
|
|
|
|
|
print(cursor.rowcount, "Record inserted successfully into Logs")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except mariadb.Error as ex:
|
|
|
|
|
|
|
|
print("Parameterized Query Failed: {}".format(ex))
|
|
|
|
|
|
|
|
|
|
|
|
# Processing the message
|
|
|
|
# Processing the message
|
|
|
|
await client.process_commands(message)
|
|
|
|
await client.process_commands(message)
|
|
|
|