>Update bot
Took 51 minutes
This commit is contained in:
parent
6102599e5d
commit
b56fca07c7
97
index.js
97
index.js
@ -99,11 +99,12 @@ client.on ( "message", async ( message ) =>
|
||||
|
||||
// Filter goes here
|
||||
|
||||
if ( checkMessage ( message.guild.id, message.content ) )
|
||||
if ( await checkMessage ( message.guild.id, message.content ) )
|
||||
{
|
||||
await message.delete ();
|
||||
let notifyChannelID = getNotifyChannel ( message.guild.id );
|
||||
if ( notifyChannelID.length === 0 || notifyChannelID === 0 )
|
||||
let notifyChannelID = await getNotifyChannel ( message.guild.id );
|
||||
|
||||
if ( notifyChannelID.length < 1 || notifyChannelID === "" )
|
||||
{
|
||||
// NotifyChannel not send, so we gonna send the msg here
|
||||
const notify = new Discord.MessageEmbed ()
|
||||
@ -119,7 +120,8 @@ client.on ( "message", async ( message ) =>
|
||||
} );
|
||||
} else
|
||||
{
|
||||
const notifyChannel = message.member.guild.channels.cache.find ( ch => ch.id === notifyChannelID );
|
||||
|
||||
const notifyChannel = await message.member.guild.channels.cache.find ( ch => ch.id === notifyChannelID );
|
||||
const notify = new Discord.MessageEmbed ()
|
||||
.setColor ( "#b30202" )
|
||||
.setTitle ( "Nachricht gelöscht" )
|
||||
@ -145,7 +147,7 @@ client.on ( "message", async ( message ) =>
|
||||
await message.reply ( "mir wurde beigebracht, dass ich mit fremden Leuten nicht reden darf :c" );
|
||||
return;
|
||||
}
|
||||
let notifyChannelID = getNotifyChannel ( message.guild.id );
|
||||
let notifyChannelID = await getNotifyChannel ( message.guild.id );
|
||||
|
||||
const commandBody = message.content.slice ( config.prefix.length );
|
||||
const args = commandBody.split ( ' ' ); // 1=> arg
|
||||
@ -171,7 +173,7 @@ client.on ( "message", async ( message ) =>
|
||||
|
||||
for ( let wordsKey in words )
|
||||
{
|
||||
output += `${wordsKey}\t | \t${words[wordsKey]}\n`;
|
||||
output += `__${wordsKey}__\t | \t__${words[wordsKey]}__\n`;
|
||||
}
|
||||
|
||||
|
||||
@ -185,7 +187,7 @@ client.on ( "message", async ( message ) =>
|
||||
const index = Number.parseInt ( args[0] );
|
||||
if ( !isNaN ( index ) )
|
||||
{
|
||||
if( deleteWord( message.guild.id, args[0] ) === true )
|
||||
if( await deleteWord(message.guild.id, args[0]) === true )
|
||||
{
|
||||
await message.reply( `ich habe Index erfolgreich gelöscht! :D` );
|
||||
}
|
||||
@ -207,7 +209,7 @@ client.on ( "message", async ( message ) =>
|
||||
{
|
||||
if ( args.length > 0 )
|
||||
{
|
||||
if( addWord ( message.guild.id, args[0] ) )
|
||||
if( await addWord(message.guild.id, args[0]) )
|
||||
{
|
||||
await message.reply( `ich habe das Wort oder den Satz erfolgreich zu deinem Filter hinzugefügt! :D` );
|
||||
}
|
||||
@ -222,30 +224,53 @@ client.on ( "message", async ( message ) =>
|
||||
}
|
||||
}
|
||||
|
||||
if( command === "setnotify" || command === "setnotifychannel" || command === "setchannel" || command === "setchannel" )
|
||||
{
|
||||
await setNotifyChannel( message.guild.id, message.channel.id );
|
||||
await message.reply( `der neue Notify-Channel ist nun dieser hier!` );
|
||||
}
|
||||
|
||||
if ( command === "c" || command === "clear" )
|
||||
{
|
||||
await message.reply(`Befehl derzeit nicht aktiv!`);
|
||||
return;
|
||||
async function clear() {
|
||||
let fetched;
|
||||
do {
|
||||
fetched = await message.channel.messages.fetch({limit: 100});
|
||||
await message.channel.messages.bulkDelete(fetched);
|
||||
}
|
||||
while(fetched.size >= 2);
|
||||
}
|
||||
clear().then( () => { message.reply( `es wurden alle Nachrichten gelöscht!` ) } )
|
||||
}
|
||||
|
||||
if( command === "help" || command === "h" )
|
||||
{
|
||||
let help = `**Hilfe**\nMein Prefix ist .w, setze dies einfach vor jeden Befehl!\n\nadd <Word/Sentence> - Fügt ein Wort/Satz zum Filter hinzu\ndelete <Index> - Löscht ein Wort/Satz\nlist - Listet alle Wörter auf\nsetnotify - Setzt den Notify-Channel auf den aktuellen Kanal`;
|
||||
|
||||
await message.channel.send( help );
|
||||
}
|
||||
|
||||
|
||||
} );
|
||||
|
||||
client.on ( "guildCreate", ( guild ) =>
|
||||
{
|
||||
console.log ( `[INFO] Joined a new guild named "${ guild.name }" with ID ${ guild.id }` );
|
||||
createServerEntry ( guild.id, guild.name );
|
||||
createServerEntry(guild.id, guild.name).then();
|
||||
|
||||
} );
|
||||
|
||||
function createServerEntry( a_ServerID, a_ServerName )
|
||||
async function createServerEntry( a_ServerID, a_ServerName )
|
||||
{
|
||||
console.log ( `[INFO] Creating server entry...` );
|
||||
let query = "INSERT INTO guilds ( guild_id, server_name ) VALUES ( ?, ? )";
|
||||
con.query( query, [ a_ServerID, a_ServerName ], function( error, results, fields )
|
||||
{
|
||||
if( error )
|
||||
{
|
||||
|
||||
console.log ( `[ERROR] An error occurred while creating a new guild in database: ${error.message} ` );
|
||||
return false;
|
||||
}
|
||||
await con.promise().query( query, [a_ServerID, a_ServerName] );
|
||||
|
||||
|
||||
return true;
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
@ -271,12 +296,14 @@ function checkMessage( a_ServerID, a_Message )
|
||||
|
||||
async function refreshWords( a_ServerID )
|
||||
{
|
||||
let success = false;
|
||||
|
||||
console.log( "[INFO] Loading filter for guild " + a_ServerID )
|
||||
// Add the word to the database
|
||||
let query = "SELECT id, word FROM words WHERE guildID = ?";
|
||||
let results = await con.query( query );
|
||||
let [results] = await con.promise().query( query, [a_ServerID] );
|
||||
|
||||
|
||||
//results = results[0];
|
||||
badWords[a_ServerID] = {};
|
||||
for (let i = 0; i < results.length; i++ ) {
|
||||
badWords[a_ServerID][results[i].id] = results[i].word;
|
||||
@ -298,7 +325,7 @@ async function loadAllUp()
|
||||
let [results] = await con.promise().query( query );
|
||||
|
||||
for (let i = 0; i < results.length; i++) {
|
||||
refreshWords( results[i].guild_id );
|
||||
await refreshWords(results[i].guild_id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -306,15 +333,27 @@ async function loadAllUp()
|
||||
async function getNotifyChannel( a_ServerID )
|
||||
{
|
||||
let query = "SELECT id, notify_channel FROM guilds WHERE guilds.guild_id = ?";
|
||||
let results = await con.query( query, [ a_ServerID ] );
|
||||
let [results] = await con.promise().query( query, [ a_ServerID ] );
|
||||
|
||||
|
||||
|
||||
if( results.length < 1 )
|
||||
{
|
||||
createServerEntry( a_ServerID );
|
||||
return getNotifyChannel( a_ServerID );
|
||||
console.log( "newentry")
|
||||
await createServerEntry(a_ServerID);
|
||||
return await getNotifyChannel( a_ServerID );
|
||||
}
|
||||
return results.notify_channel;
|
||||
|
||||
return await results[0]['notify_channel'].toString();
|
||||
|
||||
}
|
||||
|
||||
async function setNotifyChannel( a_ServerID, a_ChannelID )
|
||||
{
|
||||
let query = "UPDATE guilds SET notify_channel = ? WHERE guild_id = ?";
|
||||
let [results] = await con.promise().query( query, [ a_ChannelID, a_ServerID ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// function broken i guess, the console.log is not getting out, so idk what happening
|
||||
@ -324,9 +363,9 @@ async function deleteWord( a_ServerID, a_Index )
|
||||
// Add the word to the database
|
||||
let success = false;
|
||||
let query = "DELETE FROM words WHERE id = ? AND guildID = ?";
|
||||
let results = await con.query( query, [a_Index, a_ServerID] );
|
||||
let [results] = await con.promise().query( query, [a_Index, a_ServerID] );
|
||||
|
||||
refreshWords( a_ServerID );
|
||||
await refreshWords(a_ServerID);
|
||||
return true;
|
||||
|
||||
}
|
||||
@ -336,9 +375,9 @@ async function addWord( a_ServerID, a_Word )
|
||||
let success = false;
|
||||
// Add the word to the database
|
||||
let query = "INSERT INTO words ( word, guildID ) VALUES ( ?, ? )";
|
||||
let results = await con.query( query, [ a_Word, a_ServerID ] );
|
||||
let [results] = await con.promise().query( query, [ a_Word, a_ServerID ] );
|
||||
|
||||
refreshWords( a_ServerID );
|
||||
await refreshWords(a_ServerID);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user