DTube IPFS Discord Bot v1.1: Whitelisting system, silent mode and more!

Header Image

Repository

https://github.com/techcoderx/DTube-IPFS-Bot

New features

SD-only mode

Maintaining IPFS nodes can be expensive. The cost may be renting the server that has sufficient storage for all the files, or the hardware cost if the files are self-hosted. Therefore, some server owners may want to disable HD video pinning so that users may only pin 240p and 480p videos to save disk space. Now you may do so easily by setting sdOnlyMode to true in config.json file. When the user tries to pin 720p, 1080p or source video files when sdOnlyMode is true, the user will be greeted with this message:

Screen Shot 20180909 at 5.29.06 PM.png

Whitelisting system

Instead of blocking the HD pinning commands for all users by setting sdOnlyMode to true, is there any way to only allow certain users to pin HD content to IPFS?

With the new whitelisting system, it's possible to add a Discord user to the whitelist by sending the !hdwhitelist add @user command. It will take the Discord User ID of the mentioned user from the guild, and add it to the whitelist in HDWhitelist.txt. To remove a user from the whitelist, just enter the !hdwhitelist rm @user command into the chat and the mentioned Discord user's ID will be taken off that whitelist file. These commands may only be executed by users with administrator privileges in the Discord server.

Admins can also type !hdwhitelist ls to view all users in the whitelist. Once the command is sent, the bot will send a DM back to the admin, listing all whitelisted users.

All users may check if they're in the whitelist by typing !hdwhitelist check command.

Screen Shot 20180909 at 5.43.26 PM.png

Note: Whitelist system and its commands will only work if hdwhitelistEnabled is set to true and sdOnlyMode is set to false in config.json file.

Silent mode is here!

Some people may wish to run the bot in multiple servers (preferably in a geographically different location) for redundancy and decentralization. The problem is that the users will see that the bot has sent the same message more than once. Now it's possible to silent the bot so that messages get logged to the console instead of sending the message to the chat.

Pong replies and download complete notifications however, will be sent to the chat regardless if silent mode is enabled or not. This is to provide visual feedback to the user that the servers are online and the video has been downloaded to multiple servers.

To enable silent mode, set silentModeEnabled to true in config.json file. You may also change the bot replies by changing the words in the BotOutputMessage section in the same file.

No more double pinning!

As some server providers impose certain amount of monthly bandwidth quota, it's crucial to ensure that it has been used sparingly. But, unnecessary bandwidth usage can be created by sending the pinning commands more than once, hence downloading the same file that has already been pinned repeatedly.

Now a check has been added to ensure that files which are already pinned to IPFS node do not get downloaded again. It will compare the IPFS hash of the file against the list of pinned hashes in AllPinned.txt to see if the hash exists in the text file. If the hash is in the file, the user will see this when they're trying to download a file more than once:

Screen Shot 20180909 at 6.06.56 PM.png

The AllPinned.txt file located in the Pinned folder in the repo does not update dynamically when the contents of the IPFS node changes. Therefore, it is needed to fetch the output of ipfs pin ls -t recursive to the text file. To handle this, a cron job can be created using the built-in utility in Linux and macOS called crontab to execute ipfs pin ls -t recursive > /path/to/repo/Pinned/AllPinned.txt regularly (preferably multiple times every minute).

In addition to that, ipfs pin ls -t recursive > Pinned/AllPinned.txt will run each time when PinFiles.sh and rmPins.sh is executed to update AllPinned.txt once files have been pinned/unpinned.

IPFS Bot User Database

Server admins would like to see what files do users pin to their node. Instead of scrolling through the chat to look for what files are pinned, I've made a database which stores the IPFS hashes that each user downloads to the server, by Discord User ID. Each time a file is downloaded through the bot, the IPFS hash will be recorded in a text file with the user ID being the file name of the text file. The text files are stored in Pinned folder together with the AllPinned.txt file.

If the server admin decides to unpin all files pinned by a user, they can do so by executing ./rmPins.sh <userID> in the same folder, specifying the user ID of the Discord user. After unpinning the files, just execute ipfs repo gc to properly delete all files that were unpinned.

Flexible command prefix

Some Discord servers invites multiple bots, so it's possible that the bot commands may conflict with another bot. Therefore' I've made it easy to change the command prefix by changing the value of commandPrefix to something other than the preconfigured ! in config.json file.

Notice that the above images showed that the bot command started with >? It was changed from ! so that the test server doesn't conflict with the main bot server.

Get link to GitHub repo for this bot with a simple command!

Users who are curious to see the development, or wants to inspect the source code for this bot may execute the !botsource command to get the link to the GitHub repository for this bot!


Additional features

These are the features that are already on the repo for more than 3 weeks but not mentioned in the first post.

  1. DSound links support - Now you're able to pin DSound audio files to IPFS with !ipfssound <link> command.
  2. Support for 720p and 1080p videos - Since DTube 0.8 came out, it's possible to post a video with a 1080p version of the source file (e.g. a 1440p source video encoded into 1080p). Users may pin their HD videos (if they're in the whitelist with whitelisting system enabled) using !ipfs720 <link> and/or ipfs1080 <link> commands.
  3. Added donation links - As I've mentioned above, hosting an IPFS node can be expensive, so server owners may wish to raise funds (in STEEM/SBD) from users. Now SteemConnect donation links can be generated by typing !ipfsdonate <currency> <amount>. Remember to set the community Steem account in the config.json file.

Invalid bot commands

I have received some feedback when I have posted the first post about the bot, regarding invalid commands such as a broken link. Here's what will happen if invalid commands are entered:

  1. Broken link in pinning command - Unexpected end of JSON input error message will be logged into the console. Bot will not crash.
  2. Community account not set (communityAccount in config.json file is ""): Sends a message telling user that community Steem account is not set.
  3. Video doesn't exist for specified resolution: Unexpected end of JSON input error message will be logged into the console. Bot will not crash.
  4. IPFS hash doesn't exist: Bot replies a 404 error.

Github account

https://github.com/techcoderx

H2
H3
H4
3 columns
2 columns
1 column
7 Comments
Ecency