diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index 7518036..a1565d3 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -5,8 +5,7 @@
mariadb
true
org.mariadb.jdbc.Driver
- jdbc:mariadb://localhost:3306/c1woam_bot
- $ProjectFileDir$
+ jdbc:mariadb://localhost:3307/c1woam_bot
\ No newline at end of file
diff --git a/.idea/dataSources/112d4e6b-18c0-47f6-af79-cbfa6a945483.xml b/.idea/dataSources/112d4e6b-18c0-47f6-af79-cbfa6a945483.xml
index 0771246..b043336 100644
--- a/.idea/dataSources/112d4e6b-18c0-47f6-af79-cbfa6a945483.xml
+++ b/.idea/dataSources/112d4e6b-18c0-47f6-af79-cbfa6a945483.xml
@@ -1,6 +1,6 @@
-
+
10.5.9
InnoDB
@@ -1021,7 +1021,7 @@
localhost
- ALL PRIVILEGES|c1woam_bot
+ ALL PRIVILEGES|c1woam_bot:null
diff --git a/index.js b/index.js
index 0e2257d..c822731 100644
--- a/index.js
+++ b/index.js
@@ -36,7 +36,7 @@ const con = mySQL.createConnection ( {
password: config.mysqlPassword
} );
-let badWords = {"0":{}};
+let badWords = {}; // 0 => {1:2,}
con.connect(function(err) {
if (err) {
@@ -75,7 +75,7 @@ client.on ( "message", async ( message ) =>
// Filter goes here
- if ( checkMessage ( message.content ) )
+ if ( checkMessage ( message.guild.id, message.content ) )
{
await message.delete ();
let notifyChannelID = getNotifyChannel ( message.guild.id );
@@ -204,7 +204,7 @@ function createServerEntry( a_ServerID, a_ServerName )
}
-function checkMessage( a_Message )
+function checkMessage( a_ServerID, a_Message )
{
/*let query = "SELECT word FROM words WHERE word LIKE ?";
con.query( query, ['%' + a_Message + '%'], function( error, results, fields ) {
@@ -213,6 +213,49 @@ function checkMessage( a_Message )
console.log ( `[ERROR] An error occurred while fetching th` )
}
} );*/
+ if( badWords[a_ServerID].contains( a_Message ) )
+ {
+ return true;
+ }
+
+ return false;
+}
+
+function refreshWords( a_ServerID )
+{
+ // Add the word to the database
+ let query = "SELECT id, word FROM words WHERE guildID = ?";
+ con.query( query, [ a_ServerID ], function( error, results, fields ) {
+ if( error )
+ {
+ console.log ( `[ERROR] An error occurred while getting filter for guild ${a_ServerID}` );
+ return false;
+ }
+ for (let i = 0; i < results.length; i++ ) {
+ badWords[a_ServerID][results[i].id] = results[i].word;
+ }
+ return true;
+ } );
+ return false;
+}
+
+function loadAllUp()
+{
+ console.log( "[INFO] Loading all up..." );
+ // LOADING ALL UP, can take a while
+ // Add the word to the database
+ let query = "SELECT id, guild_id FROM guilds";
+ con.query( query, function( error, results, fields ) {
+ if( error )
+ {
+ console.log ( `[ERROR] An error occurred while loading all up` );
+ return false;
+ }
+ for (let i = 0; i < results.length; i++) {
+ refreshWords( results[i].guild_id );
+ }
+ return true;
+ } );
return false;
}
@@ -229,9 +272,20 @@ function getNotifyChannel( a_ServerID )
return 0;
}
-function deleteWord( a_Index )
+function deleteWord( a_ServerID, a_Index )
{
// Delete the word out of the database
+ // Add the word to the database
+ let query = "DELETE FROM words WHERE id = ? AND guildID = ?";
+ con.query( query, [ a_Index, a_ServerID ], function( error, results, fields ) {
+ if( error )
+ {
+ console.log ( `[ERROR] An error occurred while inserting a new filter entry` );
+ return false;
+ }
+ return true;
+ } );
+ return false;
}
function addWord( a_ServerID, a_Word )