Added commands history

- Added commands history
- Added "clear" command
- Small code improvements
This commit is contained in:
Stone-Red-Code
2021-05-28 19:54:42 +02:00
parent d9143457a7
commit 2265b044cc
23 changed files with 76 additions and 32 deletions
+4
View File
@@ -33,6 +33,10 @@ I will update the above if anything changes!
- deletes auth token and exits application - deletes auth token and exits application
### clear
- clears the console
### guilds ### guilds
- lists all guilds you are in - lists all guilds you are in
Binary file not shown.
+11 -3
View File
@@ -1,9 +1,8 @@
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus; using DSharpPlus;
using Stone_Red_Utilities.ColorConsole; using Stone_Red_Utilities.ConsoleExtentions;
using Stone_Red_Utilities.StringExtentions; using Stone_Red_Utilities.StringExtentions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System; using System;
@@ -213,9 +212,12 @@ namespace DiscordCLI
if (discordUser is not null) if (discordUser is not null)
{ {
string status = discordUser.Presence?.Status.ToString();
status ??= "N/A";
string infoString = string infoString =
$"Username: {discordUser.Username}#{discordUser.Discriminator}" + Environment.NewLine + $"Username: {discordUser.Username}#{discordUser.Discriminator}" + Environment.NewLine +
$"Status: {discordUser.Presence?.Status}" + Environment.NewLine + $"Status: {status}" + Environment.NewLine +
$"Created at: {discordUser.CreationTimestamp}" + Environment.NewLine + $"Created at: {discordUser.CreationTimestamp}" + Environment.NewLine +
$"ID: {discordUser.Id}" + Environment.NewLine + $"ID: {discordUser.Id}" + Environment.NewLine +
$"Bot: {discordUser.IsBot}"; $"Bot: {discordUser.IsBot}";
@@ -228,5 +230,11 @@ namespace DiscordCLI
await Task.CompletedTask; await Task.CompletedTask;
} }
protected async Task Clear(string args)
{
Console.Clear();
await Task.CompletedTask;
}
} }
} }
+3 -2
View File
@@ -1,5 +1,5 @@
using DSharpPlus; using DSharpPlus;
using Stone_Red_Utilities.ColorConsole; using Stone_Red_Utilities.ConsoleExtentions;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System; using System;
@@ -23,13 +23,14 @@ namespace DiscordCLI
{ {
{ "exit", ("exits application", null) }, { "exit", ("exits application", null) },
{ "logout", ("deletes auth token and exits application", DeleteToken) }, { "logout", ("deletes auth token and exits application", DeleteToken) },
{ "clear", ("clears the console", Clear) },
{ "guilds", ("lists all guilds you are in", ListGuilds) }, { "guilds", ("lists all guilds you are in", ListGuilds) },
{ "dms", ("lists all private channels", ListDms) }, { "dms", ("lists all private channels", ListDms) },
{ "channels", ("lists all channels of guild args:<guild name/index>", ListGuildChannels) }, { "channels", ("lists all channels of guild args:<guild name/index>", ListGuildChannels) },
{ "enterg", ("enter guild args:<guild name/index>", ListGuildChannels) }, { "enterg", ("enter guild args:<guild name/index>", ListGuildChannels) },
{ "enterc", ("enter channel args:<channel name/index>", EnterChannel) }, { "enterc", ("enter channel args:<channel name/index>", EnterChannel) },
{ "enterd", ("enter DM channel args:<channel name/index>", EnterDmChannel) }, { "enterd", ("enter DM channel args:<channel name/index>", EnterDmChannel) },
{ "userinfo", ("gets information about a user:<user name>", UserInfo) }, { "userinfo", ("gets information about a user args:<username>", UserInfo) },
}; };
Timer cooldownTimer = new Timer(1000); Timer cooldownTimer = new Timer(1000);
+3 -1
View File
@@ -3,11 +3,13 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<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> </Project>
+29
View File
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using System; using System;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using System.Linq; using System.Linq;
using System.Collections.Generic;
namespace DiscordCLI namespace DiscordCLI
{ {
@@ -10,6 +11,7 @@ namespace DiscordCLI
{ {
private readonly CommandsManager commandsManager; private readonly CommandsManager commandsManager;
private readonly DiscordClient client; private readonly DiscordClient client;
private readonly List<string> previousInputs = new List<string>();
public const string prefix = ">"; public const string prefix = ">";
public string Input { get; private set; } = string.Empty; public string Input { get; private set; } = string.Empty;
@@ -21,6 +23,7 @@ namespace DiscordCLI
public async Task ReadInput() public async Task ReadInput()
{ {
int inputListIndex = 0;
bool exit = false; bool exit = false;
bool printOverride = false; bool printOverride = false;
string lastInput = prefix; string lastInput = prefix;
@@ -44,6 +47,26 @@ namespace DiscordCLI
{ {
Input = Input.Remove(Input.Length - 1); Input = Input.Remove(Input.Length - 1);
} }
else if (keyInfo.Key == ConsoleKey.UpArrow)
{
if (previousInputs.Count > 0)
Input = previousInputs[previousInputs.Count - inputListIndex - 1];
if (inputListIndex < previousInputs.Count - 1)
inputListIndex++;
Console.CursorLeft = infoString.Length - 1;
Console.Write(Input + new string(' ', Console.WindowWidth - infoString.Length - 1));
}
else if (keyInfo.Key == ConsoleKey.DownArrow)
{
if (previousInputs.Count > 0)
Input = previousInputs[previousInputs.Count - inputListIndex - 1];
if (inputListIndex > 0)
inputListIndex--;
Console.CursorLeft = infoString.Length - 1;
Console.Write(Input + new string(' ', Console.WindowWidth - infoString.Length - 1));
}
Console.Write(keyInfo.KeyChar); Console.Write(keyInfo.KeyChar);
if (keyInfo.Key == ConsoleKey.Backspace) if (keyInfo.Key == ConsoleKey.Backspace)
@@ -53,8 +76,14 @@ namespace DiscordCLI
} while (keyInfo.Key != ConsoleKey.Enter); } while (keyInfo.Key != ConsoleKey.Enter);
if (GlobalInformation.currentTextChannel == null && !Input.StartsWith(prefix)) if (GlobalInformation.currentTextChannel == null && !Input.StartsWith(prefix))
{
if (previousInputs.Count > 10)
previousInputs.RemoveAt(0);
previousInputs.Add(new string(Input));
Input = prefix + Input; Input = prefix + Input;
}
inputListIndex = 0;
lastInput = new string(Input); lastInput = new string(Input);
Input = string.Empty; Input = string.Empty;
+1 -3
View File
@@ -2,7 +2,7 @@
using ColorMine.ColorSpaces; using ColorMine.ColorSpaces;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus; using DSharpPlus;
using Stone_Red_Utilities.ColorConsole; using Stone_Red_Utilities.ConsoleExtentions;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
@@ -122,8 +122,6 @@ namespace DiscordCLI
string part2 = words[i].Substring(index1, index2 - index1 + 1); string part2 = words[i].Substring(index1, index2 - index1 + 1);
string part3 = words[i].Substring(index2 + 1, words[i].Length - index2 - 1); string part3 = words[i].Substring(index2 + 1, words[i].Length - index2 - 1);
Debug.WriteLine(words[i] + "/" + i);
Debug.WriteLine(part1 + "/" + part2 + "/" + part3);
words[i] = part2; words[i] = part2;
if (!string.IsNullOrEmpty(part1)) if (!string.IsNullOrEmpty(part1))
{ {
+5 -3
View File
@@ -1,8 +1,9 @@
using DSharpPlus; using DSharpPlus;
using Stone_Red_Utilities.ColorConsole;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using System; using System;
using DSharpPlus.Exceptions;
using Stone_Red_Utilities.ConsoleExtentions;
namespace DiscordCLI namespace DiscordCLI
{ {
@@ -46,12 +47,13 @@ namespace DiscordCLI
client.MessageCreated += Client_MessageCreated; client.MessageCreated += Client_MessageCreated;
await client.ConnectAsync(); await client.ConnectAsync();
ConsoleExt.WriteLine("Welcome to DiscordCLI", ConsoleColor.Green);
} }
catch (Exception ex) catch (Exception ex)
{ {
ConsoleExt.WriteLine(ex, ConsoleColor.Red); ConsoleExt.WriteLine(ex.Message, ConsoleColor.Red);
if (ex.Message.Contains("Authentication failed")) if (ex.InnerException is UnauthorizedException)
{ {
File.Delete(tokenPath); File.Delete(tokenPath);
token = string.Empty; token = string.Empty;
@@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"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": {}
@@ -186,11 +186,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"
} }
} }
}, },
@@ -1173,12 +1173,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",
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
d74c436d6f045a94c6aefe230b53cf4fbca29cc5 d66ea650fdd7843db4c6a535455ec0e4db621eb3
Binary file not shown.
@@ -1 +1 @@
3e2c7be251ce3e62a6541dac29e1895e802a69f2 7913be6fc5baee9a6c6e2d3d32160d2ff9b796ff
Binary file not shown.
Binary file not shown.
@@ -56,7 +56,7 @@
}, },
"Stone_Red-C-Sharp-Utilities": { "Stone_Red-C-Sharp-Utilities": {
"target": "Package", "target": "Package",
"version": "[1.0.0.2, )" "version": "[1.0.2.1, )"
} }
}, },
"imports": [ "imports": [
+7 -7
View File
@@ -333,7 +333,7 @@
} }
} }
}, },
"Stone_Red-C-Sharp-Utilities/1.0.0.2": { "Stone_Red-C-Sharp-Utilities/1.0.2.1": {
"type": "package", "type": "package",
"compile": { "compile": {
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll": {} "lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll": {}
@@ -2116,17 +2116,17 @@
"runtimes/ubuntu.16.10-x64/native/System.Security.Cryptography.Native.OpenSsl.so" "runtimes/ubuntu.16.10-x64/native/System.Security.Cryptography.Native.OpenSsl.so"
] ]
}, },
"Stone_Red-C-Sharp-Utilities/1.0.0.2": { "Stone_Red-C-Sharp-Utilities/1.0.2.1": {
"sha512": "/oH1XweI6G2VjeXuutq3XhHAPiSpotfPnsRMK0n8BXFOqG85y0AXQGaKiEdhCZZOpLHFrNY8rtLepMgLJrsY9w==", "sha512": "QzwH0QvsDiBvCJTFroZBhN/pMEIiz0C8TNkQci+pxCbnjfTtVkxAYsgmlshCl5oHFJh7VYDLcGAULcMBARSb+w==",
"type": "package", "type": "package",
"path": "stone_red-c-sharp-utilities/1.0.0.2", "path": "stone_red-c-sharp-utilities/1.0.2.1",
"files": [ "files": [
".nupkg.metadata", ".nupkg.metadata",
".signature.p7s", ".signature.p7s",
"LICENSE", "LICENSE",
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll", "lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll",
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.xml", "lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.xml",
"stone_red-c-sharp-utilities.1.0.0.2.nupkg.sha512", "stone_red-c-sharp-utilities.1.0.2.1.nupkg.sha512",
"stone_red-c-sharp-utilities.nuspec" "stone_red-c-sharp-utilities.nuspec"
] ]
}, },
@@ -5871,7 +5871,7 @@
"net5.0": [ "net5.0": [
"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"
] ]
}, },
"packageFolders": { "packageFolders": {
@@ -5931,7 +5931,7 @@
}, },
"Stone_Red-C-Sharp-Utilities": { "Stone_Red-C-Sharp-Utilities": {
"target": "Package", "target": "Package",
"version": "[1.0.0.2, )" "version": "[1.0.2.1, )"
} }
}, },
"imports": [ "imports": [
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"version": 2, "version": 2,
"dgSpecHash": "XLOvAlY87TySZurLo7RL2ezpJBE2tGd1+FsXFkZDwV1NittIw9rcMhOKE+zQq9a72LifKd0qtXSCJ9fmOFQBgA==", "dgSpecHash": "Sd5hpdPX468vitJPajPRcSMeE6uWNGkfdaCwfOPZjTBB+77H8fvWa+ejKX0QBCdfNu4FyA2bZOqgsxhGYcKcVA==",
"success": true, "success": true,
"projectFilePath": "C:\\Users\\David\\Google Drive\\Programmieren\\DiscordCLI\\src\\DiscordCLI\\DiscordCLI.csproj", "projectFilePath": "C:\\Users\\David\\Google Drive\\Programmieren\\DiscordCLI\\src\\DiscordCLI\\DiscordCLI.csproj",
"expectedPackageFiles": [ "expectedPackageFiles": [
@@ -29,7 +29,7 @@
"C:\\Users\\David\\.nuget\\packages\\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.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\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.nupkg.sha512",
"C:\\Users\\David\\.nuget\\packages\\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.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\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.nupkg.sha512",
"C:\\Users\\David\\.nuget\\packages\\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.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\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.nupkg.sha512",
"C:\\Users\\David\\.nuget\\packages\\stone_red-c-sharp-utilities\\1.0.0.2\\stone_red-c-sharp-utilities.1.0.0.2.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\stone_red-c-sharp-utilities\\1.0.2.1\\stone_red-c-sharp-utilities.1.0.2.1.nupkg.sha512",
"C:\\Users\\David\\.nuget\\packages\\system.appcontext\\4.3.0\\system.appcontext.4.3.0.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\system.appcontext\\4.3.0\\system.appcontext.4.3.0.nupkg.sha512",
"C:\\Users\\David\\.nuget\\packages\\system.buffers\\4.3.0\\system.buffers.4.3.0.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\system.buffers\\4.3.0\\system.buffers.4.3.0.nupkg.sha512",
"C:\\Users\\David\\.nuget\\packages\\system.collections\\4.3.0\\system.collections.4.3.0.nupkg.sha512", "C:\\Users\\David\\.nuget\\packages\\system.collections\\4.3.0\\system.collections.4.3.0.nupkg.sha512",