News:

Support for jDownloads 3 has been ended
Since 17 August 2023 Joomla.org has discontinued support for Joomla 3.x. Therefore, we will no longer offer official support for our Joomla 3 jDownloads version 3.9.x from January 2024.
Please update your website to the latest Joomla version (Joomla 4 or Joomla 5) as soon as possible. Afterwards, please update jDownloads to the latest published version. The longer you delay, the more difficult the upgrade process for your website is likely to be.

Main Menu
Support-Forum

Extend with Discord Bot support

Started by marcow, 19.06.2022 10:47:59

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

marcow

I've managed to hack a small subroutine into the notification of downloads to send emails and a Discord Notification.

Just to give back to the project I'm sharing the tweaks/hacks I've made. Naturally, you may use this as inspiration to extend the options in jDownloads. (And frankly I hope you do.)

First, I've used this source as inspiration:

https://gist.github.com/Mo45/cb0813cb8a6ebcd6524f6a36d4f8862c

Secondly I've created a function around it:

function sendToDiscord($message, $username, $title, $keyvalues) {
...
}

And thirdly I've patched the function sendMailDownload from jdownloads.php in the helpers folder to include these lines:

        ...
        // Send the Mail
        $result = $mailer->Send();

      /* ASSEMBLE ARRAY TO SEND TO DISCORD BOT
      */
        include_once (JPATH_ROOT.DS.'myfolder'.DS.'discord.msg.send.php');
        $items = '';
        for ($i=0; $i<count($files); $i++) {
               $items .= $files[$i]->title.' '.$files[$i]->release.'. ';
        }      
      $arr = array(
         array('name'=>'user', 'value'=>$user_name),
         array('name'=>'name', 'value'=>$user_fullname),
         array('name'=>'email', 'value'=>$user_email),
         array('name'=>'groups', 'value'=>$user_group),
         array('name'=>'files', 'value'=>$items)
         );
        sendToDiscord('Hi, this is a message from the Bot.', 'jDownloads', 'Download:', $arr);
  •