mirror of
https://github.com/Stone-Red-Code/DiscordCLI.git
synced 2026-09-04 00:55:58 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b0765997a | ||
|
|
361859d2bc | ||
|
|
881299c2d2 | ||
|
|
4231256bfe | ||
|
|
5bf354a22a | ||
|
|
c7e4e89e17 | ||
|
|
6186779115 | ||
|
|
49d62348c8 | ||
|
|
db75f856ff | ||
|
|
3d8d1d4709 | ||
|
|
a1609916c2 | ||
|
|
d162cc0056 | ||
|
|
c63a480fe5 | ||
|
|
45d5b51bab | ||
|
|
5a09767dbc | ||
|
|
f900292d86 | ||
|
|
95d3c4e476 | ||
|
|
fb55a909f0 | ||
|
|
b758cdab49 | ||
|
|
e9cde21189 | ||
|
|
d518f79263 | ||
|
|
7fbfd85ff4 | ||
|
|
16cee9413b | ||
|
|
2265b044cc | ||
|
|
d9143457a7 | ||
|
|
35db02685b | ||
|
|
af721731ea | ||
|
|
652c81defa | ||
|
|
07ff5a6d4a | ||
|
|
57215db498 | ||
|
|
76845b9ae0 | ||
|
|
31b4f9cc44 | ||
|
|
524ed14b1f | ||
|
|
8d93a9de2c | ||
|
|
c6ba3a434d | ||
|
|
fc3d170e07 | ||
|
|
ce4fb237b3 | ||
|
|
f0fcbc03c5 | ||
|
|
f53d614fca | ||
|
|
74f40593ba | ||
|
|
7521d9053d | ||
|
|
b38433badc | ||
|
|
890625e6da | ||
|
|
433a71e838 | ||
|
|
1ddd35e5a4 | ||
|
|
12271b760b | ||
|
|
992dcf832b | ||
|
|
d3117795d3 | ||
|
|
144869d5ad | ||
|
|
bd5384f356 | ||
|
|
9ad6a23305 | ||
|
|
da2fa6f581 |
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
+365
-1
@@ -1 +1,365 @@
|
||||
*.txt
|
||||
## 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/master/VisualStudio.gitignore
|
||||
|
||||
# DiscordCLI-specific files
|
||||
token.txt
|
||||
|
||||
# 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
|
||||
*.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 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/
|
||||
|
||||
# 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
|
||||
|
||||
Binary file not shown.
@@ -1,205 +0,0 @@
|
||||
using DSharpPlus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Stone_Red_Utilities.ColorConsole;
|
||||
|
||||
using DSharpPlus.Entities;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
internal class CommandsManager : Commands
|
||||
{
|
||||
private readonly DiscordClient client;
|
||||
|
||||
private readonly Dictionary<string, (string, Action<string>)> CommandsList;
|
||||
|
||||
public CommandsManager(DiscordClient dicordClient) : base(dicordClient)
|
||||
{
|
||||
client = dicordClient;
|
||||
|
||||
CommandsList = new()
|
||||
{
|
||||
{ "exit", ("exits application", null) },
|
||||
{ "logout", ("deletes auth token and exits application", DeleteToken) },
|
||||
{ "guilds", ("lists all guilds you are in", ListGuilds) },
|
||||
{ "dms", ("lists all private channels (Not implemented yet)", ListDms) },
|
||||
{ "channels", ("lists all channels of guild args:<guild name/index>", ListGuildChannels) },
|
||||
{ "enterg", ("enter guild args:<guild name/index>", ListGuildChannels) },
|
||||
{ "enterc", ("enter chat args:<channel name/index>", EnterChannel) },
|
||||
};
|
||||
}
|
||||
|
||||
public bool CheckCommand(string input)
|
||||
{
|
||||
input = input.Trim().ToLower().Replace('\n', '\0');
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return false;
|
||||
|
||||
if (input.StartsWith('<'))
|
||||
{
|
||||
input = input.Remove(0, 1);
|
||||
}
|
||||
else if (GlobalInformation.currentTextChannel != null)
|
||||
{
|
||||
Console.CursorTop--;
|
||||
Console.Write("\r" + new string(' ', Console.WindowWidth));
|
||||
GlobalInformation.currentTextChannel.SendMessageAsync(input);
|
||||
return false;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
if (input == "exit" || input is null)
|
||||
return true;
|
||||
|
||||
string args = input.Contains(" ") ? input[input.IndexOf(" ")..].Trim() : null;
|
||||
input = input.Contains(" ") ? input.Substring(0, input.IndexOf(" ")) : input;
|
||||
|
||||
if (input == "help")
|
||||
{
|
||||
for (int i = 0; i < CommandsList.Count; i++)
|
||||
{
|
||||
Console.Write($"{i + 1}. {CommandsList.Keys.ElementAt(i)}".PadRight(15));
|
||||
Console.WriteLine(CommandsList.Values.ElementAt(i).Item1);
|
||||
}
|
||||
}
|
||||
else if (CommandsList.ContainsKey(input))
|
||||
{
|
||||
CommandsList[input].Item2(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleExt.WriteLine("Command does not exist!", ConsoleColor.Red);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal class Commands
|
||||
{
|
||||
private IReadOnlyDictionary<ulong, DiscordGuild> socketGuildsCache;
|
||||
|
||||
private readonly DiscordClient client;
|
||||
|
||||
public Commands(DiscordClient dicordClient)
|
||||
{
|
||||
client = dicordClient;
|
||||
}
|
||||
|
||||
protected void ListGuilds(string args)
|
||||
{
|
||||
socketGuildsCache ??= client.Guilds;
|
||||
|
||||
int index = 1;
|
||||
foreach (DiscordGuild guild in socketGuildsCache.Values)
|
||||
{
|
||||
Console.WriteLine($"{index}. {guild.Name}");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ListDms(string args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected void ListGuildChannels(string args)
|
||||
{
|
||||
IReadOnlyCollection<DiscordChannel> textChannels;
|
||||
DiscordGuild guild;
|
||||
|
||||
if (args != null)
|
||||
{
|
||||
if (int.TryParse(args, out int ind))
|
||||
{
|
||||
guild = socketGuildsCache?.Values.ElementAtOrDefault(ind - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
guild = socketGuildsCache?.FirstOrDefault(x => x.Value.Name == args).Value;
|
||||
}
|
||||
GlobalInformation.currentTextChannel = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
guild = GlobalInformation.currentGuild;
|
||||
}
|
||||
|
||||
if (guild is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("Guild not found!", ConsoleColor.Red);
|
||||
GlobalInformation.currentTextChannel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
GlobalInformation.currentGuild = guild;
|
||||
textChannels = guild.Channels;
|
||||
|
||||
int index = 1;
|
||||
foreach (DiscordChannel channel in textChannels)
|
||||
{
|
||||
switch (channel.Type)
|
||||
{
|
||||
case ChannelType.Category:
|
||||
//Console.WriteLine($"[{channel.Name}]");
|
||||
break;
|
||||
|
||||
case ChannelType.Text:
|
||||
Console.WriteLine($" {index}. {channel.Name}");
|
||||
index++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async void EnterChannel(string args)
|
||||
{
|
||||
DiscordChannel textChannel;
|
||||
|
||||
if (GlobalInformation.currentGuild is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("You are not in a guild!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.TryParse(args, out int ind))
|
||||
{
|
||||
textChannel = GlobalInformation.currentGuild?.Channels.Where(x => x.Type == ChannelType.Text).ElementAtOrDefault(ind - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
textChannel = GlobalInformation.currentGuild?.Channels.Where(x => x.Type == ChannelType.Text).FirstOrDefault(x => x.Name == args);
|
||||
}
|
||||
|
||||
GlobalInformation.currentTextChannel = textChannel;
|
||||
|
||||
if (textChannel is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("Channel not found!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (DiscordMessage message in (await textChannel.GetMessagesAsync(10)).Reverse())
|
||||
{
|
||||
try
|
||||
{
|
||||
await Program.WriteMessage(message, textChannel, GlobalInformation.currentGuild);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void DeleteToken(string args)
|
||||
{
|
||||
File.Delete(Program.tokenPath);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
using ColorMine.ColorSpaces;
|
||||
using ColorMine.ColorSpaces.Comparisons;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using Stone_Red_Utilities.ColorConsole;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Color = System.Drawing.Color;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
=> new Program().MainAsync().GetAwaiter().GetResult();
|
||||
|
||||
private static DiscordClient client;
|
||||
private CommandsManager commandsManager;
|
||||
|
||||
private static string input = "<";
|
||||
public const string tokenPath = "token.txt";
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
|
||||
string token = string.Empty;
|
||||
if (File.Exists(tokenPath))
|
||||
token = File.ReadAllText(tokenPath);
|
||||
|
||||
while (string.IsNullOrEmpty(token))
|
||||
{
|
||||
Console.Write("Enter auth token: ");
|
||||
token = Console.ReadLine();
|
||||
}
|
||||
|
||||
File.WriteAllText(tokenPath, token);
|
||||
|
||||
try
|
||||
{
|
||||
client = new DiscordClient(new DiscordConfiguration()
|
||||
{
|
||||
Token = token,
|
||||
TokenType = TokenType.User
|
||||
});
|
||||
|
||||
client.MessageCreated += Client_MessageCreated;
|
||||
|
||||
await client.ConnectAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleExt.WriteLine(ex, ConsoleColor.Red);
|
||||
|
||||
if (ex.Message.Contains("Authentication failed"))
|
||||
File.Delete(tokenPath);
|
||||
return;
|
||||
}
|
||||
|
||||
commandsManager = new CommandsManager(client);
|
||||
|
||||
await ReadInput();
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
private async Task Client_MessageCreated(DSharpPlus.EventArgs.MessageCreateEventArgs e)
|
||||
{
|
||||
await WriteMessage(e.Message, e.Channel, e.Guild);
|
||||
}
|
||||
|
||||
public static async Task WriteMessage(DiscordMessage message, DiscordChannel channel, DiscordGuild guild)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (channel.Id != GlobalInformation.currentTextChannel?.Id)
|
||||
return;
|
||||
DiscordUser user = message.Author;
|
||||
DiscordMember discordMember = await guild.GetMemberAsync(user.Id);
|
||||
DiscordColor discordColor = discordMember.Color;
|
||||
|
||||
Color color = Color.FromArgb(discordColor.R, discordColor.G, discordColor.B);
|
||||
|
||||
WriteTop($"[{discordMember.DisplayName}]", color, message, $"{discordMember.Username}#{discordMember.Discriminator} {message.Timestamp.LocalDateTime}");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(message.Content))
|
||||
WriteTop(message.Content, Color.White, message);
|
||||
|
||||
foreach (DiscordAttachment attachment in message.Attachments)
|
||||
{
|
||||
WriteTop($"{attachment.Url}", Color.White, message, attachment.FileName);
|
||||
}
|
||||
foreach (DiscordEmbed embed in message.Embeds)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(embed.Title))
|
||||
WriteTop($">>> {{{embed.Title}}}", Color.FromArgb(embed.Color.Value), message);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(embed.Description))
|
||||
WriteTop($">> {embed.Description}", Color.White, message);
|
||||
|
||||
WriteTop($"{string.Join(Environment.NewLine, embed.Fields.Select(x => $">{x.Name}{Environment.NewLine}{x.Value}"))}", Color.White, message);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
|
||||
WriteTop(string.Empty, Color.White, message);
|
||||
Console.Write($"[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{GlobalInformation.currentGuild?.Name}/{GlobalInformation.currentTextChannel?.Name}] ==> ");
|
||||
Console.Write(input);
|
||||
}
|
||||
|
||||
private async Task ReadInput()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
bool exit = false;
|
||||
while (!exit)
|
||||
{
|
||||
string infoString = $"\r[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{GlobalInformation.currentGuild?.Name}/{GlobalInformation.currentTextChannel?.Name}] ==> ";
|
||||
if (input.StartsWith('<'))
|
||||
Console.Write(Environment.NewLine + infoString);
|
||||
|
||||
input = string.Empty;
|
||||
|
||||
ConsoleKeyInfo keyInfo;
|
||||
do
|
||||
{
|
||||
keyInfo = Console.ReadKey(true);
|
||||
if (!char.IsControl(keyInfo.KeyChar))
|
||||
input += keyInfo.KeyChar.ToString();
|
||||
|
||||
if (keyInfo.Key == ConsoleKey.Backspace)
|
||||
{
|
||||
if (input.Length > 0)
|
||||
{
|
||||
input = input.Remove(input.Length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
Console.Write(keyInfo.KeyChar);
|
||||
if (keyInfo.Key == ConsoleKey.Backspace)
|
||||
Console.Write(" ");
|
||||
|
||||
Console.CursorLeft = infoString.Length + input.Length - 1;
|
||||
} while (keyInfo.Key != ConsoleKey.Enter);
|
||||
|
||||
if (GlobalInformation.currentTextChannel == null && !input.StartsWith('<'))
|
||||
input = "<" + input;
|
||||
|
||||
exit = commandsManager.CheckCommand(input);
|
||||
}
|
||||
Environment.Exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
private async static void WriteTop(string message, Color color, DiscordMessage discordMessage, string info = null)
|
||||
{
|
||||
ConsoleColor consoleColor = ClosestConsoleColor3(color);
|
||||
|
||||
if (consoleColor == Console.BackgroundColor || consoleColor == ConsoleColor.DarkGray)
|
||||
consoleColor = ConsoleColor.White;
|
||||
|
||||
//Console.SetCursorPosition(0, Console.WindowTop + Console.WindowHeight - 1);
|
||||
|
||||
Console.Write('\r' + new string(' ', Console.WindowWidth) + '\r');
|
||||
|
||||
string[] words = message.Split(' ');
|
||||
for (int i = 0; i < words.Length; i++)
|
||||
{
|
||||
ConsoleColor mentionColor = ConsoleColor.Black;
|
||||
foreach (DiscordUser user in discordMessage.MentionedUsers)
|
||||
{
|
||||
if (user?.Mention is not null)
|
||||
if (words[i].Contains(user.Mention))
|
||||
{
|
||||
words[i] = words[i].Replace(user.Mention, $"@{user.Username}#{user.Discriminator}");
|
||||
mentionColor = ConsoleColor.Blue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DiscordChannel channel in discordMessage.MentionedChannels)
|
||||
{
|
||||
if (channel?.Mention is not null)
|
||||
if (words[i].Contains(channel.Mention))
|
||||
{
|
||||
words[i] = words[i].Replace(channel.Mention, $"#{channel.Name}");
|
||||
mentionColor = ConsoleColor.Blue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (DiscordRole role in discordMessage.MentionedRoles)
|
||||
{
|
||||
if (role?.Mention is not null)
|
||||
if (words[i].Contains(role.Mention))
|
||||
{
|
||||
words[i] = words[i].Replace(role.Mention, $"@{role.Name}");
|
||||
DiscordColor discordColor = role.Color;
|
||||
mentionColor = ClosestConsoleColor3(Color.FromArgb(discordColor.R, discordColor.G, discordColor.B));
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleExt.Write(words[i] + " ", mentionColor == ConsoleColor.Black ? consoleColor : mentionColor);
|
||||
}
|
||||
|
||||
ConsoleExt.WriteLine(" " + info, ConsoleColor.DarkGray);
|
||||
}
|
||||
|
||||
public static ConsoleColor ClosestConsoleColor3(Color targetColor)
|
||||
{
|
||||
double minDif = double.MaxValue;
|
||||
ConsoleColor bestColor = ConsoleColor.White;
|
||||
|
||||
foreach (ConsoleColor consoleColor in Enum.GetValues(typeof(ConsoleColor)))
|
||||
{
|
||||
Color color = Color.FromName(consoleColor.ToString());
|
||||
|
||||
var colorA = new Rgb
|
||||
{
|
||||
R = targetColor.R,
|
||||
G = targetColor.G,
|
||||
B = targetColor.B
|
||||
};
|
||||
|
||||
var colorB = new Rgb
|
||||
{
|
||||
R = color.R,
|
||||
G = color.G,
|
||||
B = color.B
|
||||
};
|
||||
double diff = colorA.Compare(colorB, new Cie1976Comparison());
|
||||
|
||||
if (diff < minDif)
|
||||
{
|
||||
minDif = diff;
|
||||
bestColor = consoleColor;
|
||||
}
|
||||
}
|
||||
return bestColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "netcoreapp3.1",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "3.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"additionalProbingPaths": [
|
||||
"C:\\Users\\David\\.dotnet\\store\\|arch|\\|tfm|",
|
||||
"C:\\Users\\David\\.nuget\\packages",
|
||||
"C:\\Microsoft\\Xamarin\\NuGet"
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"additionalProbingPaths": [
|
||||
"C:\\Users\\David\\.dotnet\\store\\|arch|\\|tfm|",
|
||||
"C:\\Users\\David\\.nuget\\packages",
|
||||
"C:\\Microsoft\\Xamarin\\NuGet"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net5.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "5.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net5.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "5.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
dfd104565a5c51e51c96fc2a0f9e9b9515e39127
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
3e2c7be251ce3e62a6541dac29e1895e802a69f2
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
b19e6f37bddcbdb1df945fddaf2581ec8ab2932c
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
3ab14035ed25e46cb2eb046c245e2f90325a2743
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
3e2c7be251ce3e62a6541dac29e1895e802a69f2
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
8dbf5d9b5cf6fb65f2290f681f68bfa7a21560cd
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
6843f3cabf894dfce1aaffe6c65e64e8531c52b6
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
70e9524befa3e92045c7c316dc8b56aab9375e23
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
8dbf5d9b5cf6fb65f2290f681f68bfa7a21560cd
|
||||
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Stone_Red
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,87 @@
|
||||
# DiscordCLI
|
||||
|
||||
> Use Discord in the terminal
|
||||
|
||||
## Warning
|
||||
|
||||
**Use this software at your own risk!**\
|
||||
This isn't directly a selfbot, but Discord may count it as User account automation and this is against their TOS.\
|
||||
I guess everything should be fine as long as you don't behave conspicuously but still proceed with caution!\
|
||||
Currently there are no known cases where a user got banned for using this Discord client but that doesn't mean it will never happen.\
|
||||
Don't blame me if you get banned!\
|
||||
I will update the above if anything changes!
|
||||
|
||||
## Usage
|
||||
|
||||
1. [Download]("https://github.com/Stone-Red-Code/DiscordCLI/releases
|
||||
) one of the releases
|
||||
2. Execute the `DiscordCLI` file
|
||||
3. Enter your [User Token](https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs#how-to-get-a-user-token">)
|
||||
4. Enter one of the commands below
|
||||
|
||||
## Commands
|
||||
|
||||
### help
|
||||
|
||||
- lists all commands
|
||||
|
||||
### exit
|
||||
|
||||
- exits application
|
||||
|
||||
### logout
|
||||
|
||||
- deletes auth token and exits application
|
||||
|
||||
### clear
|
||||
|
||||
- clears the console
|
||||
|
||||
### guilds
|
||||
|
||||
- lists all guilds you are in
|
||||
|
||||
### dms
|
||||
|
||||
- lists all private channels
|
||||
|
||||
### channels
|
||||
|
||||
- lists all channels of guild
|
||||
|
||||
- args: \<guild name/index>
|
||||
|
||||
### enterg
|
||||
|
||||
- enter guild
|
||||
- args: \<guild name/index>
|
||||
|
||||
### enterc
|
||||
|
||||
- enter channel
|
||||
- args: \<channel name/index>
|
||||
|
||||
### enterd
|
||||
|
||||
- enter DM channel
|
||||
- args: \<channel name/index>
|
||||
|
||||
### userinfo
|
||||
|
||||
- gets information about a user
|
||||
- args: \<user name>
|
||||
|
||||
## Limitations
|
||||
|
||||
DiscordCLI doesn't support everything the official Discord app does.
|
||||
If you find a missing feature in DiscordCLI that is not listed below please tell me or create a pull request and update the list below.
|
||||
|
||||
### Current limitation
|
||||
|
||||
- No voice support
|
||||
- Mentions can't be created easily
|
||||
- You can't add/remove guilds
|
||||
- You can't create/accept friend requests
|
||||
- Discord online status not updating
|
||||
|
||||
And probably more.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,266 @@
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
using Stone_Red_Utilities.StringExtentions;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
internal class Commands
|
||||
{
|
||||
private readonly DiscordClient client;
|
||||
|
||||
private readonly OutputManager outputManager;
|
||||
|
||||
public Commands(DiscordClient dicordClient, OutputManager outputMan)
|
||||
{
|
||||
client = dicordClient;
|
||||
outputManager = outputMan;
|
||||
}
|
||||
|
||||
protected async Task ListGuilds(string args)
|
||||
{
|
||||
int index = 1;
|
||||
foreach (DiscordGuild guild in client.Guilds.Values)
|
||||
{
|
||||
Console.WriteLine($"{index}. {guild.Name}");
|
||||
index++;
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task ListDms(string args)
|
||||
{
|
||||
int index = 1;
|
||||
foreach (DiscordDmChannel dmChannel in client.PrivateChannels)
|
||||
{
|
||||
Console.WriteLine($"{index}. {string.Join(", ", dmChannel.Recipients.Select(x => x.Username))}");
|
||||
index++;
|
||||
}
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task ListGuildChannels(string args)
|
||||
{
|
||||
IReadOnlyCollection<DiscordChannel> discordChannels;
|
||||
DiscordGuild guild;
|
||||
|
||||
if (args != null)
|
||||
{
|
||||
if (int.TryParse(args, out int ind))
|
||||
{
|
||||
guild = client.Guilds?.Values.ElementAtOrDefault(ind - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
guild = client.Guilds?.FirstOrDefault(x => x.Value.Name == args).Value;
|
||||
}
|
||||
GlobalInformation.currentTextChannel = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
guild = GlobalInformation.currentGuild;
|
||||
}
|
||||
|
||||
if (guild is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("Guild not found!", ConsoleColor.Red);
|
||||
GlobalInformation.currentTextChannel = null;
|
||||
return;
|
||||
}
|
||||
|
||||
GlobalInformation.currentGuild = guild;
|
||||
discordChannels = guild.Channels;
|
||||
|
||||
int index = 0;
|
||||
foreach (DiscordChannel channel in discordChannels.OrderBy(x => x.Position))
|
||||
{
|
||||
if (channel.Type == ChannelType.Category)
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"--- {channel.Name} ---");
|
||||
foreach (DiscordChannel child in channel.Children.OrderBy(x => x.Position))
|
||||
{
|
||||
if (child.Type == ChannelType.Text)
|
||||
{
|
||||
index++;
|
||||
|
||||
Console.WriteLine($"{index}. {child.Name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleExt.WriteLine($"-. {child.Name}", ConsoleColor.DarkGray);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task EnterChannel(string args)
|
||||
{
|
||||
DiscordChannel textChannel;
|
||||
|
||||
if (GlobalInformation.currentGuild is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("You are not in a guild!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
if (int.TryParse(args, out int ind))
|
||||
{
|
||||
textChannel = GlobalInformation.currentGuild?.Channels.Where(x => x.Type == ChannelType.Text).OrderBy(x => x.Position).ElementAtOrDefault(ind - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
textChannel = GlobalInformation.currentGuild?.Channels.Where(x => x.Type == ChannelType.Text).OrderBy(x => x.Position).FirstOrDefault(x => x.Name == args);
|
||||
}
|
||||
|
||||
GlobalInformation.currentTextChannel = textChannel;
|
||||
|
||||
if (textChannel is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("Channel not found!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (DiscordMessage message in (textChannel.GetMessagesAsync(10).Result).Reverse())
|
||||
{
|
||||
await outputManager.WriteMessage(message, textChannel, false);
|
||||
}
|
||||
Console.CursorTop--;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleExt.WriteLine(ex.Message, ConsoleColor.Red);
|
||||
GlobalInformation.currentTextChannel = null;
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task EnterDmChannel(string args)
|
||||
{
|
||||
DiscordDmChannel dmChannel;
|
||||
|
||||
GlobalInformation.currentGuild = null;
|
||||
|
||||
if (int.TryParse(args, out int ind))
|
||||
{
|
||||
dmChannel = client.PrivateChannels.ElementAtOrDefault(ind - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dmChannel = client.PrivateChannels.FirstOrDefault(x => x.Name == args);
|
||||
}
|
||||
|
||||
GlobalInformation.currentTextChannel = dmChannel;
|
||||
|
||||
if (dmChannel is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("Channel not found!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
foreach (DiscordMessage message in (await dmChannel.GetMessagesAsync(10)).Reverse())
|
||||
{
|
||||
await outputManager.WriteMessage(message, dmChannel, false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ConsoleExt.WriteLine(ex.Message, ConsoleColor.Red);
|
||||
GlobalInformation.currentTextChannel = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task DeleteToken(string args)
|
||||
{
|
||||
File.Delete(Program.tokenPath);
|
||||
Environment.Exit(0);
|
||||
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected async Task UserInfo(string userName)
|
||||
{
|
||||
if (GlobalInformation.currentGuild is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("You are not in a guild!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
if (userName is null)
|
||||
{
|
||||
ConsoleExt.WriteLine("User not found!", ConsoleColor.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordUser discordUser = await GetDiscordUser(userName);
|
||||
|
||||
string status = discordUser?.Presence?.Status.ToString();
|
||||
status ??= "N/A";
|
||||
|
||||
if (discordUser is DiscordMember discordMember)
|
||||
{
|
||||
string infoString =
|
||||
$"Username: {discordMember.Username}#{discordMember.Discriminator}" + Environment.NewLine +
|
||||
$"Nickname: {discordMember.Nickname ?? "N/A"}" + Environment.NewLine +
|
||||
$"Roles: {string.Join(", ", discordMember.Roles.Select(x => x.Name))}" + Environment.NewLine +
|
||||
$"Status: {status}" + Environment.NewLine +
|
||||
$"Created at: {discordMember.CreationTimestamp}" + Environment.NewLine +
|
||||
$"ID: {discordMember.Id}" + Environment.NewLine +
|
||||
$"Bot: {discordMember.IsBot}";
|
||||
Console.WriteLine(infoString);
|
||||
}
|
||||
else if (discordUser is not null)
|
||||
{
|
||||
string infoString =
|
||||
$"Username: {discordUser.Username}#{discordUser.Discriminator}" + Environment.NewLine +
|
||||
$"Status: {status}" + Environment.NewLine +
|
||||
$"Created at: {discordUser.CreationTimestamp}" + Environment.NewLine +
|
||||
$"ID: {discordUser.Id}" + Environment.NewLine +
|
||||
$"Bot: {discordUser.IsBot}";
|
||||
Console.WriteLine(infoString);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleExt.WriteLine("User not found!", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
async Task<DiscordUser> GetDiscordUser(string name)
|
||||
{
|
||||
DiscordUser discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => user.Username.EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}#{user.Discriminator}".EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}".EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Nickname}".EqualsIgnoreSpacesAndCase(userName));
|
||||
|
||||
if (discordUser is null)
|
||||
{
|
||||
IReadOnlyList<DiscordUser> users = await GlobalInformation.currentGuild.GetAllMembersAsync();
|
||||
discordUser ??= users.FirstOrDefault(user => user.Username.EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= users.FirstOrDefault(user => $"{user.Username}#{user.Discriminator}".EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= users.FirstOrDefault(user => $"{user.Username}".EqualsIgnoreSpacesAndCase(userName));
|
||||
}
|
||||
|
||||
return discordUser;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task Clear(string args)
|
||||
{
|
||||
Console.Clear();
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
using DSharpPlus;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Timers;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
internal class CommandsManager : Commands
|
||||
{
|
||||
private readonly DiscordClient client;
|
||||
|
||||
private readonly Dictionary<string, (string, Func<string, Task>)> CommandsList;
|
||||
private int cooldown = 0;
|
||||
|
||||
public CommandsManager(DiscordClient dicordClient, OutputManager outputManager) : base(dicordClient, outputManager)
|
||||
{
|
||||
client = dicordClient;
|
||||
|
||||
CommandsList = new()
|
||||
{
|
||||
{ "exit", ("exits application", null) },
|
||||
{ "logout", ("deletes auth token and exits application", DeleteToken) },
|
||||
{ "clear", ("clears the console", Clear) },
|
||||
{ "guilds", ("lists all guilds you are in", ListGuilds) },
|
||||
{ "dms", ("lists all private channels", ListDms) },
|
||||
{ "channels", ("lists all channels of guild args:<guild name/index>", ListGuildChannels) },
|
||||
{ "enterg", ("enter guild args:<guild name/index>", ListGuildChannels) },
|
||||
{ "enterc", ("enter channel args:<channel name/index>", EnterChannel) },
|
||||
{ "enterd", ("enter DM channel args:<channel name/index>", EnterDmChannel) },
|
||||
{ "userinfo", ("gets information about a user args:<username>", UserInfo) },
|
||||
};
|
||||
|
||||
Timer cooldownTimer = new Timer(1000);
|
||||
cooldownTimer.Elapsed += CooldownTimer_Elapsed;
|
||||
cooldownTimer.Start();
|
||||
}
|
||||
|
||||
private void CooldownTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (cooldown > 0)
|
||||
cooldown--;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check the command and return true if the program should exit
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns>exit bool and write override bool</returns>
|
||||
public async Task<(bool, bool)> CheckCommand(string rawInput)
|
||||
{
|
||||
string input = rawInput.Trim().ToLower().Replace('\n', '\0');
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.StartsWith(InputManager.Prefix) ? input.Remove(0, 1) : input))
|
||||
{
|
||||
Console.CursorTop--;
|
||||
return (false, false);
|
||||
}
|
||||
|
||||
cooldown++;
|
||||
|
||||
if (cooldown > 1)
|
||||
{
|
||||
Console.WriteLine();
|
||||
ConsoleExt.WriteLine("You are beeing rate limited!", ConsoleColor.Yellow);
|
||||
ConsoleExt.WriteLine("Wait a few seconds before making another request!", ConsoleColor.Yellow);
|
||||
return (false, true);
|
||||
}
|
||||
|
||||
if (input.StartsWith(InputManager.Prefix))
|
||||
{
|
||||
input = input.Remove(0, 1);
|
||||
}
|
||||
else if (GlobalInformation.currentTextChannel != null)
|
||||
{
|
||||
cooldown++;
|
||||
|
||||
try
|
||||
{
|
||||
await GlobalInformation.currentTextChannel.SendMessageAsync(rawInput);
|
||||
Console.CursorTop--;
|
||||
Console.Write("\r" + new string(' ', Console.WindowWidth));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine();
|
||||
ConsoleExt.WriteLine(ex.Message, ConsoleColor.Red);
|
||||
}
|
||||
return (false, true);
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
if (input == "exit" || input is null)
|
||||
return (true, false);
|
||||
|
||||
string args = input.Contains(" ") ? input[input.IndexOf(" ")..].Trim() : null;
|
||||
input = input.Contains(" ") ? input.Substring(0, input.IndexOf(" ")) : input;
|
||||
|
||||
if (input == "help" || input == "?")
|
||||
{
|
||||
Console.WriteLine($"Prefix: '{InputManager.Prefix}' (Only required in text channels)");
|
||||
Console.WriteLine();
|
||||
|
||||
for (int i = 0; i < CommandsList.Count; i++)
|
||||
{
|
||||
Console.Write($"{i + 1}. {CommandsList.Keys.ElementAt(i)}".PadRight(15));
|
||||
Console.WriteLine(CommandsList.Values.ElementAt(i).Item1);
|
||||
}
|
||||
}
|
||||
else if (CommandsList.ContainsKey(input))
|
||||
{
|
||||
await CommandsList[input].Item2(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleExt.WriteLine("Command does not exist!", ConsoleColor.Red);
|
||||
}
|
||||
return (false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AssemblyVersion>0.0.5.0</AssemblyVersion>
|
||||
<FileVersion>0.0.5.0</FileVersion>
|
||||
<Version>0.0.5.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.4" />
|
||||
<PackageReference Include="ColorMineStandard" Version="1.0.0" />
|
||||
<PackageReference Include="DSharpPlus" Version="3.2.3" />
|
||||
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.0.2" />
|
||||
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\PublishProfiles\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<_LastSelectedProfileId>C:\Users\David\Google Drive\Programmieren\DiscordCLI\DiscordCLI\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
|
||||
<_LastSelectedProfileId>C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\Properties\PublishProfiles\Linux-ARM.pubxml</_LastSelectedProfileId>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,9 +1,4 @@
|
||||
using DSharpPlus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
@@ -11,6 +6,5 @@ namespace DiscordCLI
|
||||
{
|
||||
public static DiscordGuild currentGuild;
|
||||
public static DiscordChannel currentTextChannel;
|
||||
public static int colorMode = 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using DSharpPlus;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using DSharpPlus.Entities;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
internal class InputManager
|
||||
{
|
||||
private readonly CommandsManager commandsManager;
|
||||
private readonly DiscordClient client;
|
||||
private readonly List<string> previousInputs = new List<string>();
|
||||
public const string Prefix = ">";
|
||||
public string Input { get; private set; } = string.Empty;
|
||||
|
||||
public InputManager(DiscordClient dicordClient, CommandsManager commandsMan)
|
||||
{
|
||||
client = dicordClient;
|
||||
commandsManager = commandsMan;
|
||||
}
|
||||
|
||||
public async Task ReadInput()
|
||||
{
|
||||
int inputListIndex = 0;
|
||||
bool exit = false;
|
||||
bool printOverride = false;
|
||||
string lastInput = Prefix;
|
||||
while (!exit)
|
||||
{
|
||||
DiscordDmChannel dmChannel = GlobalInformation.currentTextChannel as DiscordDmChannel;
|
||||
string infoString = $"\r[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{(dmChannel is null ? GlobalInformation.currentGuild?.Name : "DMs")}/{(dmChannel is null ? GlobalInformation.currentTextChannel?.Name : string.Join(", ", dmChannel.Recipients.Select(x => x.Username)))}] ==> ";
|
||||
if (lastInput.StartsWith(Prefix) || printOverride)
|
||||
Console.Write(Environment.NewLine + infoString);
|
||||
|
||||
printOverride = false;
|
||||
|
||||
ConsoleKeyInfo keyInfo;
|
||||
do
|
||||
{
|
||||
keyInfo = Console.ReadKey(true);
|
||||
if (!char.IsControl(keyInfo.KeyChar))
|
||||
Input += keyInfo.KeyChar.ToString();
|
||||
|
||||
if (keyInfo.Key == ConsoleKey.Backspace && Input.Length > 0)
|
||||
{
|
||||
Input = Input.Remove(Input.Length - 1);
|
||||
}
|
||||
else if (keyInfo.Key == ConsoleKey.UpArrow)
|
||||
{
|
||||
if (previousInputs.Count > 0)
|
||||
Input = previousInputs[previousInputs.Count - inputListIndex - 1];
|
||||
|
||||
if (inputListIndex < previousInputs.Count - 1)
|
||||
inputListIndex++;
|
||||
Console.CursorLeft = infoString.Length - 1;
|
||||
Console.Write(Input + new string(' ', Console.WindowWidth - infoString.Length - 1));
|
||||
}
|
||||
else if (keyInfo.Key == ConsoleKey.DownArrow)
|
||||
{
|
||||
if (previousInputs.Count > 0)
|
||||
Input = previousInputs[previousInputs.Count - inputListIndex - 1];
|
||||
|
||||
if (inputListIndex > 0)
|
||||
inputListIndex--;
|
||||
Console.CursorLeft = infoString.Length - 1;
|
||||
Console.Write(Input + new string(' ', Console.WindowWidth - infoString.Length - 1));
|
||||
}
|
||||
|
||||
Console.Write(keyInfo.KeyChar);
|
||||
if (keyInfo.Key == ConsoleKey.Backspace)
|
||||
Console.Write(" ");
|
||||
|
||||
Console.CursorLeft = infoString.Length + Input.Length - 1;
|
||||
} while (keyInfo.Key != ConsoleKey.Enter);
|
||||
|
||||
if (GlobalInformation.currentTextChannel == null)
|
||||
{
|
||||
Input = Input.Trim();
|
||||
if (!Input.StartsWith(Prefix))
|
||||
Input = Prefix + Input;
|
||||
|
||||
if (previousInputs.Count > 10)
|
||||
previousInputs.RemoveAt(0);
|
||||
|
||||
if (previousInputs.Count == 0 || previousInputs[previousInputs.Count - 1] != Input)
|
||||
previousInputs.Add(new string(Input));
|
||||
}
|
||||
|
||||
inputListIndex = 0;
|
||||
lastInput = new string(Input);
|
||||
Input = string.Empty;
|
||||
|
||||
(exit, printOverride) = await commandsManager.CheckCommand(lastInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
using ColorMine.ColorSpaces.Comparisons;
|
||||
using ColorMine.ColorSpaces;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace DiscordCLI
|
||||
{
|
||||
internal class OutputManager
|
||||
{
|
||||
private readonly DiscordClient client;
|
||||
public InputManager InputManager { get; set; }
|
||||
|
||||
public OutputManager(DiscordClient discordClient)
|
||||
{
|
||||
client = discordClient;
|
||||
}
|
||||
|
||||
public async Task WriteMessage(DiscordMessage message, DiscordChannel channel, bool writeInfo = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (message.ChannelId != GlobalInformation.currentTextChannel?.Id)
|
||||
return;
|
||||
|
||||
DiscordUser user = message.Author;
|
||||
|
||||
if (GlobalInformation.currentGuild is not null)
|
||||
{
|
||||
DiscordMember discordMember = await channel.Guild.GetMemberAsync(user.Id);
|
||||
DiscordColor discordColor = discordMember.Color;
|
||||
Color color = Color.FromArgb(discordColor.R, discordColor.G, discordColor.B);
|
||||
|
||||
WriteTop($"[{discordMember.DisplayName}]", color, message, true, true, $"{discordMember.Username}#{discordMember.Discriminator} {message.Timestamp.LocalDateTime}");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTop($"[{user.Username}]", Color.White, message, true, true, $"{user.Username}#{user.Discriminator} {message.Timestamp.LocalDateTime}");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(message.Content))
|
||||
WriteTop(message.Content, Color.White, message);
|
||||
|
||||
foreach (DiscordAttachment attachment in message.Attachments)
|
||||
{
|
||||
WriteTop($"{attachment.Url}", Color.White, message, true, true, attachment.FileName);
|
||||
}
|
||||
|
||||
foreach (DiscordEmbed embed in message.Embeds)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(embed.Title))
|
||||
{
|
||||
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
||||
WriteTop($"{{{embed.Title}}}", Color.White, message, false);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(embed.Description))
|
||||
{
|
||||
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
||||
WriteTop($"{embed.Description}", Color.White, message, false);
|
||||
}
|
||||
|
||||
if (embed.Fields is not null)
|
||||
{
|
||||
foreach (DiscordEmbedField field in embed.Fields)
|
||||
{
|
||||
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
||||
WriteTop($"{field.Name}{Environment.NewLine}{field.Value}", Color.White, message, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine(ex);
|
||||
}
|
||||
|
||||
WriteTop(string.Empty, Color.White, message);
|
||||
DiscordDmChannel dmChannel = GlobalInformation.currentTextChannel as DiscordDmChannel;
|
||||
|
||||
if (writeInfo)
|
||||
{
|
||||
string infoString = $"\r[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{(dmChannel is null ? GlobalInformation.currentGuild?.Name : "DMs")}/{(dmChannel is null ? GlobalInformation.currentTextChannel?.Name : string.Join(", ", dmChannel.Recipients.Select(x => x.Username)))}] ==> ";
|
||||
Console.Write(infoString);
|
||||
Console.Write(InputManager.Input);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteTop(string message, Color color, DiscordMessage discordMessage, bool removeText = true, bool newLine = true, string info = null)
|
||||
{
|
||||
if (removeText)
|
||||
Console.Write('\r' + new string(' ', Console.WindowWidth) + '\r');
|
||||
|
||||
foreach (Match match in Regex.Matches(message, "<@(.*?)>"))
|
||||
{
|
||||
foreach (DiscordUser user in discordMessage.MentionedUsers)
|
||||
{
|
||||
if (user?.Mention is not null)
|
||||
{
|
||||
if (match.Value == user.Mention.Replace("!", string.Empty))
|
||||
{
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ConsoleColor.Blue}C>@{user.Username}#{user.Discriminator}\0");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ulong.TryParse(match.Value.Replace("!", string.Empty).Replace("<@", string.Empty).Replace(">", string.Empty), out ulong id))
|
||||
{
|
||||
DiscordUser discordUser = client.GetUserAsync(id).Result;
|
||||
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ConsoleColor.Blue}C>@{discordUser.Username}#{discordUser.Discriminator}\0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Match match in Regex.Matches(message, "<#(.*?)>"))
|
||||
{
|
||||
foreach (DiscordChannel channel in discordMessage.MentionedChannels)
|
||||
{
|
||||
if (channel?.Mention is not null)
|
||||
{
|
||||
if (match.Value == channel.Mention)
|
||||
{
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ConsoleColor.Blue}C>#{channel.Name}\0");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ulong.TryParse(match.Value.Replace("<#", string.Empty).Replace(">", string.Empty), out ulong id))
|
||||
{
|
||||
DiscordChannel discordChannel = client.GetChannelAsync(id).Result;
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ConsoleColor.Blue}C>#{discordChannel.Name}\0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Match match in Regex.Matches(message, @"<@&(.*?)>"))
|
||||
{
|
||||
foreach (DiscordRole role in discordMessage.MentionedRoles)
|
||||
{
|
||||
if (role?.Mention is not null)
|
||||
{
|
||||
if (match.Value == role.Mention)
|
||||
{
|
||||
DiscordColor discordColor = role.Color;
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ClosestConsoleColor(Color.FromArgb(discordColor.R, discordColor.G, discordColor.B))}C>@{role.Name}\0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Match match in Regex.Matches(message, @"((https?)\:\/\/|www.)[A-Za-z0-9\.\-\&\#\?\/]*", RegexOptions.IgnoreCase))
|
||||
{
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ConsoleColor.Blue}C>{match.Value}\0");
|
||||
}
|
||||
|
||||
foreach (string part in message.Split("\0"))
|
||||
{
|
||||
ConsoleColor consoleColor;
|
||||
string messagePart = part;
|
||||
|
||||
string stringColor = Regex.Match(messagePart, "(?<=(<C))(.*)(?=C>)").Value;
|
||||
bool succ = int.TryParse(stringColor, out int colorIndex);
|
||||
if (succ && colorIndex >= 0 && colorIndex < 16)
|
||||
{
|
||||
messagePart = messagePart.Replace($"<C{stringColor}C>", string.Empty);
|
||||
consoleColor = (ConsoleColor)colorIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
consoleColor = ClosestConsoleColor(color);
|
||||
}
|
||||
|
||||
if (consoleColor == Console.BackgroundColor || consoleColor == ConsoleColor.DarkGray)
|
||||
consoleColor = ConsoleColor.White;
|
||||
ConsoleExt.Write(messagePart, consoleColor);
|
||||
}
|
||||
|
||||
ConsoleExt.Write($" {info}", ConsoleColor.DarkGray);
|
||||
|
||||
if (newLine)
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
private ConsoleColor ClosestConsoleColor(Color targetColor)
|
||||
{
|
||||
double minDif = double.MaxValue;
|
||||
ConsoleColor closestColor = ConsoleColor.White;
|
||||
|
||||
foreach (ConsoleColor consoleColor in Enum.GetValues(typeof(ConsoleColor)))
|
||||
{
|
||||
Color color = Color.FromName(consoleColor.ToString());
|
||||
|
||||
var colorA = new Rgb
|
||||
{
|
||||
R = targetColor.R,
|
||||
G = targetColor.G,
|
||||
B = targetColor.B
|
||||
};
|
||||
|
||||
var colorB = new Rgb
|
||||
{
|
||||
R = color.R,
|
||||
G = color.G,
|
||||
B = color.B
|
||||
};
|
||||
double diff = colorA.Compare(colorB, new Cie1976Comparison());
|
||||
|
||||
if (diff < minDif)
|
||||
{
|
||||
minDif = diff;
|
||||
closestColor = consoleColor;
|
||||
}
|
||||
}
|
||||
return closestColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user