mirror of
https://github.com/Stone-Red-Code/DiscordCLI.git
synced 2026-09-04 09:05:59 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4921d73ce0 | ||
|
|
1b123e3b3a | ||
|
|
6289f17dfa | ||
|
|
7a731cc62c | ||
|
|
5a09767dbc | ||
|
|
f900292d86 | ||
|
|
95d3c4e476 | ||
|
|
fb55a909f0 | ||
|
|
b758cdab49 | ||
|
|
e9cde21189 | ||
|
|
d518f79263 | ||
|
|
7fbfd85ff4 | ||
|
|
eba0d62fa7 | ||
|
|
a6beab85bb | ||
|
|
16cee9413b | ||
|
|
2265b044cc | ||
|
|
d9143457a7 | ||
|
|
35db02685b | ||
|
|
af721731ea | ||
|
|
652c81defa | ||
|
|
07ff5a6d4a | ||
|
|
57215db498 | ||
|
|
76845b9ae0 | ||
|
|
31b4f9cc44 | ||
|
|
524ed14b1f | ||
|
|
8d93a9de2c | ||
|
|
c6ba3a434d | ||
|
|
fc3d170e07 | ||
|
|
ce4fb237b3 | ||
|
|
f0fcbc03c5 | ||
|
|
f53d614fca | ||
|
|
74f40593ba | ||
|
|
7521d9053d | ||
|
|
b38433badc | ||
|
|
890625e6da | ||
|
|
433a71e838 | ||
|
|
1ddd35e5a4 | ||
|
|
12271b760b |
@@ -0,0 +1,32 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: bug
|
||||||
|
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/Videos**
|
||||||
|
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: enhancement
|
||||||
|
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.
|
||||||
Binary file not shown.
@@ -1,207 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
namespace DiscordCLI
|
|
||||||
{
|
|
||||||
internal class CommandsManager : Commands
|
|
||||||
{
|
|
||||||
private readonly DiscordClient client;
|
|
||||||
|
|
||||||
private readonly Dictionary<string, (string, Action<string>)> CommandsList;
|
|
||||||
|
|
||||||
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) },
|
|
||||||
{ "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;
|
|
||||||
|
|
||||||
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,60 +0,0 @@
|
|||||||
using DSharpPlus;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DiscordCLI
|
|
||||||
{
|
|
||||||
internal class InputManager
|
|
||||||
{
|
|
||||||
private readonly CommandsManager commandsManager;
|
|
||||||
private readonly DiscordClient client;
|
|
||||||
public string Input { get; private set; } = "<";
|
|
||||||
|
|
||||||
public InputManager(DiscordClient dicordClient, CommandsManager commandsMan)
|
|
||||||
{
|
|
||||||
client = dicordClient;
|
|
||||||
commandsManager = commandsMan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public 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 && 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
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)
|
|
||||||
{
|
|
||||||
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, true, true, $"{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, 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);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
//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(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = 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 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
using DSharpPlus;
|
|
||||||
using Stone_Red_Utilities.ColorConsole;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DiscordCLI
|
|
||||||
{
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
public static void Main(string[] args)
|
|
||||||
=> new Program().MainAsync().GetAwaiter().GetResult();
|
|
||||||
|
|
||||||
private DiscordClient client;
|
|
||||||
private InputManager inputManager;
|
|
||||||
private OutputManager outputManager;
|
|
||||||
private CommandsManager commandsManager;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
outputManager = new OutputManager(client);
|
|
||||||
commandsManager = new CommandsManager(client, outputManager);
|
|
||||||
inputManager = new InputManager(client, commandsManager);
|
|
||||||
outputManager.InputManager = inputManager;
|
|
||||||
|
|
||||||
await inputManager.ReadInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task Client_MessageCreated(DSharpPlus.EventArgs.MessageCreateEventArgs e)
|
|
||||||
{
|
|
||||||
await outputManager.WriteMessage(e.Message, e.Channel, e.Guild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?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-x64</PublishDir>
|
|
||||||
<PublishProtocol>FileSystem</PublishProtocol>
|
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
|
||||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
|
||||||
<SelfContained>false</SelfContained>
|
|
||||||
<PublishSingleFile>True</PublishSingleFile>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?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.
@@ -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.
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.
File diff suppressed because it is too large
Load Diff
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.
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 @@
|
|||||||
c330ac1ec415f28e8dfa881f69ac743ee03b156f
|
|
||||||
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 @@
|
|||||||
f577cd7c0c9371a4e25c13c1586e47e82f16d417
|
|
||||||
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
3e2c7be251ce3e62a6541dac29e1895e802a69f2
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
c27366fe7586ce3c313a2245960fd7296c163460
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
8dbf5d9b5cf6fb65f2290f681f68bfa7a21560cd
|
|
||||||
@@ -1,4 +1,87 @@
|
|||||||
# 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 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.exe` file (also works on Linux)
|
||||||
|
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.
@@ -0,0 +1,240 @@
|
|||||||
|
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> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => user.Username.EqualsIgnoreSpacesAndCase(userName));
|
||||||
|
|
||||||
|
if (discordUser is null)
|
||||||
|
{
|
||||||
|
discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}#{user.Discriminator}".EqualsIgnoreSpacesAndCase(userName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discordUser is null)
|
||||||
|
{
|
||||||
|
discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Nickname}".EqualsIgnoreSpacesAndCase(userName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discordUser is not null)
|
||||||
|
{
|
||||||
|
string status = discordUser.Presence?.Status.ToString();
|
||||||
|
status ??= "N/A";
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task Clear(string args)
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
string input = rawInput.Trim().ToLower().Replace('\n', '\0');
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(input))
|
||||||
|
return (false, false);
|
||||||
|
|
||||||
|
if (input.StartsWith(InputManager.prefix))
|
||||||
|
{
|
||||||
|
input = input.Remove(0, 1);
|
||||||
|
}
|
||||||
|
else if (GlobalInformation.currentTextChannel != null)
|
||||||
|
{
|
||||||
|
cooldown++;
|
||||||
|
Console.Write("\r" + new string(' ', Console.WindowWidth));
|
||||||
|
await GlobalInformation.currentTextChannel.SendMessageAsync(rawInput);
|
||||||
|
return (false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<AssemblyVersion>0.0.4.1</AssemblyVersion>
|
||||||
|
<FileVersion>0.0.4.1</FileVersion>
|
||||||
|
<Version>0.0.4.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.3" />
|
||||||
<PackageReference Include="ColorMineStandard" Version="1.0.0" />
|
<PackageReference Include="ColorMineStandard" Version="1.0.0" />
|
||||||
<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.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties\PublishProfiles\" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<_LastSelectedProfileId>C:\Users\David\Google Drive\Programmieren\DiscordCLI\DiscordCLI\Properties\PublishProfiles\Linux-x64.pubxml</_LastSelectedProfileId>
|
<_LastSelectedProfileId>C:\Users\David\Google Drive\Programmieren\DiscordCLI\src\DiscordCLI\Properties\PublishProfiles\DiscordCLI.pubxml</_LastSelectedProfileId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<Enum> GetFlags(Enum input)
|
||||||
|
{
|
||||||
|
foreach (Enum value in Enum.GetValues(input.GetType()))
|
||||||
|
if (input.HasFlag(value))
|
||||||
|
yield return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
System.Diagnostics.Debug.WriteLine(inputListIndex);
|
||||||
|
System.Diagnostics.Debug.WriteLine(previousInputs.Count - inputListIndex - 1);
|
||||||
|
if (keyInfo.KeyChar == (int)ConsoleKey.Backspace && Input.Length > 0)
|
||||||
|
{
|
||||||
|
Input = Input.Remove(Input.Length - 1);
|
||||||
|
}
|
||||||
|
else if (keyInfo.Key == ConsoleKey.UpArrow)
|
||||||
|
{
|
||||||
|
int previousLength = Input.Length;
|
||||||
|
if (previousInputs.Count > 0)
|
||||||
|
Input = previousInputs[previousInputs.Count - inputListIndex - 1];
|
||||||
|
|
||||||
|
if (inputListIndex < previousInputs.Count - 2)
|
||||||
|
inputListIndex++;
|
||||||
|
Console.CursorLeft = infoString.Length - 1;
|
||||||
|
Console.Write(Input + new string(' ', Math.Max(previousLength - Input.Length, 0)));
|
||||||
|
}
|
||||||
|
else if (keyInfo.Key == ConsoleKey.DownArrow)
|
||||||
|
{
|
||||||
|
int previousLength = Input.Length;
|
||||||
|
if (previousInputs.Count > 0)
|
||||||
|
Input = previousInputs[previousInputs.Count - inputListIndex - 1];
|
||||||
|
|
||||||
|
if (inputListIndex > 0)
|
||||||
|
inputListIndex--;
|
||||||
|
Console.CursorLeft = infoString.Length - 1;
|
||||||
|
Console.Write(Input + new string(' ', Math.Max(previousLength - Input.Length, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
if (previousInputs.Count > 10)
|
||||||
|
previousInputs.RemoveAt(0);
|
||||||
|
|
||||||
|
if (previousInputs.Count == 0 || previousInputs[previousInputs.Count - 1] != Input)
|
||||||
|
previousInputs.Add(new string(Input));
|
||||||
|
|
||||||
|
Input = prefix + Input;
|
||||||
|
}
|
||||||
|
|
||||||
|
inputListIndex = 0;
|
||||||
|
lastInput = new string(Input);
|
||||||
|
Input = string.Empty;
|
||||||
|
|
||||||
|
(exit, printOverride) = await commandsManager.CheckCommand(lastInput);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
List<string> words = message.Replace("\n", " %<newLine>%").Split(' ').ToList();
|
||||||
|
for (int i = 0; i < words.Count; i++)
|
||||||
|
{
|
||||||
|
ConsoleColor mentionColor = ConsoleColor.Black;
|
||||||
|
|
||||||
|
if (IsUri(words[i]))
|
||||||
|
{
|
||||||
|
mentionColor = ConsoleColor.DarkCyan;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (words[i].Contains("<") && words[i].Contains(">") && !(words[i].StartsWith("<") && words[i].EndsWith(">")))
|
||||||
|
{
|
||||||
|
int index1 = words[i].IndexOf("<");
|
||||||
|
int index2 = words[i].IndexOf(">");
|
||||||
|
if (index1 < index2)
|
||||||
|
{
|
||||||
|
string part1 = words[i].Substring(0, index1);
|
||||||
|
string part2 = words[i].Substring(index1, index2 - index1 + 1);
|
||||||
|
string part3 = words[i].Substring(index2 + 1, words[i].Length - index2 - 1);
|
||||||
|
|
||||||
|
words[i] = part2;
|
||||||
|
if (!string.IsNullOrEmpty(part1))
|
||||||
|
{
|
||||||
|
words.Insert(i, part1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(part3))
|
||||||
|
{
|
||||||
|
words.Insert(i + (string.IsNullOrEmpty(part1) ? 1 : 2), part3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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('>'))
|
||||||
|
{
|
||||||
|
if (ulong.TryParse(words[i].Replace("!", string.Empty).Replace("<@", string.Empty).Replace(">", string.Empty), out ulong id))
|
||||||
|
{
|
||||||
|
DiscordUser discordUser = client.GetUserAsync(id).Result;
|
||||||
|
Console.WriteLine(discordUser is null);
|
||||||
|
|
||||||
|
words[i] = words[i].Replace("<@!", "<@").Replace(discordUser.Mention, $"@{discordUser.Username}#{discordUser.Discriminator}");
|
||||||
|
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].Replace("%<newLine>%", "\n") + " ", 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
using DSharpPlus;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System;
|
||||||
|
using DSharpPlus.Exceptions;
|
||||||
|
using Stone_Red_Utilities.ConsoleExtentions;
|
||||||
|
using System.Reflection;
|
||||||
|
using AlwaysUpToDate;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace DiscordCLI
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
public const string tokenPath = "token.txt";
|
||||||
|
|
||||||
|
private DiscordClient client;
|
||||||
|
private CommandsManager commandsManager;
|
||||||
|
private InputManager inputManager;
|
||||||
|
private OutputManager outputManager;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
private Updater updater = new Updater(new TimeSpan(0), "https://raw.githubusercontent.com/Stone-Red-Code/DiscordCLI/develop/update/updateInfo.json", "./", true);
|
||||||
|
#else
|
||||||
|
private Updater updater = new Updater(new TimeSpan(0), "https://raw.githubusercontent.com/Stone-Red-Code/DiscordCLI/main/update/updateInfo.json", "./", true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public static void Main() => new Program().Setup().GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
private async Task Setup()
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||||
|
|
||||||
|
updater.UpdateAvailible += Updater_UpdateAvailible;
|
||||||
|
updater.NoUpdateAvailible += Updater_NoUpdateAvailible;
|
||||||
|
updater.ProgressChanged += Updater_ProgressChanged;
|
||||||
|
|
||||||
|
updater.Start();
|
||||||
|
await Task.Delay(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Start()
|
||||||
|
{
|
||||||
|
string token = string.Empty;
|
||||||
|
if (File.Exists(tokenPath))
|
||||||
|
token = File.ReadAllText(tokenPath);
|
||||||
|
|
||||||
|
tokenInput:
|
||||||
|
while (string.IsNullOrWhiteSpace(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();
|
||||||
|
ConsoleExt.WriteLine("Welcome to DiscordCLI", ConsoleColor.Green);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ConsoleExt.WriteLine(ex.Message, ConsoleColor.Red);
|
||||||
|
|
||||||
|
if (ex.InnerException is UnauthorizedException)
|
||||||
|
{
|
||||||
|
File.Delete(tokenPath);
|
||||||
|
token = string.Empty;
|
||||||
|
goto tokenInput;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
outputManager = new OutputManager(client);
|
||||||
|
commandsManager = new CommandsManager(client, outputManager);
|
||||||
|
inputManager = new InputManager(client, commandsManager);
|
||||||
|
outputManager.InputManager = inputManager;
|
||||||
|
|
||||||
|
await inputManager.ReadInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void Updater_NoUpdateAvailible()
|
||||||
|
{
|
||||||
|
await Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
ConsoleExt.WriteLine($"Downloading Update: {progressPercentage}% {totalBytesDownloaded}/{totalFileSize}", ConsoleColor.Yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Updater_UpdateAvailible(string version, string additionalInformation)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"New version avalible! {version}");
|
||||||
|
updater.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Client_MessageCreated(DSharpPlus.EventArgs.MessageCreateEventArgs e)
|
||||||
|
{
|
||||||
|
await outputManager.WriteMessage(e.Message, e.Channel, e.Guild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-3
@@ -6,9 +6,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration>Release</Configuration>
|
<Configuration>Release</Configuration>
|
||||||
<Platform>Any CPU</Platform>
|
<Platform>Any CPU</Platform>
|
||||||
<PublishDir>bin\Release\net5.0\publish\Windows</PublishDir>
|
<PublishDir>bin\Release\net5.0\publish\DiscordCLI</PublishDir>
|
||||||
<PublishProtocol>FileSystem</PublishProtocol>
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
|
||||||
<SelfContained>false</SelfContained>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?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>
|
||||||
|
<History>True|2021-05-31T17:23:33.4240354Z;True|2021-05-31T19:20:39.6710032+02:00;True|2021-05-29T18:25:28.6698849+02:00;True|2021-05-29T17:53:55.7039453+02:00;True|2021-05-29T17:07:22.9610987+02:00;True|2021-05-29T16:21:45.0240481+02:00;</History>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
+3
@@ -3,4 +3,7 @@
|
|||||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
-->
|
-->
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<History>True|2021-05-27T05:49:47.3666888Z;True|2021-05-27T07:46:50.5745814+02:00;</History>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Binary file not shown.
Binary file not shown.
+44
-10
@@ -6,16 +6,28 @@
|
|||||||
"compilationOptions": {},
|
"compilationOptions": {},
|
||||||
"targets": {
|
"targets": {
|
||||||
".NETCoreApp,Version=v5.0": {
|
".NETCoreApp,Version=v5.0": {
|
||||||
"DiscordCLI/1.0.0": {
|
"DiscordCLI/0.0.4.1": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"AlwaysUpToDate": "1.0.0.3",
|
||||||
"ColorMineStandard": "1.0.0",
|
"ColorMineStandard": "1.0.0",
|
||||||
"DSharpPlus": "3.2.3",
|
"DSharpPlus": "3.2.3",
|
||||||
"Stone_Red-C-Sharp-Utilities": "1.0.0.2"
|
"Stone_Red-C-Sharp-Utilities": "1.0.2.1"
|
||||||
},
|
},
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"DiscordCLI.dll": {}
|
"DiscordCLI.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"AlwaysUpToDate/1.0.0.3": {
|
||||||
|
"dependencies": {
|
||||||
|
"System.Text.Json": "5.0.2"
|
||||||
|
},
|
||||||
|
"runtime": {
|
||||||
|
"lib/netstandard2.1/AlwaysUpToDate.dll": {
|
||||||
|
"assemblyVersion": "1.0.0.3",
|
||||||
|
"fileVersion": "1.0.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"ColorMineStandard/1.0.0": {
|
"ColorMineStandard/1.0.0": {
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"lib/netstandard2.0/ColorMineStandard.dll": {
|
"lib/netstandard2.0/ColorMineStandard.dll": {
|
||||||
@@ -186,11 +198,11 @@
|
|||||||
"runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.2": {},
|
"runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.2": {},
|
||||||
"runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.2": {},
|
"runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.2": {},
|
||||||
"runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.2": {},
|
"runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl/4.3.2": {},
|
||||||
"Stone_Red-C-Sharp-Utilities/1.0.0.2": {
|
"Stone_Red-C-Sharp-Utilities/1.0.2.1": {
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll": {
|
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll": {
|
||||||
"assemblyVersion": "1.0.0.2",
|
"assemblyVersion": "1.0.2.1",
|
||||||
"fileVersion": "1.0.0.2"
|
"fileVersion": "1.0.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -903,6 +915,14 @@
|
|||||||
"System.Text.Encoding": "4.3.0"
|
"System.Text.Encoding": "4.3.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"System.Text.Json/5.0.2": {
|
||||||
|
"runtime": {
|
||||||
|
"lib/netcoreapp3.0/System.Text.Json.dll": {
|
||||||
|
"assemblyVersion": "5.0.0.0",
|
||||||
|
"fileVersion": "5.0.521.16609"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"System.Text.RegularExpressions/4.3.0": {
|
"System.Text.RegularExpressions/4.3.0": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"System.Runtime": "4.3.0"
|
"System.Runtime": "4.3.0"
|
||||||
@@ -993,11 +1013,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"libraries": {
|
"libraries": {
|
||||||
"DiscordCLI/1.0.0": {
|
"DiscordCLI/0.0.4.1": {
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"serviceable": false,
|
"serviceable": false,
|
||||||
"sha512": ""
|
"sha512": ""
|
||||||
},
|
},
|
||||||
|
"AlwaysUpToDate/1.0.0.3": {
|
||||||
|
"type": "package",
|
||||||
|
"serviceable": true,
|
||||||
|
"sha512": "sha512-vJCFkNoEa4cnf4Bck20k0DaPsLk1kgP8uH2B2dbOSpXv+kzVzLAaUsPWO1cm3Yo8bs3Z8JwG3J4xz4AcRzh3yg==",
|
||||||
|
"path": "alwaysuptodate/1.0.0.3",
|
||||||
|
"hashPath": "alwaysuptodate.1.0.0.3.nupkg.sha512"
|
||||||
|
},
|
||||||
"ColorMineStandard/1.0.0": {
|
"ColorMineStandard/1.0.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"serviceable": true,
|
"serviceable": true,
|
||||||
@@ -1173,12 +1200,12 @@
|
|||||||
"path": "runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl/4.3.2",
|
"path": "runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl/4.3.2",
|
||||||
"hashPath": "runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512"
|
"hashPath": "runtime.ubuntu.16.10-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512"
|
||||||
},
|
},
|
||||||
"Stone_Red-C-Sharp-Utilities/1.0.0.2": {
|
"Stone_Red-C-Sharp-Utilities/1.0.2.1": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"serviceable": true,
|
"serviceable": true,
|
||||||
"sha512": "sha512-/oH1XweI6G2VjeXuutq3XhHAPiSpotfPnsRMK0n8BXFOqG85y0AXQGaKiEdhCZZOpLHFrNY8rtLepMgLJrsY9w==",
|
"sha512": "sha512-QzwH0QvsDiBvCJTFroZBhN/pMEIiz0C8TNkQci+pxCbnjfTtVkxAYsgmlshCl5oHFJh7VYDLcGAULcMBARSb+w==",
|
||||||
"path": "stone_red-c-sharp-utilities/1.0.0.2",
|
"path": "stone_red-c-sharp-utilities/1.0.2.1",
|
||||||
"hashPath": "stone_red-c-sharp-utilities.1.0.0.2.nupkg.sha512"
|
"hashPath": "stone_red-c-sharp-utilities.1.0.2.1.nupkg.sha512"
|
||||||
},
|
},
|
||||||
"System.AppContext/4.3.0": {
|
"System.AppContext/4.3.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
@@ -1614,6 +1641,13 @@
|
|||||||
"path": "system.text.encoding.extensions/4.3.0",
|
"path": "system.text.encoding.extensions/4.3.0",
|
||||||
"hashPath": "system.text.encoding.extensions.4.3.0.nupkg.sha512"
|
"hashPath": "system.text.encoding.extensions.4.3.0.nupkg.sha512"
|
||||||
},
|
},
|
||||||
|
"System.Text.Json/5.0.2": {
|
||||||
|
"type": "package",
|
||||||
|
"serviceable": true,
|
||||||
|
"sha512": "sha512-I47dVIGiV6SfAyppphxqupertT/5oZkYLDCX6vC3HpOI4ZLjyoKAreUoem2ie6G0RbRuFrlqz/PcTQjfb2DOfQ==",
|
||||||
|
"path": "system.text.json/5.0.2",
|
||||||
|
"hashPath": "system.text.json.5.0.2.nupkg.sha512"
|
||||||
|
},
|
||||||
"System.Text.RegularExpressions/4.3.0": {
|
"System.Text.RegularExpressions/4.3.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"serviceable": true,
|
"serviceable": true,
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
-1
@@ -3,7 +3,8 @@
|
|||||||
"additionalProbingPaths": [
|
"additionalProbingPaths": [
|
||||||
"C:\\Users\\David\\.dotnet\\store\\|arch|\\|tfm|",
|
"C:\\Users\\David\\.dotnet\\store\\|arch|\\|tfm|",
|
||||||
"C:\\Users\\David\\.nuget\\packages",
|
"C:\\Users\\David\\.nuget\\packages",
|
||||||
"C:\\Microsoft\\Xamarin\\NuGet"
|
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
|
||||||
|
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user