Created
January 25, 2026 22:53
-
-
Save douxxtech/12fe7f58b71f66923cc4109366c52d28 to your computer and use it in GitHub Desktop.
Script for this blog post: https://douxx.blog/?p=7-harassing-my-friend-with-an-esp32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using nanoFramework.Networking; | |
| using System; | |
| using System.Diagnostics; | |
| using System.IO; | |
| using System.Net; | |
| using System.Net.Http.Headers; | |
| using System.Text; | |
| using System.Threading; | |
| namespace AntHarass | |
| { | |
| public class Program | |
| { | |
| private const bool DISCORD_IS_APP = false; // set to true if you're using an official discord app. to false if you're using a user token (warning, that can be bannable !) | |
| private const string DISCORD_TOKEN = ""; // the app / user token | |
| private const string DISCORD_CHANNEL_ID = ""; // the channel id to send the message in | |
| private const string DISCORD_MESSAGE = "Fais le css stp"; // the actual message to send | |
| private const int TARGET_RATE = 60000; // in ms/message. 60000 is one minute | |
| private const string WIFI_SSID = ""; // wifi ssid | |
| private const string WIFI_PSK = ""; // wifi passkey | |
| private const bool DEBUG_TIMER = true; | |
| public static void Main() | |
| { | |
| Debug.WriteLine("Hello from AntHarass!"); | |
| Debug.WriteLine("Read the blog post about this software: https://douxx.blog/?p=7-harassing-my-friend-with-an-esp32"); | |
| Debug.WriteLine("The actual program will start now."); | |
| Debug.WriteLine("=================================="); | |
| Debug.WriteLine("Attempting to connect to WiFi"); | |
| int message_count = 0; | |
| long start = 0; | |
| if (DEBUG_TIMER) | |
| { | |
| start = DateTime.UtcNow.Ticks; | |
| } | |
| WifiNetworkHelper.ConnectDhcp(WIFI_SSID, WIFI_PSK); | |
| if (WifiNetworkHelper.Status != NetworkHelperStatus.NetworkIsReady) | |
| { | |
| Debug.WriteLine($"Failed to connect to WiFi. Status: {WifiNetworkHelper.Status}"); | |
| Thread.Sleep(Timeout.Infinite); | |
| } | |
| Debug.WriteLine($"Connected to WiFi {WIFI_SSID}"); | |
| long elapsed = (DateTime.UtcNow.Ticks - start) / 10000; | |
| if (DEBUG_TIMER) Debug.WriteLine($"> WiFi connection took: {elapsed}ms"); | |
| while (true) | |
| { | |
| start = DateTime.UtcNow.Ticks; | |
| bool sent = false; | |
| try | |
| { | |
| HttpWebRequest request = (HttpWebRequest)WebRequest.Create($"https://discord.com/api/v9/channels/{DISCORD_CHANNEL_ID}/messages"); | |
| request.Method = "POST"; | |
| string auth = DISCORD_IS_APP ? $"Bot {DISCORD_TOKEN}" : DISCORD_TOKEN; | |
| request.Headers.Add("Authorization", auth); | |
| request.ContentType = "application/json"; | |
| string data = "{\"content\": \"" + DISCORD_MESSAGE + "\"}"; | |
| byte[] body = Encoding.UTF8.GetBytes(data); | |
| request.ContentLength = body.Length; | |
| using (Stream stream = request.GetRequestStream()) | |
| { | |
| stream.Write(body, 0, body.Length); | |
| } | |
| sent = true; | |
| message_count++; | |
| } | |
| catch (WebException wex) | |
| { | |
| if (sent) | |
| { | |
| Debug.WriteLine("Message sent but response read failed -> counting as success"); | |
| } | |
| else | |
| { | |
| Debug.WriteLine($"Failed to send message: {wex.Message}"); | |
| message_count--; | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| Debug.WriteLine($"Unexpected error: {ex}"); | |
| } | |
| Debug.WriteLine("STATS =========="); | |
| Debug.WriteLine($"Successfully sent messages: {message_count}"); | |
| Debug.WriteLine($"Sending rate: {TARGET_RATE/1000}s/m"); | |
| Debug.WriteLine("================"); | |
| elapsed = (DateTime.UtcNow.Ticks - start) / 10000; | |
| if (DEBUG_TIMER) Debug.WriteLine($"> Main Loop took: {elapsed}ms"); | |
| long sleep_time = TARGET_RATE - elapsed; | |
| if (sleep_time < 0) sleep_time = 0; | |
| Debug.WriteLine($"Waiting {sleep_time / 1000}s before sending next message"); | |
| Thread.Sleep((int)sleep_time); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment