Raised This Month: $ Target: $400
 0% 

[SNIPPET] SteamWorks to Slack (webhook)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 12-29-2016 , 15:35   [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #1

Requires SteamWorks

May be useful to some.

PHP Code:
public void SendToSlack(const char[] cMessage)
{
    
char[] sFormat = new char[2048];
    
Format(sFormat2048"{\"channel\": \"#sourcemod\", \"username\": \"%s\", \"text\": \"%s\", \"icon_emoji\": \":speech_balloon:\"}""CSGO Server"cMessage);

    
Handle hHTTP_request SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST"https://hooks.slack.com/services/...");
    
SteamWorks_SetHTTPRequestRawPostBody(hHTTP_request"application/json"sFormatstrlen(sFormat));
    if (
hHTTP_request == null || !SteamWorks_SetHTTPCallbacks(hHTTP_requestSlack_Callback) || !SteamWorks_SendHTTPRequest(hHTTP_request))
    {
        
PrintToServer("[SendToSlack] SendToSlack failed to fire");
        
delete hHTTP_request;
    }
}

public 
Slack_Callback(Handle hRequestbool bFailurebool bRequestSuccessfulEHTTPStatusCode eStatusCode
{
    
char cActionName[64];
    
cActionName "Slack_Callback";
    if (!
bFailure && bRequestSuccessful)
    {
        switch (
eStatusCode)
        {
            case 
200:
            {
                
//all gud
            
}
            default:
            {
                
PrintToServer("[%s] failed with code [%i]"cActionNameeStatusCode);
                
SteamWorks_GetHTTPResponseBodyCallback(hRequestPrint_Response);
            }
        }
    }
    
delete hRequest;
}
public 
Print_Response(const char[] sData)
{
    
PrintToServer("[Print_Response] %s"sData);

__________________

Last edited by ImACow; 12-29-2016 at 15:40.
ImACow is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 12-29-2016 , 19:07   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #2

What's Slack?
__________________
Neuro Toxin is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 12-29-2016 , 19:54   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #3

Quote:
Originally Posted by Neuro Toxin View Post
What's Slack?
https://slack.com/
__________________
Pelipoika is offline
hadesownage
AlliedModders Donor
Join Date: Jun 2013
Location: Romania, Iași
Old 12-30-2016 , 11:15   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #4

People is using Discord, not Slack.
If you can convert this to work on Discord will be great!
hadesownage is offline
Send a message via Yahoo to hadesownage Send a message via Skype™ to hadesownage
Mitchell
~lick~
Join Date: Mar 2010
Old 12-30-2016 , 12:42   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #5

Quote:
Originally Posted by hadesownage View Post
People is using Discord, not Slack.
If you can convert this to work on Discord will be great!
Gamers use Discord,
Developers use Slack,
Old people (psychonic) use IRC.
Mitchell is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 12-30-2016 , 13:11   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
Gamers use Discord,
Developers use Slack,
Old people (psychonic) use IRC.
__________________

Last edited by Pelipoika; 12-30-2016 at 13:12.
Pelipoika is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 01-02-2017 , 10:48   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #7

Quote:
Originally Posted by hadesownage View Post
People is using Discord, not Slack.
If you can convert this to work on Discord will be great!

Last edited by 404UserNotFound; 01-02-2017 at 10:54.
404UserNotFound is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-02-2017 , 14:01   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #8

Quote:
Originally Posted by abrandnewday View Post
~snip~
It would make more sense, since most admins would be in discord, not slack.
With discord you need to setup a bot account etc with the discord site.
Mitchell is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 01-02-2017 , 21:15   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #9

Quote:
Originally Posted by hadesownage View Post
People is using Discord, not Slack.
If you can convert this to work on Discord will be great!
Untested but should work for Discord. Create webhook from server settings -> webhooks
PHP Code:
public void SendToDiscord(const char[] message) {
    
Handle request SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST"Enter webhooks url here");
    
    
SteamWorks_SetHTTPRequestGetOrPostParameter(request"content"message);
    
SteamWorks_SetHTTPRequestHeaderValue(request"Content-Type""application/x-www-form-urlencoded");
    
    if(
request == null || !SteamWorks_SetHTTPCallbacks(requestDiscord_Callback) || !SteamWorks_SendHTTPRequest(request)) {
        
PrintToServer("[SendToSlack] SendToDiscord failed to fire");
        
delete request;
    }
}

public 
Discord_Callback(Handle hRequestbool bFailurebool bRequestSuccessfulEHTTPStatusCode eStatusCode) {
    if(!
bFailure && bRequestSuccessful) {
        switch (
eStatusCode) {
            case 
200:{
                
//all gud
            
}
            default: {
                
PrintToServer("[Send To Discord] failed with code [%i]"eStatusCode);
                
SteamWorks_GetHTTPResponseBodyCallback(hRequestPrint_Response);
            }
        }
    }
    
delete hRequest;
}

public 
Print_Response(const char[] sData) {
    
PrintToServer("[Print_Response] %s"sData);

__________________
Deathknife is offline
Phire
Junior Member
Join Date: May 2016
Location: Scotland, United Kingdom
Old 01-02-2017 , 23:19   Re: [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #10

Quote:
Originally Posted by Deathknife View Post
Untested but should work for Discord. Create webhook from server settings -> webhooks
Spoiler
I've tested it and I can confirm that it works. If anyone wants a quick script to send custom messages then this is what you can use
Spoiler
__________________
root@phire:~# sudo apt-get install life
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package life

Last edited by Phire; 01-02-2017 at 23:26.
Phire is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode