My Hive Posts

    Removing Duplicate and Too Frequent Steemit and Busy link from Discord

    We often see in the Post Promotion channel of the Discord that people posts his or her same post more than once or more than one in 24 hours. So we need a script which will intelligent enough to delete those posts if its finds duplicate or more than one posts by a user in 24 hours. This will keep the post promotion clean and everyone will get the equal opportunity to promote their posts.

    Technology Stack

    The application is written in Node.js and we save the data in Sqlite database. Along with that we will use Discordie npm package to talk to Discord API. Along with this we also use Cluster Npm Package to make the BOT running 24 hours even if it crashes anytime.

    Code

    We are using Sqlite Database using the NPM package sqlite3. So before starting we need to create the table, whenever you run the script it will see if the posts.db has been created or not, if not it will create one for you with the Columns required in the script as shown below :

    let db = new sqlite3.Database('posts.db');
    db.serialize(function() {
      db.run("CREATE TABLE if not exists posts_info
                             (discordName TEXT, post TEXT, time TEXT, channel_id TEXT)");
    });
    

    Next we Connect to the Discord using Discordie and whenever we see any incoming messages we will send the event to the Check Posts Function.

    client.connect({
      token: 'Bot Token'
    });
    client.Dispatcher.on(Events.GATEWAY_READY, e => {
      console.log('Connected as: ' + client.User.username);
    });
    client.Dispatcher.on(Events.MESSAGE_CREATE, e => {
     if (e.message.author.bot) {
       return;
    }
    checkPosts(e);
     });
    

    In the Check Posts function we check if the link is valid i.e. if its from Steemit or Busy, if it is valid we check in the database if the user has added the Posts before by checking the discordName and channel_id. Once we get the posts we check the posts URL and the Time Difference between the earlier post and current post. If everything is correct you can post otherwise the bot will delete the post with a warning.

    Commits

    https://github.com/codingdefined/DiscordSpamRemoval/commit/da4821165749b309b65e8c9b70df1fce146ad331 https://github.com/codingdefined/DiscordSpamRemoval/commit/6b124748fcf6ff7cb4c5ebc9781349b58de5db57 https://github.com/codingdefined/DiscordSpamRemoval/commit/c36b504c6280d9ac7220b8f5b367cc2dd3fc7968

    Bot in Action

    image.png

    Roadmap

    As of now the Bot will save the Channel ID where the posts have been written along with Discord Name, now if you use more than one discord account you can still spam using the different account. We need to store the Steemit Username, Discord Name, Channel Id, Guild Id and Posts URL to reduce the spamming as much as possible. Create Test Cases and error handling.

    How to contribute?

    The code is freely available in Github which you can fork and create a pull request. If you need any feature to be added, you can also talk to me on the Discord (Id - codingdefined).



    Posted on Utopian.io - Rewarding Open Source Contributors