This commit is contained in:
Elijah R 2024-04-21 13:28:07 -04:00
commit 6891b4376a
9 changed files with 639 additions and 0 deletions

402
.gitignore vendored Normal file
View file

@ -0,0 +1,402 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
.idea/
# config
config.toml

16
CollabBot.sln Normal file
View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CollabBot", "CollabBot\CollabBot.csproj", "{98585BE2-CF5F-4BC5-AE49-1E6A88470BF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98585BE2-CF5F-4BC5-AE49-1E6A88470BF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98585BE2-CF5F-4BC5-AE49-1E6A88470BF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98585BE2-CF5F-4BC5-AE49-1E6A88470BF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98585BE2-CF5F-4BC5-AE49-1E6A88470BF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyVersion>3.0</AssemblyVersion>
<FileVersion>3.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02211" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02211" />
<PackageReference Include="Samboy063.Tomlet" Version="5.3.1" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,136 @@
using System.Text.Json;
using System.Text.RegularExpressions;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Microsoft.VisualBasic;
namespace CollabBot;
public class DiscordCommands : ApplicationCommandModule
{
[SlashCommand("vnc", "View insecure VNCs around the world!")]
public async Task VNC(InteractionContext ctx,
[Option("country", "If specified, a random VNC from this country")] string? country = null)
{
await ctx.DeferAsync();
VNC vnc;
using var http = new HttpClient();
if (country != null)
{
if (!Regex.IsMatch(country, "^[a-zA-Z]{2}$"))
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(
"Country name must be ISO code (i.e. GB for England, US for United States)"));
return;
}
var response =
await http.GetStringAsync(
$"https://computernewb.com/vncresolver/api/scans/vnc/search?country={country}");
var results = JsonSerializer.Deserialize<VNCSearchResult>(response);
if (results == null || results.error != null)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(results != null
? results.error!
: "Failed to fetch VNC data (response was null, please ping an admin!)"));
}
if (results.count == 0)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(country.ToUpper() == "NK" ? "You wish lol" : "No VNCs from that country found."));
return;
}
var random = new Random().Next(results.count);
response = await http.GetStringAsync(
$"https://computernewb.com/vncresolver/api/scans/vnc/id/{results.result[random]}");
vnc = JsonSerializer.Deserialize<VNC>(response);
}
else
{
var response = await http.GetStringAsync("https://computernewb.com/vncresolver/api/scans/vnc/random");
vnc = JsonSerializer.Deserialize<VNC>(response);
}
if (vnc == null)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Failed to fetch VNC data (response was null, please ping an admin!)"));
return;
}
var embed = new DiscordEmbedBuilder()
.WithTitle($"VNC {vnc.id}").WithUrl($"https://computernewb.com/vncresolver/browse/#id/{vnc.id}")
.AddField("Address", $"{vnc.ip}:{vnc.port}")
.AddField("Location", $"{vnc.city}, {vnc.country} :flag_{vnc.country.ToLower()}:")
.AddField("ASN", vnc.asn)
.WithImageUrl($"https://computernewb.com/vncresolver/api/scans/vnc/screenshot/{vnc.id}.jpeg")
.WithFooter($"Added to database on {vnc.createdat}");
if (!String.IsNullOrEmpty(vnc.clientname)) embed.AddField("Client", vnc.clientname);
if (!String.IsNullOrEmpty(vnc.screenres)) embed.AddField("Screen Resolution", vnc.screenres);
if (!String.IsNullOrEmpty(vnc.hostname)) embed.AddField("Hostname", vnc.hostname);
await ctx.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(embed));
}
[SlashCommand("report", "Report a user for breaking the rules on the main VMs")]
public async Task ReportUser(InteractionContext ctx,
[Option("user", "Who is breaking the rules?")]
string user,
[Option("vm", "Which VM are they on?"), ChoiceProvider(typeof(VMChoiceProvider))]
string vm,
[Option("rule", "Which rule are they breaking?"), ChoiceProvider(typeof(RulesChoiceProvider))]
string rule,
[Option("reason", "What exactly are they doing?")]
string reason
)
{
await ctx.DeferAsync(true);
await Program.ReportChannel.SendMessageAsync($"<@&{Program.Config.ReportRole}>", new DiscordEmbedBuilder()
.WithTitle("User Reported")
.AddField("User", user)
.AddField("VM", vm)
.AddField("Rule", rule)
.AddField("Reason", reason)
.AddField("Reporter", $"{ctx.User.Mention} ({ctx.User.Username})")
.Build());
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Thank you for your report!"));
}
}
public abstract class DictChoiceProvider : ChoiceProvider
{
public abstract Dictionary<string,string> Options { get; }
public override Task<IEnumerable<DiscordApplicationCommandOptionChoice>> Provider()
{
return Task.FromResult(Options.Select(o => new DiscordApplicationCommandOptionChoice(o.Key, o.Value)));
}
}
public class RulesChoiceProvider : DictChoiceProvider
{
public override Dictionary<string, string> Options => new()
{
{ "R1. Don't break the law.", "R1" },
{ "R2. No running DoS/DDoS tools.", "R2"},
{ "R3. No spam distribution.", "R3"},
{ "R4. Do not abuse any exploits.", "R4" },
{ "R6. One vote per person.", "R6" },
{ "R7. No Remote Administration Tools.", "R7" },
{ "R8. No bypassing CollabNet.", "R8" },
{ "R9. No performing destructive actions constantly.", "R9" },
{ "R10. No Cryptomining", "R10" },
{ "NSFW Content on Main VMs", "NSFW" }
};
}
public class VMChoiceProvider : DictChoiceProvider
{
public override Dictionary<string, string> Options => new()
{
{ "VM0b0t", "VM0b0t" },
{ "VM1", "VM1" },
{ "VM2", "VM2" },
{ "VM3", "VM3" },
{ "VM4", "VM4" },
{ "VM5", "VM5" },
{ "VM6", "VM6" },
{ "VM7", "VM7" },
{ "VM8", "VM8" }
};
}

