Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Topic started by: vbgamer45 on October 21, 2018, 12:26:05 PM

Title: Discord Web Hooks
Post by: vbgamer45 on October 21, 2018, 12:26:05 PM
Link to Mod (https://custom.simplemachines.org/mods/index.php?mod=4190)

Adds support for posting of new topics and messages to discord.
Also supports posting when a new user registers.

You can customize the messages posted for these actions, along with the name of the bot that posts the message.
Video demo: https://softwaredemos.tinytake.com/sf/MjkxMDYwMV84NzMyNzM0

Uses either cURL or fsockopen to make the post.

Changelog


2.0.1
+Pretty Urls support on messages posted to discord

2.0
+Added options to set custom discord post urls on a board level

1.0.2
!Fixed message link in postings to include anchor links.
!Fixed case of username guest language string not being loaded.
Title: Re: Discord Web Hooks
Post by: Rock Lee on October 21, 2018, 08:04:48 PM
Oh it seems interesting I'm going to try it, great job @vbgamer45!


Regards!
Title: Re: Discord Web Hooks
Post by: moyack on October 23, 2018, 04:31:53 PM
Awesome mod!! could be added the option in the profile settings to add the discord username so it can be set in the in the automated messages?
Title: Re: Discord Web Hooks
Post by: vbgamer45 on October 24, 2018, 08:52:04 AM
So it would just appear in the message? As an option.
Title: Re: Discord Web Hooks
Post by: moyack on November 07, 2018, 12:36:51 PM
So it would just appear in the message? As an option.
Yes, something like that :D

BTW, could it be possible, when someone make a new topic, that the discord message shows the canonical url instead the recent one.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on November 07, 2018, 01:16:52 PM
Possible like the main url to the topic?
Title: Re: Discord Web Hooks
Post by: moyack on November 10, 2018, 01:30:34 PM
Possible like the main url to the topic?
That's right. This could help to show better the topic link in the discord chat. In my forum it will show the page with description and image preview now that I use Open Graph tags.
Title: Re: Discord Web Hooks
Post by: efk on November 11, 2018, 01:21:35 PM
Awesome mod!! could be added the option in the profile settings to add the discord username so it can be set in the in the automated messages?
Sounds like a really nice mod, will try it in next days.
Title: Re: Discord Web Hooks
Post by: moyack on November 23, 2018, 08:53:11 PM
I just noticed a bug but I think it's not totally caused by the mod. When I post a message it shows in discord the link in the wrong way:
right link: http://wc3modding.info/5531/2-pirate-coasts/msg41393/#msg41393 or it should be:
link shown in discord: http://wc3modding.info/index.php?topic=5531.msg=41393

I think it's caused by the usage of SEF in my site. I use portamx SEF to make links more friendly. Any idea about how to fix it?

Thanks in advance
Title: Re: Discord Web Hooks
Post by: vbgamer45 on November 23, 2018, 09:12:09 PM
The code in sources/discord2.php needs to be updated to support portamx SEF I would ask them if they have  a function to turn into an seo link.
Title: Re: Discord Web Hooks
Post by: moyack on December 09, 2018, 08:13:32 PM
I did some modifications to handle canonical url and show properly special characters in the discord channel.

find:
Code: [Select]
$message = str_replace("(username)",$username,$message);
$message = str_replace("(title)",$row['subject'],$message);
$message = str_replace("(board)",$row['name'],$message);
$message = str_replace("(url)",$scripturl . '?topic=' . $row['id_topic'] . '.msg=' . $messageid,$message);

Replace with:
Code: [Select]
$message = str_replace("(username)",$username,$message);
$message = str_replace("(title)",$row['subject'],$message);
$message = str_replace("(board)",$row['name'],$message);
$message = str_replace("(can_url)",$scripturl . '?topic=' . $row['id_topic'] . '.0',$message); // this one allows canonical url...
$message = str_replace("(url)",$scripturl . '?topic=' . $row['id_topic'] . '.msg=' . $messageid,$message);
$message = html_entity_decode($message, ENT_QUOTES | ENT_XML1, 'UTF-8');

The html_entity_decode function was needed because I put this text in the discord settings in your mod:

Quote
@(username) wrote a new post *(title)* - __(url)__ on *(board)* board. As Illidan says, this is a "Child's Play"
and it showed in discord in this way:

Quote
@moyack wrote a new post Re: A new TESH Syntax Highlighter for Warcraft 3 - http://wc3modding.info/index.php?topic=5436.msg=41399 on WC3 Editing Tools board. As Illidan says, this is a "Child's Play"
Title: Re: Discord Web Hooks
Post by: vbgamer45 on December 09, 2018, 08:46:54 PM
Nice good tip!
Title: Re: Discord Web Hooks
Post by: vbgamer45 on December 09, 2018, 09:34:13 PM
Update
1.0.1
!Fixed entity issue with discord message posts thanks to moyack
+Added (can_url) variable to handle canonical url thanks to moyack
Title: Re: Discord Web Hooks
Post by: moyack on December 10, 2018, 01:53:08 PM
Update
1.0.1
!Fixed entity issue with discord message posts thanks to moyack
+Added (can_url) variable to handle canonical url thanks to moyack

Glad to help :)

If I manage to add the integration with PortaMX, I'll share this modification. This could lead into other integrations with other SEF...
Title: Re: Discord Web Hooks
Post by: Arantor on December 10, 2018, 02:15:06 PM
Um, that isn’t the right url format, it isn’t topic=123.msg=456 in stock SMF.

As for SEF, most of them work off hacking the sess_rewrite buffer.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on February 24, 2019, 10:37:42 AM
1.0.1a
+Added support for SMF 2.1.x
Title: Re: Discord Web Hooks
Post by: SugarD-x on May 31, 2019, 02:17:22 AM
1.0.1a
+Added support for SMF 2.1.x
Just a heads up, in SMF 2.1 RC2, it is still reporting the version number as being 1.0.1 and not 1.0.1a.
Title: Re: Discord Web Hooks
Post by: shaggyze on June 11, 2019, 03:55:15 PM
For some reason or another it seems as though Discord Web Hooks has installed twice to my smf board but only one appears in installed packages because when a new post is made it gets sent to discord twice so i was wondering what file i would have to edit to remove the double send.

uotiara.com/img/2019-06-11_12-42-41.png

also the link that gets sent to discord is the wrong link for my smf version i guess so i also need to know the file to edit that as well.

mabimods.net/index.php?topic=10456.msg=252115

should be

mabimods.net/index.php?topic=10456.msg252115#msg252115
Title: Re: Discord Web Hooks
Post by: vbgamer45 on June 11, 2019, 04:06:38 PM
Upload package to https://www.smfhacks.com/smf-package-parser.html
And check the file edits are applied only once.


For the second you would need to edit sources/discord2.php
Title: Re: Discord Web Hooks
Post by: shaggyze on June 11, 2019, 05:26:13 PM
getting an error saying package-info.xml not found! when uploading
puu.sh/DEJlX/d1f571659d.zip
though it does contain package-info.xml and i did use the right smf version when uploading it, however i did open the zip as soon as it downloaded to desktop an extracted your original .zip into a folder due to just plain lazyness an created a new .zip on desktop from that folder in which i installed... so that may have been the reason/problem to begin with, which as i said i think i may have installed it twice somehow...
(might have deleted it without uninstalling it)

each time i try uninstalling and reinstalling it still posts to discord twice so i'm not sure what i can do to fix the mistake already made.

using your original zip on smfhacks.com/smf-package-parser.html worked without an error so i'll try uninstalling and reinstalling the correct package here in a minute

Edit:
using your original package still results in double posts so need to find the file that was edited that probably now has two crucial edits causing it to be posted twice.
Title: Re: Discord Web Hooks
Post by: SugarD-x on July 18, 2019, 12:13:06 PM
getting an error saying package-info.xml not found! when uploading
puu.sh/DEJlX/d1f571659d.zip
though it does contain package-info.xml and i did use the right smf version when uploading it, however i did open the zip as soon as it downloaded to desktop an extracted your original .zip into a folder due to just plain lazyness an created a new .zip on desktop from that folder in which i installed... so that may have been the reason/problem to begin with, which as i said i think i may have installed it twice somehow...
(might have deleted it without uninstalling it)

each time i try uninstalling and reinstalling it still posts to discord twice so i'm not sure what i can do to fix the mistake already made.

using your original zip on smfhacks.com/smf-package-parser.html worked without an error so i'll try uninstalling and reinstalling the correct package here in a minute

