44 Commits
Author SHA1 Message Date
Stone_Red 4921d73ce0 Update updateInfo.json 2021-05-31 19:32:37 +02:00
Stone-Red-Code 1b123e3b3a Fixed #3 and some other bugs
- Fixed command history adding random newlines
- Fixed #3 (hopefully)
2021-05-31 19:27:33 +02:00
Stone_Red 6289f17dfa Update README.md 2021-05-29 18:38:26 +02:00
Stone-Red-Code 7a731cc62c Merge branch 'develop' into main 2021-05-29 18:29:59 +02:00
Stone-Red-Code 5a09767dbc Merge branch 'develop' of https://github.com/Stone-Red-Code/DiscordCLI into develop 2021-05-29 18:28:49 +02:00
Stone-Red-Code f900292d86 Added auto update 2021-05-29 18:27:50 +02:00
Stone_Red 95d3c4e476 Add files via upload 2021-05-29 18:19:12 +02:00
Stone_Red fb55a909f0 Add files via upload 2021-05-29 18:16:05 +02:00
Stone_Red b758cdab49 Update updateInfo.json 2021-05-29 18:04:45 +02:00
Stone_Red e9cde21189 Update updateInfo.json 2021-05-29 17:58:34 +02:00
Stone_Red d518f79263 Add files via upload 2021-05-29 17:54:57 +02:00
Stone-Red-Code 7fbfd85ff4 Auto update [Test 1] 2021-05-29 17:45:59 +02:00
Stone_Red eba0d62fa7 Update issue templates 2021-05-29 13:19:19 +02:00
Stone_Red a6beab85bb Update issue templates 2021-05-28 20:19:32 +02:00
Stone-Red-Code 16cee9413b Merge branch 'main' into develop 2021-05-28 19:57:31 +02:00
Stone-Red-Code 2265b044cc Added commands history
- Added commands history
- Added "clear" command
- Small code improvements
2021-05-28 19:54:42 +02:00
Stone-Red-Code d9143457a7 Updated file structure 2021-05-28 18:00:22 +02:00
Stone_Red 35db02685b Update issue templates 2021-05-28 17:52:23 +02:00
Stone-Red-Code af721731ea Better mention syntax highlighting and more
- Better mention syntax highlighting
- Added "userinfo" command
2021-05-28 16:47:56 +02:00
Stone_Red 652c81defa Update README.md 2021-05-27 18:13:05 +02:00
Stone-Red-Code 07ff5a6d4a Replaced .rar files through .zip files 2021-05-27 08:02:12 +02:00
Stone-Red-Code 57215db498 #2 DiscordCLI not sending capital letters. 2021-05-27 07:53:54 +02:00
Stone_Red 76845b9ae0 Update README.md 2021-05-01 20:41:58 +02:00
Stone_Red 31b4f9cc44 Update README.md 2021-04-16 12:00:23 +02:00
Stone_Red 524ed14b1f Update README.md 2021-04-14 14:36:49 +02:00
Stone_Red 8d93a9de2c Update README.md 2021-04-14 14:36:20 +02:00
Stone_Red c6ba3a434d Merge pull request #1 from Stone-Red-Code/develop
Develop
2021-04-14 12:06:08 +02:00
Stone-Red-Code fc3d170e07 Added new releases 2021-04-14 12:03:24 +02:00
Stone-Red-Code ce4fb237b3 Update Program.cs 2021-04-14 11:54:10 +02:00
Stone-Red-Code f0fcbc03c5 Made more code async and added request cooldown 2021-04-14 11:53:53 +02:00
Stone_Red f53d614fca Added Limitations sections to README 2021-04-13 21:18:09 +02:00
Stone_Red 74f40593ba Added exclamation mark 2021-04-13 11:51:41 +02:00
Stone_Red 7521d9053d Update README.md 2021-04-13 11:48:58 +02:00
Stone_Red b38433badc Updated User Token link in README 2021-04-13 11:12:55 +02:00
Stone_Red 890625e6da Added description to README 2021-04-13 11:09:58 +02:00
Stone-Red-Code 433a71e838 Merge branch 'main' of https://github.com/Stone-Red-Code/DiscordCLI into main 2021-04-13 10:18:15 +02:00
Stone-Red-Code 1ddd35e5a4 Added DM support
- Added DM support
- Improved Token input
- Put the Commands class in its own file
2021-04-13 10:18:10 +02:00
Stone_Red 12271b760b Update README.md 2021-04-12 22:50:44 +02:00
Stone-Red-Code 992dcf832b Added releases for "Improved visuals and code cleanup" commit 2021-04-12 22:36:57 +02:00
Stone-Red-Code d3117795d3 Merge branch 'main' of https://github.com/Stone-Red-Code/DiscordCLI into main 2021-04-12 22:30:03 +02:00
Stone_Red 144869d5ad Create README.md 2021-04-12 22:29:28 +02:00
Stone-Red-Code bd5384f356 Improved visuals and code cleanup
-Fixed mention highlighting bug
-Improved embeds design
-Improved code structure
2021-04-12 22:28:02 +02:00
Stone_Red 9ad6a23305 Create LICENSE 2021-04-12 12:52:56 +02:00
Stone-Red-Code da2fa6f581 Remove unnecessary async keyword 2021-04-12 12:49:56 +02:00
234 changed files with 1266 additions and 8191 deletions
+32
View File
@@ -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.
+20
View File
@@ -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.
-205
View File
@@ -1,205 +0,0 @@
using DSharpPlus;
using System;
using System.Collections.Generic;
using System.Linq;
using Stone_Red_Utilities.ColorConsole;
using DSharpPlus.Entities;
using System.Diagnostics;
using System.IO;
namespace DiscordCLI
{
internal class CommandsManager : Commands
{
private readonly DiscordClient client;
private readonly Dictionary<string, (string, Action<string>)> CommandsList;
public CommandsManager(DiscordClient dicordClient) : base(dicordClient)
{
client = dicordClient;
CommandsList = new()
{
{ "exit", ("exits application", null) },
{ "logout", ("deletes auth token and exits application", DeleteToken) },
{ "guilds", ("lists all guilds you are in", ListGuilds) },
{ "dms", ("lists all private channels (Not implemented yet)", ListDms) },
{ "channels", ("lists all channels of guild args:<guild name/index>", ListGuildChannels) },
{ "enterg", ("enter guild args:<guild name/index>", ListGuildChannels) },
{ "enterc", ("enter chat args:<channel name/index>", EnterChannel) },
};
}
public bool CheckCommand(string input)
{
input = input.Trim().ToLower().Replace('\n', '\0');
if (string.IsNullOrWhiteSpace(input))
return false;
if (input.StartsWith('<'))
{
input = input.Remove(0, 1);
}
else if (GlobalInformation.currentTextChannel != null)
{
Console.CursorTop--;
Console.Write("\r" + new string(' ', Console.WindowWidth));
GlobalInformation.currentTextChannel.SendMessageAsync(input);
return false;
}
Console.WriteLine();
if (input == "exit" || input is null)
return true;
string args = input.Contains(" ") ? input[input.IndexOf(" ")..].Trim() : null;
input = input.Contains(" ") ? input.Substring(0, input.IndexOf(" ")) : input;
if (input == "help")
{
for (int i = 0; i < CommandsList.Count; i++)
{
Console.Write($"{i + 1}. {CommandsList.Keys.ElementAt(i)}".PadRight(15));
Console.WriteLine(CommandsList.Values.ElementAt(i).Item1);
}
}
else if (CommandsList.ContainsKey(input))
{
CommandsList[input].Item2(args);
}
else
{
ConsoleExt.WriteLine("Command does not exist!", ConsoleColor.Red);
}
return false;
}
}
internal class Commands
{
private IReadOnlyDictionary<ulong, DiscordGuild> socketGuildsCache;
private readonly DiscordClient client;
public Commands(DiscordClient dicordClient)
{
client = dicordClient;
}
protected void ListGuilds(string args)
{
socketGuildsCache ??= client.Guilds;
int index = 1;
foreach (DiscordGuild guild in socketGuildsCache.Values)
{
Console.WriteLine($"{index}. {guild.Name}");
index++;
}
}
protected void ListDms(string args)
{
throw new NotImplementedException();
}
protected void ListGuildChannels(string args)
{
IReadOnlyCollection<DiscordChannel> textChannels;
DiscordGuild guild;
if (args != null)
{
if (int.TryParse(args, out int ind))
{
guild = socketGuildsCache?.Values.ElementAtOrDefault(ind - 1);
}
else
{
guild = socketGuildsCache?.FirstOrDefault(x => x.Value.Name == args).Value;
}
GlobalInformation.currentTextChannel = null;
}
else
{
guild = GlobalInformation.currentGuild;
}
if (guild is null)
{
ConsoleExt.WriteLine("Guild not found!", ConsoleColor.Red);
GlobalInformation.currentTextChannel = null;
return;
}
GlobalInformation.currentGuild = guild;
textChannels = guild.Channels;
int index = 1;
foreach (DiscordChannel channel in textChannels)
{
switch (channel.Type)
{
case ChannelType.Category:
//Console.WriteLine($"[{channel.Name}]");
break;
case ChannelType.Text:
Console.WriteLine($" {index}. {channel.Name}");
index++;
break;
}
}
}
protected async void EnterChannel(string args)
{
DiscordChannel textChannel;
if (GlobalInformation.currentGuild is null)
{
ConsoleExt.WriteLine("You are not in a guild!", ConsoleColor.Red);
return;
}
if (int.TryParse(args, out int ind))
{
textChannel = GlobalInformation.currentGuild?.Channels.Where(x => x.Type == ChannelType.Text).ElementAtOrDefault(ind - 1);
}
else
{
textChannel = GlobalInformation.currentGuild?.Channels.Where(x => x.Type == ChannelType.Text).FirstOrDefault(x => x.Name == args);
}
GlobalInformation.currentTextChannel = textChannel;
if (textChannel is null)
{
ConsoleExt.WriteLine("Channel not found!", ConsoleColor.Red);
return;
}
foreach (DiscordMessage message in (await textChannel.GetMessagesAsync(10)).Reverse())
{
try
{
await Program.WriteMessage(message, textChannel, GlobalInformation.currentGuild);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}
protected void DeleteToken(string args)
{
File.Delete(Program.tokenPath);
Environment.Exit(0);
}
}
}
-247
View File
@@ -1,247 +0,0 @@
using ColorMine.ColorSpaces;
using ColorMine.ColorSpaces.Comparisons;
using DSharpPlus;
using DSharpPlus.Entities;
using Stone_Red_Utilities.ColorConsole;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Color = System.Drawing.Color;
namespace DiscordCLI
{
internal class Program
{
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
private static DiscordClient client;
private CommandsManager commandsManager;
private static string input = "<";
public const string tokenPath = "token.txt";
public async Task MainAsync()
{
Console.ForegroundColor = ConsoleColor.White;
Console.OutputEncoding = System.Text.Encoding.UTF8;
string token = string.Empty;
if (File.Exists(tokenPath))
token = File.ReadAllText(tokenPath);
while (string.IsNullOrEmpty(token))
{
Console.Write("Enter auth token: ");
token = Console.ReadLine();
}
File.WriteAllText(tokenPath, token);
try
{
client = new DiscordClient(new DiscordConfiguration()
{
Token = token,
TokenType = TokenType.User
});
client.MessageCreated += Client_MessageCreated;
await client.ConnectAsync();
}
catch (Exception ex)
{
ConsoleExt.WriteLine(ex, ConsoleColor.Red);
if (ex.Message.Contains("Authentication failed"))
File.Delete(tokenPath);
return;
}
commandsManager = new CommandsManager(client);
await ReadInput();
await Task.Delay(-1);
}
private async Task Client_MessageCreated(DSharpPlus.EventArgs.MessageCreateEventArgs e)
{
await WriteMessage(e.Message, e.Channel, e.Guild);
}
public static async Task WriteMessage(DiscordMessage message, DiscordChannel channel, DiscordGuild guild)
{
try
{
if (channel.Id != GlobalInformation.currentTextChannel?.Id)
return;
DiscordUser user = message.Author;
DiscordMember discordMember = await guild.GetMemberAsync(user.Id);
DiscordColor discordColor = discordMember.Color;
Color color = Color.FromArgb(discordColor.R, discordColor.G, discordColor.B);
WriteTop($"[{discordMember.DisplayName}]", color, message, $"{discordMember.Username}#{discordMember.Discriminator} {message.Timestamp.LocalDateTime}");
if (!string.IsNullOrWhiteSpace(message.Content))
WriteTop(message.Content, Color.White, message);
foreach (DiscordAttachment attachment in message.Attachments)
{
WriteTop($"{attachment.Url}", Color.White, message, attachment.FileName);
}
foreach (DiscordEmbed embed in message.Embeds)
{
if (!string.IsNullOrWhiteSpace(embed.Title))
WriteTop($">>> {{{embed.Title}}}", Color.FromArgb(embed.Color.Value), message);
if (!string.IsNullOrWhiteSpace(embed.Description))
WriteTop($">> {embed.Description}", Color.White, message);
WriteTop($"{string.Join(Environment.NewLine, embed.Fields.Select(x => $">{x.Name}{Environment.NewLine}{x.Value}"))}", Color.White, message);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
WriteTop(string.Empty, Color.White, message);
Console.Write($"[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{GlobalInformation.currentGuild?.Name}/{GlobalInformation.currentTextChannel?.Name}] ==> ");
Console.Write(input);
}
private async Task ReadInput()
{
await Task.Run(() =>
{
bool exit = false;
while (!exit)
{
string infoString = $"\r[{client.CurrentUser.Username}#{client.CurrentUser.Discriminator}] [{GlobalInformation.currentGuild?.Name}/{GlobalInformation.currentTextChannel?.Name}] ==> ";
if (input.StartsWith('<'))
Console.Write(Environment.NewLine + infoString);
input = string.Empty;
ConsoleKeyInfo keyInfo;
do
{
keyInfo = Console.ReadKey(true);
if (!char.IsControl(keyInfo.KeyChar))
input += keyInfo.KeyChar.ToString();
if (keyInfo.Key == ConsoleKey.Backspace)
{
if (input.Length > 0)
{
input = input.Remove(input.Length - 1);
}
}
Console.Write(keyInfo.KeyChar);
if (keyInfo.Key == ConsoleKey.Backspace)
Console.Write(" ");
Console.CursorLeft = infoString.Length + input.Length - 1;
} while (keyInfo.Key != ConsoleKey.Enter);
if (GlobalInformation.currentTextChannel == null && !input.StartsWith('<'))
input = "<" + input;
exit = commandsManager.CheckCommand(input);
}
Environment.Exit(0);
});
}
private async static void WriteTop(string message, Color color, DiscordMessage discordMessage, string info = null)
{
ConsoleColor consoleColor = ClosestConsoleColor3(color);
if (consoleColor == Console.BackgroundColor || consoleColor == ConsoleColor.DarkGray)
consoleColor = ConsoleColor.White;
//Console.SetCursorPosition(0, Console.WindowTop + Console.WindowHeight - 1);
Console.Write('\r' + new string(' ', Console.WindowWidth) + '\r');
string[] words = message.Split(' ');
for (int i = 0; i < words.Length; i++)
{
ConsoleColor mentionColor = ConsoleColor.Black;
foreach (DiscordUser user in discordMessage.MentionedUsers)
{
if (user?.Mention is not null)
if (words[i].Contains(user.Mention))
{
words[i] = words[i].Replace(user.Mention, $"@{user.Username}#{user.Discriminator}");
mentionColor = ConsoleColor.Blue;
}
}
foreach (DiscordChannel channel in discordMessage.MentionedChannels)
{
if (channel?.Mention is not null)
if (words[i].Contains(channel.Mention))
{
words[i] = words[i].Replace(channel.Mention, $"#{channel.Name}");
mentionColor = ConsoleColor.Blue;
}
}
foreach (DiscordRole role in discordMessage.MentionedRoles)
{
if (role?.Mention is not null)
if (words[i].Contains(role.Mention))
{
words[i] = words[i].Replace(role.Mention, $"@{role.Name}");
DiscordColor discordColor = role.Color;
mentionColor = ClosestConsoleColor3(Color.FromArgb(discordColor.R, discordColor.G, discordColor.B));
}
}
ConsoleExt.Write(words[i] + " ", mentionColor == ConsoleColor.Black ? consoleColor : mentionColor);
}
ConsoleExt.WriteLine(" " + info, ConsoleColor.DarkGray);
}
public static ConsoleColor ClosestConsoleColor3(Color targetColor)
{
double minDif = double.MaxValue;
ConsoleColor bestColor = ConsoleColor.White;
foreach (ConsoleColor consoleColor in Enum.GetValues(typeof(ConsoleColor)))
{
Color color = Color.FromName(consoleColor.ToString());
var colorA = new Rgb
{
R = targetColor.R,
G = targetColor.G,
B = targetColor.B
};
var colorB = new Rgb
{
R = color.R,
G = color.G,
B = color.B
};
double diff = colorA.Compare(colorB, new Cie1976Comparison());
if (diff < minDif)
{
minDif = diff;
bestColor = consoleColor;
}
}
return bestColor;
}
}
}
@@ -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\</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.
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"
]
}
}
@@ -1,9 +0,0 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +0,0 @@
{
"runtimeOptions": {
"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
@@ -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.
File diff suppressed because it is too large Load Diff
@@ -1,9 +0,0 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\David\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\David\\.nuget\\packages",
"C:\\Microsoft\\Xamarin\\NuGet"
]
}
}
@@ -1,9 +0,0 @@
{
"runtimeOptions": {
"tfm": "net5.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "5.0.0"
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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.
@@ -1 +0,0 @@
dfd104565a5c51e51c96fc2a0f9e9b9515e39127
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.
@@ -1 +0,0 @@
3ab14035ed25e46cb2eb046c245e2f90325a2743
Binary file not shown.
@@ -1 +0,0 @@
3e2c7be251ce3e62a6541dac29e1895e802a69f2
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
6843f3cabf894dfce1aaffe6c65e64e8531c52b6
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
8dbf5d9b5cf6fb65f2290f681f68bfa7a21560cd
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Stone_Red
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+87
View File
@@ -0,0 +1,87 @@
# DiscordCLI
> Use Discord in the terminal
## Warning
**Use this software at your own risk!**\
This isn't directly a selfbot, but Discord may count it as User account automation and this is against their TOS.\
I guess everything should be fine as long as you don't behave conspicuously but still proceed with caution!\
Currently there are no known cases where a user got banned for using this Discord client but that doesn't mean it will never happen.\
Don't blame me if you get banned!\
I will update the above if anything changes!
## Usage
1. [Download]("https://github.com/Stone-Red-Code/DiscordCLI/releases
) one of the releases
2. Execute the `DiscordCLI.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.
+240
View File
@@ -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;
}
}
}
+111
View File
@@ -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>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AssemblyVersion>0.0.4.1</AssemblyVersion>
<FileVersion>0.0.4.1</FileVersion>
<Version>0.0.4.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AlwaysUpToDate" Version="1.0.0.3" />
<PackageReference Include="ColorMineStandard" Version="1.0.0" />
<PackageReference Include="DSharpPlus" Version="3.2.3" />
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.0.2" />
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.2.1" />
</ItemGroup>
</Project>
<ItemGroup>
<Folder Include="Properties\PublishProfiles\" />
</ItemGroup>
</Project>

Some files were not shown because too many files have changed in this diff Show More