8
CollabBot/IConfig.cs Normal file
View file

@ -0,0 +1,8 @@
namespace CollabBot;
public class IConfig
{
public string DiscordToken { get; set; }
public ulong ReportChannel { get; set; }
public ulong ReportRole { get; set; }
}

27
CollabBot/Program.cs Normal file
View file

@ -0,0 +1,27 @@
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Tomlet;
namespace CollabBot;
class Program
{
public static IConfig Config { get; private set; }
public static DiscordChannel ReportChannel { get; private set; }
async static Task Main(string[] args)
{
Config = TomletMain.To<IConfig>(File.ReadAllText("config.toml"));
var discord = new DiscordClient(new DiscordConfiguration
{
Token = Config.DiscordToken,
TokenType = TokenType.Bot,
Intents = DiscordIntents.AllUnprivileged
});
var slash = discord.UseSlashCommands();
slash.RegisterCommands<DiscordCommands>();
await discord.ConnectAsync();
ReportChannel = await discord.GetChannelAsync(Config.ReportChannel);
await Task.Delay(-1);
}
}

20
CollabBot/VNC.cs Normal file
View file

@ -0,0 +1,20 @@
namespace CollabBot;
public class VNC
{
public int id { get; set; }
public string ip { get; set; }
public int port { get; set; }
public string city { get; set; }
public string state { get; set; }
public string country { get; set; }
public string asn { get; set; }
public string clientname { get; set; }
public string screenres { get; set; }
public string hostname { get; set; }
public string osname { get; set; }
public string openports { get; set; }
public string username { get; set; }
public string password { get; set; }
public string createdat { get; set; }
}

View file

@ -0,0 +1,8 @@
namespace CollabBot;
public class VNCSearchResult
{
public int count { get; set; }
public int[] result { get; set; }
public string? error { get; set; }
}

3
config.example.toml Normal file
View file

@ -0,0 +1,3 @@
DiscordToken = "abcdefg"
ReportChannel = 012345678901234567
ReportRole = 012345678901234567