Advertisement
Combreal

New-DiscordMessage.ps1

Apr 6th, 2024
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.     .SYNOPSIS
  3.     Automaticaly posts a message every 2h in a discord channel.
  4.  
  5.     .DESCRIPTION
  6.     Discord saves the Run setting every time it stops, so maximize it before executing this.
  7.     Set your discord executable path bellow.
  8.     The current setup clicks on the first discord server and then click on the channel located at 157;1083 on a 2K monitor.
  9.     Use this to get your cursor position if you need to tweak the positions :
  10.     [System.Windows.Forms.Cursor]::Position
  11. #>
  12.  
  13. $cSource = @'
  14. using System;
  15. using System.Drawing;
  16. using System.Runtime.InteropServices;
  17. using System.Windows.Forms;
  18.  
  19. public class Clicker
  20. {
  21. [StructLayout(LayoutKind.Sequential)]
  22. struct INPUT
  23. {
  24.    public int        type; // 0 = INPUT_MOUSE,
  25.                            // 1 = INPUT_KEYBOARD
  26.                            // 2 = INPUT_HARDWARE
  27.    public MOUSEINPUT mi;
  28. }
  29.  
  30. [StructLayout(LayoutKind.Sequential)]
  31. struct MOUSEINPUT
  32. {
  33.    public int    dx ;
  34.    public int    dy ;
  35.    public int    mouseData ;
  36.    public int    dwFlags;
  37.    public int    time;
  38.    public IntPtr dwExtraInfo;
  39. }
  40.  
  41. const int MOUSEEVENTF_MOVED      = 0x0001 ;
  42. const int MOUSEEVENTF_LEFTDOWN   = 0x0002 ;
  43. const int MOUSEEVENTF_LEFTUP     = 0x0004 ;
  44. const int MOUSEEVENTF_RIGHTDOWN  = 0x0008 ;
  45. const int MOUSEEVENTF_RIGHTUP    = 0x0010 ;
  46. const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
  47. const int MOUSEEVENTF_MIDDLEUP   = 0x0040 ;
  48. const int MOUSEEVENTF_WHEEL      = 0x0080 ;
  49. const int MOUSEEVENTF_XDOWN      = 0x0100 ;
  50. const int MOUSEEVENTF_XUP        = 0x0200 ;
  51. const int MOUSEEVENTF_ABSOLUTE   = 0x8000 ;
  52.  
  53. const int screen_length = 0x10000 ;
  54.  
  55. [System.Runtime.InteropServices.DllImport("user32.dll")]
  56. extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
  57.  
  58. public static void LeftClickAtPoint(int x, int y)
  59. {
  60.    //Move the mouse
  61.    INPUT[] input = new INPUT[3];
  62.    input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
  63.    input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
  64.    input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
  65.    //Left mouse button down
  66.    input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
  67.    //Left mouse button up
  68.    input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
  69.    SendInput(3, input, Marshal.SizeOf(input[0]));
  70. }
  71.  
  72. public static void RightClickAtPoint(int x, int y)
  73. {
  74.    //Move the mouse
  75.    INPUT[] input = new INPUT[3];
  76.    input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
  77.    input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
  78.    input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
  79.    //Left mouse button down
  80.    input[1].mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
  81.    //Left mouse button up
  82.    input[2].mi.dwFlags = MOUSEEVENTF_RIGHTUP;
  83.    SendInput(3, input, Marshal.SizeOf(input[0]));
  84. }
  85.  
  86. }
  87. '@
  88.  
  89. Add-Type -TypeDefinition $cSource -ReferencedAssemblies System.Windows.Forms,System.Drawing
  90.  
  91. $taskName = Split-Path -Path $MyInvocation.MyCommand.Definition -Leaf
  92. $taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName }
  93.  
  94. If(-Not $taskExists) {
  95.     $trigger = New-ScheduledTaskTrigger -Daily -At 01:00
  96.     $triggerBis = New-ScheduledTaskTrigger -Once -At 01:00 -RepetitionInterval (New-TimeSpan -Minutes 120) -RepetitionDuration (New-TimeSpan -Hours 22 -Minutes 55)
  97.     $trigger.Repetition = $triggerBis.Repetition
  98.     $action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument $($MyInvocation.MyCommand.Definition)
  99.     $task = Register-ScheduledTask -TaskName $taskName -Trigger $trigger -Action $action -RunLevel "Highest" –Force
  100. }
  101.  
  102. $wshell = New-Object -ComObject wscript.shell
  103. [bool]$stayInLoop = $true
  104.  
  105. $discordProcess = Start-Process -PassThru -FilePath "C:\Users\myuser\AppData\Local\Discord\Update.exe" -ArgumentList "--processStart Discord.exe" -WindowStyle Maximized
  106. Start-Sleep -Seconds 5.5
  107.  
  108. While($stayInLoop) {
  109.     $discordProcess = Get-Process -Name "discord" 2>$null
  110.     Foreach ($discordChild in $discordProcess) {
  111.         If ($wshell.AppActivate($discordChild.Id)) {
  112.             $stayInLoop = $false
  113.             Continue
  114.         }
  115.     }
  116.     Start-Sleep -MilliSeconds 200
  117. }
  118.  
  119. [Clicker]::LeftClickAtPoint(30,110)
  120. Start-Sleep -Seconds 1
  121. [Clicker]::LeftClickAtPoint(157,1083)
  122. Start-Sleep -Seconds 1
  123. [System.Windows.Forms.SendKeys]::SendWait("`"Java or Bedrock`": **`"Java`"**,")
  124. Start-Sleep -Seconds 0.4
  125. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  126. Start-Sleep -Seconds 0.4
  127. [System.Windows.Forms.SendKeys]::SendWait("`"Realm/Server/World`": **`"Server`"**,")
  128. Start-Sleep -Seconds 0.4
  129. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  130. Start-Sleep -Seconds 0.4
  131. [System.Windows.Forms.SendKeys]::SendWait("`"Maximum number of players`": **9**,")
  132. Start-Sleep -Seconds 0.4
  133. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  134. Start-Sleep -Seconds 0.4
  135. [System.Windows.Forms.SendKeys]::SendWait("`"Session Time in hours`": **2**,")
  136. Start-Sleep -Seconds 0.4
  137. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  138. Start-Sleep -Seconds 0.4
  139. [System.Windows.Forms.SendKeys]::SendWait("`"Gametypes`": [")
  140. Start-Sleep -Seconds 0.4
  141. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  142. Start-Sleep -Seconds 0.4
  143. [System.Windows.Forms.SendKeys]::SendWait("    **`"Hermitcraft`"**,")
  144. Start-Sleep -Seconds 0.4
  145. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  146. Start-Sleep -Seconds 0.4
  147. [System.Windows.Forms.SendKeys]::SendWait("    **`"Hard`"**,")
  148. Start-Sleep -Seconds 0.4
  149. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  150. Start-Sleep -Seconds 0.2
  151. [System.Windows.Forms.SendKeys]::SendWait("    **`"Vanilla`"**]")
  152. Start-Sleep -Seconds 0.4
  153. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  154. Start-Sleep -Seconds 0.4
  155. [System.Windows.Forms.SendKeys]::SendWait("`"Language`": **`"English`"**,")
  156. Start-Sleep -Seconds 0.4
  157. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  158. Start-Sleep -Seconds 0.2
  159. [System.Windows.Forms.SendKeys]::SendWait("`"Time Zone`": **`"Europe`"**,")
  160. Start-Sleep -Seconds 0.4
  161. [System.Windows.Forms.SendKeys]::SendWait("+{ENTER}")
  162. Start-Sleep -Seconds 0.4
  163. [System.Windows.Forms.SendKeys]::SendWait("`"Community`": **`"Adult`"**")
  164. Start-Sleep -Seconds 0.5
  165. [System.Windows.Forms.SendKeys]::SendWait('~')
  166.  
  167. Start-Sleep -Seconds 1
  168. Stop-Process -Name "Discord"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement