mirror of
https://github.com/Stone-Red-Code/DiscordCLI.git
synced 2026-09-04 09:05:59 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6ba3a434d | ||
|
|
fc3d170e07 | ||
|
|
ce4fb237b3 | ||
|
|
f0fcbc03c5 | ||
|
|
f53d614fca | ||
|
|
74f40593ba | ||
|
|
7521d9053d | ||
|
|
b38433badc | ||
|
|
890625e6da | ||
|
|
433a71e838 | ||
|
|
1ddd35e5a4 | ||
|
|
12271b760b |
Binary file not shown.
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
-144
@@ -1,11 +1,10 @@
|
|||||||
using DSharpPlus.Entities;
|
using DSharpPlus;
|
||||||
using DSharpPlus;
|
|
||||||
using Stone_Red_Utilities.ColorConsole;
|
using Stone_Red_Utilities.ColorConsole;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Timers;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace DiscordCLI
|
namespace DiscordCLI
|
||||||
{
|
{
|
||||||
@@ -13,7 +12,8 @@ namespace DiscordCLI
|
|||||||
{
|
{
|
||||||
private readonly DiscordClient client;
|
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, OutputManager outputManager) : base(dicordClient, outputManager)
|
public CommandsManager(DiscordClient dicordClient, OutputManager outputManager) : base(dicordClient, outputManager)
|
||||||
{
|
{
|
||||||
@@ -24,42 +24,71 @@ namespace DiscordCLI
|
|||||||
{ "exit", ("exits application", null) },
|
{ "exit", ("exits application", null) },
|
||||||
{ "logout", ("deletes auth token and exits application", DeleteToken) },
|
{ "logout", ("deletes auth token and exits application", DeleteToken) },
|
||||||
{ "guilds", ("lists all guilds you are in", ListGuilds) },
|
{ "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) },
|
{ "channels", ("lists all channels of guild args:<guild name/index>", ListGuildChannels) },
|
||||||
{ "enterg", ("enter 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');
|
input = input.Trim().ToLower().Replace('\n', '\0');
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(input))
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
return false;
|
return (false, false);
|
||||||
|
|
||||||
if (input.StartsWith('<'))
|
if (input.StartsWith(InputManager.prefix))
|
||||||
{
|
{
|
||||||
input = input.Remove(0, 1);
|
input = input.Remove(0, 1);
|
||||||
}
|
}
|
||||||
else if (GlobalInformation.currentTextChannel != null)
|
else if (GlobalInformation.currentTextChannel != null)
|
||||||
{
|
{
|
||||||
Console.CursorTop--;
|
cooldown++;
|
||||||
Console.Write("\r" + new string(' ', Console.WindowWidth));
|
Console.Write("\r" + new string(' ', Console.WindowWidth));
|
||||||
GlobalInformation.currentTextChannel.SendMessageAsync(input);
|
await GlobalInformation.currentTextChannel.SendMessageAsync(input);
|
||||||
return false;
|
return (false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
if (input == "exit" || input is null)
|
if (input == "exit" || input is null)
|
||||||
return true;
|
return (true, false);
|
||||||
|
|
||||||
string args = input.Contains(" ") ? input[input.IndexOf(" ")..].Trim() : null;
|
string args = input.Contains(" ") ? input[input.IndexOf(" ")..].Trim() : null;
|
||||||
input = input.Contains(" ") ? input.Substring(0, input.IndexOf(" ")) : input;
|
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++)
|
for (int i = 0; i < CommandsList.Count; i++)
|
||||||
{
|
{
|
||||||
Console.Write($"{i + 1}. {CommandsList.Keys.ElementAt(i)}".PadRight(15));
|
Console.Write($"{i + 1}. {CommandsList.Keys.ElementAt(i)}".PadRight(15));
|
||||||
@@ -68,140 +97,13 @@ namespace DiscordCLI
|
|||||||
}
|
}
|
||||||
else if (CommandsList.ContainsKey(input))
|
else if (CommandsList.ContainsKey(input))
|
||||||
{
|
{
|
||||||
CommandsList[input].Item2(args);
|
await CommandsList[input].Item2(args);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConsoleExt.WriteLine("Command does not exist!", ConsoleColor.Red);
|
ConsoleExt.WriteLine("Command does not exist!", ConsoleColor.Red);
|
||||||
}
|
}
|
||||||
return false;
|
return (false, false);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class Commands
|
|
||||||
{
|
|
||||||
private IReadOnlyDictionary<ulong, DiscordGuild> socketGuildsCache;
|
|
||||||
|
|
||||||
private readonly DiscordClient client;
|
|
||||||
|
|
||||||
private readonly OutputManager outputManager;
|
|
||||||
|
|
||||||
public Commands(DiscordClient dicordClient, OutputManager outputMan)
|
|
||||||
{
|
|
||||||
client = dicordClient;
|
|
||||||
outputManager = outputMan;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 outputManager.WriteMessage(message, textChannel, GlobalInformation.currentGuild);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Debug.WriteLine(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void DeleteToken(string args)
|
|
||||||
{
|
|
||||||
File.Delete(Program.tokenPath);
|
|
||||||
Environment.Exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
@@ -10,5 +10,4 @@
|
|||||||
<PackageReference Include="DSharpPlus" Version="3.2.3" />
|
<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.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
+34
-29
@@ -1,6 +1,8 @@
|
|||||||
using DSharpPlus;
|
using DSharpPlus;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
using System;
|
||||||
|
using DSharpPlus.Entities;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace DiscordCLI
|
namespace DiscordCLI
|
||||||
{
|
{
|
||||||
@@ -8,7 +10,8 @@ namespace DiscordCLI
|
|||||||
{
|
{
|
||||||
private readonly CommandsManager commandsManager;
|
private readonly CommandsManager commandsManager;
|
||||||
private readonly DiscordClient client;
|
private readonly DiscordClient client;
|
||||||
public string Input { get; private set; } = "<";
|
public const string prefix = ">";
|
||||||
|
public string Input { get; private set; } = string.Empty;
|
||||||
|
|
||||||
public InputManager(DiscordClient dicordClient, CommandsManager commandsMan)
|
public InputManager(DiscordClient dicordClient, CommandsManager commandsMan)
|
||||||
{
|
{
|
||||||
@@ -18,43 +21,45 @@ namespace DiscordCLI
|
|||||||
|
|
||||||
public async Task ReadInput()
|
public async Task ReadInput()
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
bool exit = false;
|
||||||
|
bool printOverride = false;
|
||||||
|
string lastInput = prefix;
|
||||||
|
while (!exit)
|
||||||
{
|
{
|
||||||
bool exit = false;
|
DiscordDmChannel dmChannel = GlobalInformation.currentTextChannel as DiscordDmChannel;
|
||||||
while (!exit)
|
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
|
||||||
{
|
{
|
||||||
string infoString = $"\r[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{GlobalInformation.currentGuild?.Name}/{GlobalInformation.currentTextChannel?.Name}] ==> ";
|
keyInfo = Console.ReadKey(true);
|
||||||
if (Input.StartsWith('<'))
|
if (!char.IsControl(keyInfo.KeyChar))
|
||||||
Console.Write(Environment.NewLine + infoString);
|
Input += keyInfo.KeyChar.ToString();
|
||||||
|
|
||||||
Input = string.Empty;
|
if (keyInfo.Key == ConsoleKey.Backspace && Input.Length > 0)
|
||||||
|
|
||||||
ConsoleKeyInfo keyInfo;
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
keyInfo = Console.ReadKey(true);
|
Input = Input.Remove(Input.Length - 1);
|
||||||
if (!char.IsControl(keyInfo.KeyChar))
|
}
|
||||||
Input += keyInfo.KeyChar.ToString();
|
|
||||||
|
|
||||||
if (keyInfo.Key == ConsoleKey.Backspace && Input.Length > 0)
|
Console.Write(keyInfo.KeyChar);
|
||||||
{
|
if (keyInfo.Key == ConsoleKey.Backspace)
|
||||||
Input = Input.Remove(Input.Length - 1);
|
Console.Write(" ");
|
||||||
}
|
|
||||||
|
|
||||||
Console.Write(keyInfo.KeyChar);
|
Console.CursorLeft = infoString.Length + Input.Length - 1;
|
||||||
if (keyInfo.Key == ConsoleKey.Backspace)
|
} while (keyInfo.Key != ConsoleKey.Enter);
|
||||||
Console.Write(" ");
|
|
||||||
|
|
||||||
Console.CursorLeft = infoString.Length + Input.Length - 1;
|
if (GlobalInformation.currentTextChannel == null && !Input.StartsWith(prefix))
|
||||||
} while (keyInfo.Key != ConsoleKey.Enter);
|
Input = prefix + Input;
|
||||||
|
|
||||||
if (GlobalInformation.currentTextChannel == null && !Input.StartsWith('<'))
|
lastInput = new string(Input);
|
||||||
Input = "<" + Input;
|
Input = string.Empty;
|
||||||
|
|
||||||
exit = commandsManager.CheckCommand(Input);
|
(exit, printOverride) = await commandsManager.CheckCommand(lastInput);
|
||||||
}
|
}
|
||||||
Environment.Exit(0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+51
-35
@@ -21,7 +21,7 @@ namespace DiscordCLI
|
|||||||
client = discordClient;
|
client = discordClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WriteMessage(DiscordMessage message, DiscordChannel channel, DiscordGuild guild)
|
public async Task WriteMessage(DiscordMessage message, DiscordChannel channel, DiscordGuild guild, bool writeInfo = true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -29,12 +29,19 @@ namespace DiscordCLI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
DiscordUser user = message.Author;
|
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);
|
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}");
|
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))
|
if (!string.IsNullOrWhiteSpace(message.Content))
|
||||||
WriteTop(message.Content, Color.White, message);
|
WriteTop(message.Content, Color.White, message);
|
||||||
@@ -57,12 +64,13 @@ namespace DiscordCLI
|
|||||||
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
||||||
WriteTop($"{embed.Description}", Color.White, message, false);
|
WriteTop($"{embed.Description}", Color.White, message, false);
|
||||||
}
|
}
|
||||||
foreach (DiscordEmbedField field in embed.Fields)
|
|
||||||
{
|
if (embed.Fields is not null)
|
||||||
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
foreach (DiscordEmbedField field in embed.Fields)
|
||||||
WriteTop($"{field.Name}{Environment.NewLine}{field.Value}", Color.White, message, false);
|
{
|
||||||
}
|
WriteTop(">>> ", Color.FromArgb(embed.Color.Value), message, true, false);
|
||||||
//WriteTop($"{string.Join(Environment.NewLine, embed.Fields.Select(x => $"> {x.Name}{Environment.NewLine}{x.Value}"))}", Color.White, message);
|
WriteTop($"{field.Name}{Environment.NewLine}{field.Value}", Color.White, message, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -71,8 +79,14 @@ namespace DiscordCLI
|
|||||||
}
|
}
|
||||||
|
|
||||||
WriteTop(string.Empty, Color.White, message);
|
WriteTop(string.Empty, Color.White, message);
|
||||||
Console.Write($"[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{GlobalInformation.currentGuild?.Name}/{GlobalInformation.currentTextChannel?.Name}] ==> ");
|
DiscordDmChannel dmChannel = GlobalInformation.currentTextChannel as DiscordDmChannel;
|
||||||
Console.Write(InputManager.Input);
|
|
||||||
|
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)
|
private void WriteTop(string message, Color color, DiscordMessage discordMessage, bool removeText = true, bool newLine = true, string info = null)
|
||||||
@@ -112,26 +126,28 @@ namespace DiscordCLI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DiscordChannel channel in discordMessage.MentionedChannels)
|
if (!discordMessage.Channel.IsPrivate)
|
||||||
{
|
foreach (DiscordChannel channel in discordMessage.MentionedChannels)
|
||||||
if (channel?.Mention is not null)
|
{
|
||||||
if (words[i].Contains(channel.Mention))
|
if (channel?.Mention is not null)
|
||||||
{
|
if (words[i].Contains(channel.Mention))
|
||||||
words[i] = words[i].Replace(channel.Mention, $"#{channel.Name}");
|
{
|
||||||
mentionColor = ConsoleColor.Blue;
|
words[i] = words[i].Replace(channel.Mention, $"#{channel.Name}");
|
||||||
}
|
mentionColor = ConsoleColor.Blue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (DiscordRole role in discordMessage.MentionedRoles)
|
if (!discordMessage.Channel.IsPrivate)
|
||||||
{
|
foreach (DiscordRole role in discordMessage.MentionedRoles)
|
||||||
if (role?.Mention is not null)
|
{
|
||||||
if (words[i].Contains(role.Mention))
|
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;
|
words[i] = words[i].Replace(role.Mention, $"@{role.Name}");
|
||||||
mentionColor = ClosestConsoleColor(Color.FromArgb(discordColor.R, discordColor.G, discordColor.B));
|
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(words[i] + " ", mentionColor == ConsoleColor.Black ? consoleColor : mentionColor);
|
||||||
}
|
}
|
||||||
@@ -150,7 +166,7 @@ namespace DiscordCLI
|
|||||||
private ConsoleColor ClosestConsoleColor(Color targetColor)
|
private ConsoleColor ClosestConsoleColor(Color targetColor)
|
||||||
{
|
{
|
||||||
double minDif = double.MaxValue;
|
double minDif = double.MaxValue;
|
||||||
ConsoleColor bestColor = ConsoleColor.White;
|
ConsoleColor closestColor = ConsoleColor.White;
|
||||||
|
|
||||||
foreach (ConsoleColor consoleColor in Enum.GetValues(typeof(ConsoleColor)))
|
foreach (ConsoleColor consoleColor in Enum.GetValues(typeof(ConsoleColor)))
|
||||||
{
|
{
|
||||||
@@ -174,10 +190,10 @@ namespace DiscordCLI
|
|||||||
if (diff < minDif)
|
if (diff < minDif)
|
||||||
{
|
{
|
||||||
minDif = diff;
|
minDif = diff;
|
||||||
bestColor = consoleColor;
|
closestColor = consoleColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bestColor;
|
return closestColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,7 @@ namespace DiscordCLI
|
|||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main() => new Program().MainAsync().GetAwaiter().GetResult();
|
||||||
=> new Program().MainAsync().GetAwaiter().GetResult();
|
|
||||||
|
|
||||||
private DiscordClient client;
|
private DiscordClient client;
|
||||||
private InputManager inputManager;
|
private InputManager inputManager;
|
||||||
@@ -27,7 +26,8 @@ namespace DiscordCLI
|
|||||||
if (File.Exists(tokenPath))
|
if (File.Exists(tokenPath))
|
||||||
token = File.ReadAllText(tokenPath);
|
token = File.ReadAllText(tokenPath);
|
||||||
|
|
||||||
while (string.IsNullOrEmpty(token))
|
tokenInput:
|
||||||
|
while (string.IsNullOrWhiteSpace(token))
|
||||||
{
|
{
|
||||||
Console.Write("Enter auth token: ");
|
Console.Write("Enter auth token: ");
|
||||||
token = Console.ReadLine();
|
token = Console.ReadLine();
|
||||||
@@ -52,7 +52,11 @@ namespace DiscordCLI
|
|||||||
ConsoleExt.WriteLine(ex, ConsoleColor.Red);
|
ConsoleExt.WriteLine(ex, ConsoleColor.Red);
|
||||||
|
|
||||||
if (ex.Message.Contains("Authentication failed"))
|
if (ex.Message.Contains("Authentication failed"))
|
||||||
|
{
|
||||||
File.Delete(tokenPath);
|
File.Delete(tokenPath);
|
||||||
|
token = string.Empty;
|
||||||
|
goto tokenInput;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
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.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
c330ac1ec415f28e8dfa881f69ac743ee03b156f
|
d74c436d6f045a94c6aefe230b53cf4fbca29cc5
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
f577cd7c0c9371a4e25c13c1586e47e82f16d417
|
6b3b4647b7644f9b16fb8ec3b15a9fe904531b35
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
|||||||
c27366fe7586ce3c313a2245960fd7296c163460
|
94d569a53a5ac292d10f2db736ac10f01f735125
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,57 @@
|
|||||||
# DiscordCLI
|
# DiscordCLI
|
||||||
> Use Discord in the terminal
|
> Use Discord in the terminal
|
||||||
|
|
||||||
# README coming soon
|
## 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user