18 Commits
Author SHA1 Message Date
Stone_Red c6ba3a434d Merge pull request #1 from Stone-Red-Code/develop
Develop
2021-04-14 12:06:08 +02:00
Stone-Red-Code fc3d170e07 Added new releases 2021-04-14 12:03:24 +02:00
Stone-Red-Code ce4fb237b3 Update Program.cs 2021-04-14 11:54:10 +02:00
Stone-Red-Code f0fcbc03c5 Made more code async and added request cooldown 2021-04-14 11:53:53 +02:00
Stone_Red f53d614fca Added Limitations sections to README 2021-04-13 21:18:09 +02:00
Stone_Red 74f40593ba Added exclamation mark 2021-04-13 11:51:41 +02:00
Stone_Red 7521d9053d Update README.md 2021-04-13 11:48:58 +02:00
Stone_Red b38433badc Updated User Token link in README 2021-04-13 11:12:55 +02:00
Stone_Red 890625e6da Added description to README 2021-04-13 11:09:58 +02:00
Stone-Red-Code 433a71e838 Merge branch 'main' of https://github.com/Stone-Red-Code/DiscordCLI into main 2021-04-13 10:18:15 +02:00
Stone-Red-Code 1ddd35e5a4 Added DM support
- Added DM support
- Improved Token input
- Put the Commands class in its own file
2021-04-13 10:18:10 +02:00
Stone_Red 12271b760b Update README.md 2021-04-12 22:50:44 +02:00
Stone-Red-Code 992dcf832b Added releases for "Improved visuals and code cleanup" commit 2021-04-12 22:36:57 +02:00
Stone-Red-Code d3117795d3 Merge branch 'main' of https://github.com/Stone-Red-Code/DiscordCLI into main 2021-04-12 22:30:03 +02:00
Stone_Red 144869d5ad Create README.md 2021-04-12 22:29:28 +02:00
Stone-Red-Code bd5384f356 Improved visuals and code cleanup
-Fixed mention highlighting bug
-Improved embeds design
-Improved code structure
2021-04-12 22:28:02 +02:00
Stone_Red 9ad6a23305 Create LICENSE 2021-04-12 12:52:56 +02:00
Stone-Red-Code da2fa6f581 Remove unnecessary async keyword 2021-04-12 12:49:56 +02:00
76 changed files with 622 additions and 2383 deletions
Binary file not shown.
+187
View File
@@ -0,0 +1,187 @@
using DSharpPlus.Entities;
using DSharpPlus;
using Stone_Red_Utilities.ColorConsole;
using System.Collections.Generic;
using System.Diagnostics;
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> textChannels;
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;
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;
}
}
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).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;
}
try
{
foreach (DiscordMessage message in (textChannel.GetMessagesAsync(10).Result).Reverse())
{
await outputManager.WriteMessage(message, textChannel, GlobalInformation.currentGuild, false);
}
}
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, GlobalInformation.currentGuild, false);
}
}
catch (Exception ex)
{
ConsoleExt.WriteLine(ex, ConsoleColor.Red);
GlobalInformation.currentTextChannel = null;
}
}
protected async Task DeleteToken(string args)
{
File.Delete(Program.tokenPath);
Environment.Exit(0);
await Task.CompletedTask;
}
}
}
+48 -144
View File
@@ -1,12 +1,10 @@
using DSharpPlus;
using System;
using Stone_Red_Utilities.ColorConsole;
using System.Collections.Generic;
using System.Linq;
using Stone_Red_Utilities.ColorConsole;
using DSharpPlus.Entities;
using System.Diagnostics;
using System.IO;
using System;
using System.Timers;
using System.Threading.Tasks;
namespace DiscordCLI
{
@@ -14,9 +12,10 @@ namespace DiscordCLI
{
private readonly DiscordClient client;
private readonly Dictionary<string, (string, Action<string>)> CommandsList;
private readonly Dictionary<string, (string, Func<string, Task>)> CommandsList;
private int cooldown = 0;
public CommandsManager(DiscordClient dicordClient) : base(dicordClient)
public CommandsManager(DiscordClient dicordClient, OutputManager outputManager) : base(dicordClient, outputManager)
{
client = dicordClient;
@@ -25,42 +24,71 @@ namespace DiscordCLI
{ "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) },
{ "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 chat args:<channel name/index>", EnterChannel) },
{ "enterc", ("enter channel args:<channel name/index>", EnterChannel) },
{ "enterd", ("enter DM channel args:<channel name/index>", EnterDmChannel) },
};
Timer cooldownTimer = new Timer(1000);
cooldownTimer.Elapsed += CooldownTimer_Elapsed;
cooldownTimer.Start();
}
public bool CheckCommand(string input)
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 input)
{
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);
}
input = input.Trim().ToLower().Replace('\n', '\0');
if (string.IsNullOrWhiteSpace(input))
return false;
return (false, false);
if (input.StartsWith('<'))
if (input.StartsWith(InputManager.prefix))
{
input = input.Remove(0, 1);
}
else if (GlobalInformation.currentTextChannel != null)
{
Console.CursorTop--;
cooldown++;
Console.Write("\r" + new string(' ', Console.WindowWidth));
GlobalInformation.currentTextChannel.SendMessageAsync(input);
return false;
await GlobalInformation.currentTextChannel.SendMessageAsync(input);
return (false, false);
}
Console.WriteLine();
if (input == "exit" || input is null)
return true;
return (true, false);
string args = input.Contains(" ") ? input[input.IndexOf(" ")..].Trim() : null;
input = input.Contains(" ") ? input.Substring(0, input.IndexOf(" ")) : input;
if (input == "help")
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));
@@ -69,137 +97,13 @@ namespace DiscordCLI
}
else if (CommandsList.ContainsKey(input))
{
CommandsList[input].Item2(args);
await 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);
return (false, false);
}
}
}
+2 -3
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@@ -10,5 +10,4 @@
<PackageReference Include="DSharpPlus" Version="3.2.3" />
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.0.2" />
</ItemGroup>
</Project>
</Project>
+1 -1
View File
@@ -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\Google Drive\Programmieren\DiscordCLI\DiscordCLI\Properties\PublishProfiles\Linux-x64.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
-6
View File
@@ -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;
}
}
+65
View File
@@ -0,0 +1,65 @@
using DSharpPlus;
using System.Threading.Tasks;
using System;
using DSharpPlus.Entities;
using System.Linq;
namespace DiscordCLI
{
internal class InputManager
{
private readonly CommandsManager commandsManager;
private readonly DiscordClient client;
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()
{
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);
}
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(prefix))
Input = prefix + Input;
lastInput = new string(Input);
Input = string.Empty;
(exit, printOverride) = await commandsManager.CheckCommand(lastInput);
}
}
}
}
+199
View File
@@ -0,0 +1,199 @@
using ColorMine.ColorSpaces.Comparisons;
using ColorMine.ColorSpaces;
using DSharpPlus.Entities;
using DSharpPlus;
using Stone_Red_Utilities.ColorConsole;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System;
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, DiscordGuild guild, bool writeInfo = true)
{
try
{
if (channel.Id != GlobalInformation.currentTextChannel?.Id)
return;
DiscordUser user = message.Author;
if (GlobalInformation.currentGuild is not null)
{
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, 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)
{
ConsoleColor consoleColor = ClosestConsoleColor(color);
if (consoleColor == Console.BackgroundColor || consoleColor == ConsoleColor.DarkGray)
consoleColor = ConsoleColor.White;
if (removeText)
Console.Write('\r' + new string(' ', Console.WindowWidth) + '\r');
string[] words = message.Split(' ');
for (int i = 0; i < words.Length; i++)
{
ConsoleColor mentionColor = ConsoleColor.Black;
if (IsUri(words[i]))
{
mentionColor = ConsoleColor.DarkCyan;
}
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;
}
}
else
{
if (words[i].Contains("<@") && words[i].Contains('>'))
mentionColor = ConsoleColor.Blue;
}
}
if (!discordMessage.Channel.IsPrivate)
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;
}
}
if (!discordMessage.Channel.IsPrivate)
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 = ClosestConsoleColor(Color.FromArgb(discordColor.R, discordColor.G, discordColor.B));
}
}
ConsoleExt.Write(words[i] + " ", mentionColor == ConsoleColor.Black ? consoleColor : mentionColor);
}
ConsoleExt.Write(info, ConsoleColor.DarkGray);
if (newLine)
Console.WriteLine();
}
private bool IsUri(string input)
{
return Uri.TryCreate(input, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
}
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;
}
}
}
+19 -190
View File
@@ -1,27 +1,20 @@
using ColorMine.ColorSpaces;
using ColorMine.ColorSpaces.Comparisons;
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus;
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;
using System;
namespace DiscordCLI
{
internal class Program
{
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public static void Main() => new Program().MainAsync().GetAwaiter().GetResult();
private static DiscordClient client;
private DiscordClient client;
private InputManager inputManager;
private OutputManager outputManager;
private CommandsManager commandsManager;
private static string input = "<";
public const string tokenPath = "token.txt";
public async Task MainAsync()
@@ -33,7 +26,8 @@ namespace DiscordCLI
if (File.Exists(tokenPath))
token = File.ReadAllText(tokenPath);
while (string.IsNullOrEmpty(token))
tokenInput:
while (string.IsNullOrWhiteSpace(token))
{
Console.Write("Enter auth token: ");
token = Console.ReadLine();
@@ -46,7 +40,7 @@ namespace DiscordCLI
client = new DiscordClient(new DiscordConfiguration()
{
Token = token,
TokenType = TokenType.User
TokenType = TokenType.User,
});
client.MessageCreated += Client_MessageCreated;
@@ -58,190 +52,25 @@ namespace DiscordCLI
ConsoleExt.WriteLine(ex, ConsoleColor.Red);
if (ex.Message.Contains("Authentication failed"))
{
File.Delete(tokenPath);
token = string.Empty;
goto tokenInput;
}
return;
}
commandsManager = new CommandsManager(client);
outputManager = new OutputManager(client);
commandsManager = new CommandsManager(client, outputManager);
inputManager = new InputManager(client, commandsManager);
outputManager.InputManager = inputManager;
await ReadInput();
await Task.Delay(-1);
await inputManager.ReadInput();
}
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;
await outputManager.WriteMessage(e.Message, e.Channel, e.Guild);
}
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net5.0\publish\Linux-arm</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
</PropertyGroup>
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
@@ -6,7 +6,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net5.0\publish\</PublishDir>
<PublishDir>bin\Release\net5.0\publish\Linux-x64</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
@@ -6,7 +6,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net5.0\publish\</PublishDir>
<PublishDir>bin\Release\net5.0\publish\Windows</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<SelfContained>false</SelfContained>
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
@@ -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.
@@ -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.
@@ -1 +1 @@
dfd104565a5c51e51c96fc2a0f9e9b9515e39127
d74c436d6f045a94c6aefe230b53cf4fbca29cc5
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
3ab14035ed25e46cb2eb046c245e2f90325a2743
6b3b4647b7644f9b16fb8ec3b15a9fe904531b35
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
6843f3cabf894dfce1aaffe6c65e64e8531c52b6
94d569a53a5ac292d10f2db736ac10f01f735125
Binary file not shown.
+21
View File
@@ -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.
+57
View File
@@ -0,0 +1,57 @@
# 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 software.\
I will update the above if anything changes!
## Download
Releases: https://github.com/Stone-Red-Code/DiscordCLI/releases
## Usage
1. <a href="https://github.com/Stone-Red-Code/DiscordCLI/releases">Download</a> one of the releases
2. Execute the `DiscordCLI` file
3. Enter your <a href="https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs#how-to-get-a-user-token">User Token</a>
4. Enter one of the commands below
## Commands
### help
- lists all commands
### exit
- exits application
### logout
- deletes auth token and exits application
### 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>
## Limitations
DiscordCLI doesn't support everything the officil Discord app does.
I'm trying to add more features continuously to it but there will be always some limitations.
### 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
<br>
And maybe more.
<br>
If you find a missing feature in DiscordCLI please tell me or create a pull request and update this list.