Edit:
using your original package still results in double posts so need to find the file that was edited that probably now has two crucial edits causing it to be posted twice.
Uninstall the mod completely, and make sure no SMF integration hooks exist if on SMF 2.1. Also delete the package from your server's FTP completely, and do a search of your database to remove any references to the mod. Once your board is completely clean of it, download a new copy of the mod, upload it, and install it as is. If you are still getting double messages, either something is configured wrong, or you have a bug that no one else has seen or reported yet.
Title: Re: Discord Web Hooks
Post by: njtweb on July 18, 2019, 12:38:35 PM
What specifically does this do?
Title: Re: Discord Web Hooks
Post by: SychO on July 18, 2019, 12:40:47 PM
Posts forum notifications(new posts/topics and new registrations) to your Discord (https://www.google.com/search?q=discord) server.
Title: Re: Discord Web Hooks
Post by: njtweb on July 18, 2019, 12:47:19 PM
Ok, thank you.
Title: Re: Discord Web Hooks
Post by: Kolya on August 19, 2019, 06:59:13 PM
This works great. I got a non-fatal error with a guest creating a new topic though:
Undefined index: discord_guest
File: /Sources/discord2.php
Line: 218
Title: Re: Discord Web Hooks
Post by: Kolya on August 19, 2019, 07:05:07 PM
Another small problem is that links to posts don't work. They only lead to the topic.

A link as generated by the mod: /index.php?topic=10839.msg=129442
Actual working link to that post: /index.php?topic=10839.msg129442#msg129442
Title: Re: Discord Web Hooks
Post by: vbgamer45 on August 19, 2019, 10:44:07 PM
1.0.2
!Fixed message link in postings to include anchor links.
!Fixed case of username guest language string not being loaded.
Title: Re: Discord Web Hooks
Post by: Kolya on August 20, 2019, 03:46:39 PM
Well that was a quick response! Thank you for the fixes. :)
Title: Re: Discord Web Hooks
Post by: vbgamer45 on August 20, 2019, 03:48:32 PM
Glad to help.
Title: Re: Discord Web Hooks
Post by: adapa on October 13, 2019, 10:37:08 PM
Posts forum notifications(new posts/topics and new registrations) to your Discord (https://www.google.com/search?q=discord) server.

any thoughts to going the reverse way?
I'd love to have discord posts appear in my forum.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on October 13, 2019, 11:13:32 PM
Might be possible with the api https://discordapp.com/developers/docs/resources/channel#get-channel-messages
Not sure how you control it though since discord is more of chat system. So can hit your forum with tons of posts...
Title: Re: Discord Web Hooks
Post by: Jelle Mees on February 07, 2020, 03:17:26 PM
It doesn't seem to tag the groupmembers on Discord.
For example, we have a group called "Member".
And I let the mod post this message:
@Member
But it posts it as regular text without actually pinging the users in the group "Member".
Title: Re: Discord Web Hooks
Post by: SugarD-x on February 07, 2020, 03:27:48 PM
It doesn't seem to tag the groupmembers on Discord.
For example, we have a group called "Member".
And I let the mod post this message:
@Member
But it posts it as regular text without actually pinging the users in the group "Member".
It might not be built to support those types of messages. I've seen Discord bots before that don't have that support built into their custom commands, and it causes the text to be sent without the mention too.
Title: Re: Discord Web Hooks
Post by: LG965 on June 01, 2020, 05:27:02 PM
Fantastic mod!
it would be even better if you could connect each board separately to a discord channel.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on June 01, 2020, 05:59:45 PM
Yeah little tricky.
Title: Re: Discord Web Hooks
Post by: kilk on June 09, 2020, 04:06:23 PM
Vbgamer is on a roll, so many badass mods! Thank you for all your hard work!
Title: Re: Discord Web Hooks
Post by: Sectomy on July 10, 2020, 10:06:08 AM
Hi,
just a question, does it always post if theres a new "post" (reply) or only new topic ?
would be cool if theres only a "new topic" switch , i dont wanna know all replies, just the topic...is that possible ?
best regards
andi
Title: Re: Discord Web Hooks
Post by: vbgamer45 on July 10, 2020, 11:08:48 AM
options for both

post on reply
post on new topic



you can customize them
Title: Re: Discord Web Hooks
Post by: Sectomy on July 12, 2020, 05:00:13 AM
Fantastic mod!
it would be even better if you could connect each board separately to a discord channel.
yeah, that would be awsome, or maybe is it possible to modificate the pakage, so you can install 2 of the mods (maybe change the name?) so you can choose this Board Topics belong to Channel 1 and Notifications of Board 2 belongs to channel 2.....
Title: Re: Discord Web Hooks
Post by: JUNK de LUXE on October 09, 2020, 06:38:03 AM
would it be possible to get a setting to toggle on/off link embedding?

When the bot pushes to my Discord channel the link is embedded and tells the user to "log in" instead of showing a preview of the topic.

A secondary solution would be if it showed an actual preview of the topic instead of telling the user to log in.



See image for clarification
Title: Re: Discord Web Hooks
Post by: vbgamer45 on October 09, 2020, 09:25:51 AM
Would have to see if there is a setting for that. It shows that text since that topic is off limits to the discord bot when it tries to view the page as text
Title: Re: Discord Web Hooks
Post by: JUNK de LUXE on October 09, 2020, 11:53:21 AM
I've looked it up and if the link is surrounded by <>-signs like this:

Code: [Select]
<www.link.tld>
then it should disable the embedding.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on October 09, 2020, 12:05:12 PM
Hmm ok that's a little tricky would have to pull out of links/convert html to that
Title: Re: Discord Web Hooks
Post by: JUNK de LUXE on October 09, 2020, 01:09:30 PM
do it if you want to, and if not I'll survive :)

we're only a small buddies discord and nothing fancy.


another solution might be if it's somehow possible for the bot to be a user of the forum so it can show the previews.. hmm.
Title: Re: Discord Web Hooks
Post by: SilverKnight on December 31, 2020, 02:25:50 AM
Thank you, this is pretty great
Title: Re: Discord Web Hooks
Post by: Anger22 on January 13, 2021, 03:43:30 AM
Love this mod. Would it be possible to add a feature to allow different boards to be connected to different webhooks? I have many restricted boards that only certain members should see. It would be cool if "admin boards" for example could be connected to a different webhook, so those comments only post to the "admin" discord channels.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 13, 2021, 08:38:22 AM
It would be possible just takes time to add.
Title: Re: Discord Web Hooks
Post by: SilverKnight on January 15, 2021, 11:45:37 PM
I second this option, to provide more purpose, if you could setup a table like structure where you could direct posts from smf -> a certain discord channel, it would greatly expand it's purpose. I'll buy you a coffee if you need an incentive? :)
Title: Re: Discord Web Hooks
Post by: Anger22 on January 17, 2021, 02:15:49 PM
I'd also be willing to throw a few bucks at it  8)
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 17, 2021, 02:26:46 PM
Ok well i might just work on it then. Settings per board level.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 17, 2021, 11:12:52 PM
Update:
2.0
+Added options to set custom discord post urls on a board level
Title: Re: Discord Web Hooks
Post by: Anger22 on January 18, 2021, 03:01:03 AM
Working flawlessly as far as I can tell. Thank you for your work! Where can I send a contribution?
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 18, 2021, 08:24:26 AM
Here is a link:
https://paypal.me/vbgamer45
Title: Re: Discord Web Hooks
Post by: SilverKnight on January 18, 2021, 10:46:14 PM
Here is a link:
https://paypal.me/vbgamer45

Fantastic and a fast update too, enjoy your Coffee(s)

Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 18, 2021, 10:48:00 PM
Thanks!
Title: Re: Discord Web Hooks
Post by: SilverKnight on January 18, 2021, 10:49:48 PM
Would like to see Botname per custom webhook too, would make it interesting to stylise individual discord channels.

Have you also considered doing a discord -> SMF forum mod e.g. when a message is done in discord, it's created in a thread or as a new thread? That would provide a true integration experience.
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 18, 2021, 11:12:31 PM
I have thought about discord to SMF, have to look at the API some more to see how it is possible.
Title: Re: Discord Web Hooks
Post by: SilverKnight on January 19, 2021, 09:22:47 PM
Tried to setup an individual hook in a child board and not seeing it trigger the webhook, is there something else we need to do to make it trigger?
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 19, 2021, 09:41:56 PM
You have to make sure the board is selected on the main page as well of the settings.
Title: Re: Discord Web Hooks
Post by: SilverKnight on January 21, 2021, 04:25:56 AM
You have to make sure the board is selected on the main page as well of the settings.

Seems to work if you do that, thanks.

Any chance of also getting prettyurl support for the outputs?
Title: Re: Discord Web Hooks
Post by: vbgamer45 on January 21, 2021, 09:57:17 AM
Update

2.0.1
+Pretty Urls support on messages posted to discord


Not tested but give that a try.