Combreal icon

New-DiscordMessage.ps1

Combreal | PRO | 04/06/24 05:52:00 PM UTC | 0 ⭐ | 5347 👁️ | Never ⏰ | [discord, powershell]
PowerShell |

6.29 KB

|

None

|

0 👍

/

0 👎

<#
    .SYNOPSIS
    Automaticaly posts a message every 2h in a discord channel.
 
    .DESCRIPTION
    Discord saves the Run setting every time it stops, so maximize it before executing this.
    Set your discord executable path bellow.
    The current setup clicks on the first discord server and then click on the channel located at 157;1083 on a 2K monitor.
    Use this to get your cursor position if you need to tweak the positions : 
    [System.Windows.Forms.Cursor]::Position
#>
 
$cSource = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
public class Clicker
{
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{ 
    public int        type; // 0 = INPUT_MOUSE,
                            // 1 = INPUT_KEYBOARD
                            // 2 = INPUT_HARDWARE
    public MOUSEINPUT mi;
}
 
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
    public int    dx ;
    public int    dy ;
    public int    mouseData ;
    public int    dwFlags;
    public int    time;
    public IntPtr dwExtraInfo;
}
 
const int MOUSEEVENTF_MOVED      = 0x0001 ;
const int MOUSEEVENTF_LEFTDOWN   = 0x0002 ;
const int MOUSEEVENTF_LEFTUP     = 0x0004 ;
const int MOUSEEVENTF_RIGHTDOWN  = 0x0008 ;
const int MOUSEEVENTF_RIGHTUP    = 0x0010 ;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
const int MOUSEEVENTF_MIDDLEUP   = 0x0040 ;
const int MOUSEEVENTF_WHEEL      = 0x0080 ;
const int MOUSEEVENTF_XDOWN      = 0x0100 ;
const int MOUSEEVENTF_XUP        = 0x0200 ;
const int MOUSEEVENTF_ABSOLUTE   = 0x8000 ;
 
const int screen_length = 0x10000 ;
 
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
 
public static void LeftClickAtPoint(int x, int y)
{
    //Move the mouse
    INPUT[] input = new INPUT[3];
    input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
    input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
    input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
    //Left mouse button down
    input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    //Left mouse button up
    input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
    SendInput(3, input, Marshal.SizeOf(input[0]));
}
 
public static void RightClickAtPoint(int x, int y)
{
    //Move the mouse
    INPUT[] input = new INPUT[3];
    input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
    input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
    input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
    //Left mouse button down
    input[1].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
    //Left mouse button up
    input[2].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
    SendInput(3, input, Marshal.SizeOf(input[0]));
}
 
}
'@
 
Add-Type -TypeDefinition $cSource -ReferencedAssemblies System.Windows.Forms,System.Drawing
 
$taskName = Split-Path -Path $MyInvocation.MyCommand.Definition -Leaf
$taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName }
 
If(-Not $taskExists) {
    $trigger = New-ScheduledTaskTrigger -Daily -At 01:00 
    $triggerBis = New-ScheduledTaskTrigger -Once -At 01:00 -RepetitionInterval (New-TimeSpan -Minutes 120) -RepetitionDuration (New-TimeSpan -Hours 22 -Minutes 55)
    $trigger.Repetition = $triggerBis.Repetition
    $action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument $($MyInvocation.MyCommand.Definition)
    $task = Register-ScheduledTask -TaskName $taskName -Trigger $trigger -Action $action -RunLevel "Highest" –Force
}
 
$wshell = New-Object -ComObject wscript.shell
[bool]$stayInLoop = $true
 
$discordProcess = Start-Process -PassThru -FilePath "C:\Users\myuser\AppData\Local\Discord\Update.exe" -ArgumentList "--processStart Discord.exe" -WindowStyle Maximized
Start-Sleep -Seconds 5.5
 
While($stayInLoop) {
    $discordProcess = Get-Process -Name "discord" 2>$null
    Foreach ($discordChild in $discordProcess) {
        If ($wshell.AppActivate($discordChild.Id)) {
            $stayInLoop = $false
            Continue
        }
    }
    Start-Sleep -MilliSeconds 200
}
 
[Clicker]::LeftClickAtPoint(30,110)
Start-Sleep -Seconds 1
[Clicker]::LeftClickAtPoint(157,1083) 
Start-Sleep -Seconds 1
[System.Windows.Forms.SendKeys]::SendWait("`"Java or Bedrock`": **`"Java`"**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("`"Realm/Server/World`": **`"Server`"**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("`"Maximum number of players`": **9**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("`"Session Time in hours`": **2**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("`"Gametypes`": [")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("    **`"Hermitcraft`"**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("    **`"Hard`"**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.2
[System.Windows.Forms.SendKeys]::SendWait("    **`"Vanilla`"**]")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("`"Language`": **`"English`"**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.2
[System.Windows.Forms.SendKeys]::SendWait("`"Time Zone`": **`"Europe`"**,")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
Start-Sleep -Seconds 0.4
[System.Windows.Forms.SendKeys]::SendWait("`"Community`": **`"Adult`"**")
Start-Sleep -Seconds 0.5
[System.Windows.Forms.SendKeys]::SendWait('~')
 
Start-Sleep -Seconds 1
Stop-Process -Name "Discord"

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