Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <shavit>
  3. #include <discord>
  4.  
  5. #define PLUGIN_VERSION "1.0"
  6.  
  7. #define WEBHOOK "https://discordapp.com/api/webhooks/376627548525953024/spv1-27XxQx92004NkZZR5JvizdCfnmy3xVt6Cb1Km5pcaCfleZ8DhllzXXUzpS4OJTR" // webhook url
  8. #define MAIN_MSG_COLOUR "#a3f441" // colour of embed
  9. #define BONUS_MSG_COLOUR "#00cbff"
  10. #define MIN_RECORDS 5 // minimum no. of records before discord bots posts wr
  11.  
  12. public Plugin myinfo =
  13. {
  14.     name = "[shavit] Discord WR Bot",
  15.     author = "SlidyBat",
  16.     description = "Makes discord bot post message when server WR is beaten",
  17.     version = PLUGIN_VERSION,
  18.     url = "steamcommunity.com/id/SlidyBat2"
  19. }
  20.  
  21. ConVar g_cvHostname;
  22. char g_cHostname[128];
  23. char g_cCurrentMap[PLATFORM_MAX_PATH];
  24.  
  25. public void OnPluginStart()
  26. {
  27.     g_cvHostname = FindConVar("hostname");
  28.     g_cvHostname.GetString( g_cHostname, sizeof( g_cHostname ) );
  29. }
  30.  
  31. public void OnMapStart()
  32. {
  33.     GetCurrentMap( g_cCurrentMap, sizeof( g_cCurrentMap ) );
  34. }
  35.  
  36. public void Shavit_OnWorldRecord( int client, int style, float time, int jumps, int strafes, float sync, int track, float oldwr )
  37. {
  38.     if( MIN_RECORDS > 0 && Shavit_GetRecordAmount( style, track ) < MIN_RECORDS ) // dont print if its a new record to avoid spam
  39.     {
  40.         return;
  41.     }
  42.  
  43.     DiscordWebHook hook = new DiscordWebHook( WEBHOOK );
  44.     hook.SlackMode = true;
  45.     hook.SetUsername( "AusBHOP WR Bot" );
  46.  
  47.     MessageEmbed embed = new MessageEmbed();
  48.  
  49.     embed.SetColor( ( track == Track_Main ) ? MAIN_MSG_COLOUR : BONUS_MSG_COLOUR );
  50.  
  51.     char styleName[128];
  52.     Shavit_GetStyleStrings( style, sStyleName, styleName, sizeof( styleName ));
  53.  
  54.     char buffer[512];
  55.     Format( buffer, sizeof( buffer ), "__**New %s World Record**__ | **%s** - **%s**", ( track == Track_Main ) ? "" : "Bonus", g_cCurrentMap, styleName );
  56.     embed.SetTitle( buffer );
  57.  
  58.     char steamid[65];
  59.     GetClientAuthId( client, AuthId_SteamID64, steamid, sizeof( steamid ) );
  60.     Format( buffer, sizeof( buffer ), "[%N](http://www.steamcommunity.com/profiles/%s)", client, steamid );
  61.     embed.AddField( "Player", buffer, true  );
  62.  
  63.     float split = time - oldwr;
  64.     char sSplit[32];
  65.     FormatSeconds( split, sSplit, sizeof( split ) );
  66.     FormatSeconds( time, buffer, sizeof( buffer ) );
  67.     Format( buffer, sizeof( buffer ), "%ss (%s)", buffer, sSplit );
  68.     embed.AddField( "Time", buffer, true );
  69.  
  70.     Format( buffer, sizeof( buffer ), "**Strafes**: %i\t\t\t\t\t\t**Sync**: %.2f%%\t\t\t\t\t\t**Jumps**: %i", strafes, sync, jumps );
  71.     embed.AddField( "Stats", buffer, true );
  72.  
  73.     embed.SetThumb( "http://www.guinnessworldrecords.com/images/logo.png" );
  74.  
  75.     Format( buffer, sizeof( buffer ), "Server: %s", g_cHostname );
  76.     embed.SetFooter( buffer );
  77.     embed.SetFooterIcon( "https://d30y9cdsu7xlg0.cloudfront.net/png/198559-200.png" );
  78.  
  79.  
  80.     hook.Embed( embed );
  81.     hook.Send();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement