Integrate free Adrenaline with discord v2

Second version of script which integrates Adrenaline with discord and allows user to push messages directly to discord. In this version we can show embedded messages!

Script:

SendEmbedWebhook(Embed);

Can be used as:

uses
 SysUtils,Discord;
 var
  Embed: TEmbedRecord;

begin
  Embed.Title := 'Title';
  Embed.Description := 'Description';
  Embed.Color := '5814783';
  Embed.Footer := 'Footer';
  Embed.Fields := [
  'Field Title 1', 'Field value 1',
  'Field Title 2', 'Field value 2',
  'Field Title 3', 'Field value 3',
  'Field Title 4', 'Field value 4',
  'Field Title 5', 'Field value 5',
  'Field Title 6', 'Field value 6'
  ];
  Embed.Username := 'L2Romans';
  Embed.AvatarUrl := 'https://i.imgur.com/AfFp7pu.png';
  
  SendEmbedWebhook(Embed);
end.

A picture is worth a thousand words

Filename: DiscordEmbeds.pas

unit Discord;
interface

uses SysUtils, Classes;
type
  TEmbedRecord = record
    Title: WideString;
    Description: WideString;
	Fields: array of WideString;
    Color: WideString;
    Footer: WideString;
    Username: WideString;
    AvatarUrl: WideString;
  end;
procedure SendWebhook(Msg:WideString);
procedure SendEmbedWebhook(const Embed: TEmbedRecord);
implementation

const WebhookURL = 'HERE_YOUR_DISCORD_WEBHOOK_URL';

procedure SendWebhook(Msg:WideString);
var
  PSCommand: WideString;
begin
  PSCommand :=
    'powershell -Command "$webhookUrl = ''' + WebhookURL + '''; ' +
    '$message = ''' + Msg + '''; ' +
    '$payload = @{ content = $message } | ConvertTo-Json -Depth 3; ' +
    'Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType ''application/json'' -Body $payload"';
	
  ShellExecuteW(0, PChar('open'), PChar('cmd.exe'),
    PChar('/C ' + PSCommand), nil, 0);
end;

procedure SendEmbedWebhook(const Embed: TEmbedRecord);
var
  PSCommand: WideString;
  FieldsString: string;
  I: Integer;
begin
  FieldsString := '';
	for I := 0 to High(Embed.Fields) - 1 do
	begin
	  if I mod 2 = 0 then
	  begin
		FieldsString := FieldsString +
		  '@{name=''' + '**' + Embed.Fields[I] + '**'';value=''' + Embed.Fields[I + 1] + ''';inline=$true},';
	  end;
	end;

  if FieldsString <> '' then
    Delete(FieldsString, Length(FieldsString), 1);

  PSCommand :=
    'powershell -Command "' +
    '$webhookUrl = ''' + WebhookURL + '''; ' +
    '$embed = @{title=''' + Embed.Title +
    ''';description=''' + Embed.Description +
    ''';color=' + Embed.Color +
    ';fields=@(' + FieldsString +
    ');footer=@{text=''' + Embed.Footer + '''}}; ' +
    '$payload = @{username=''' + Embed.Username +
    ''';avatar_url=''' + Embed.AvatarUrl +
    ''';embeds=@($embed)} | ConvertTo-Json -Depth 4; ' +
    'Invoke-RestMethod -Uri $webhookUrl -Method Post -ContentType ''application/json'' -Body $payload"';

  ShellExecuteW(0, 'open', 'cmd.exe', PChar('/C ' + PSCommand), nil, 0);
end;

function ShellExecuteW(hwnd: cardinal;
    lpOperation, lpFile, lpParameters, lpDirectory: pwidechar;
    nShowCmd: integer): cardinal;
    stdcall; external 'shell32.dll' Name 'ShellExecuteW';
end.