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
Binary file not shown.
+11 -3
View File
@@ -1,9 +1,8 @@
using DSharpPlus.Entities;
using DSharpPlus;
using Stone_Red_Utilities.ColorConsole;
using Stone_Red_Utilities.ConsoleExtentions;
using Stone_Red_Utilities.StringExtentions;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System;
@@ -213,9 +212,12 @@ namespace DiscordCLI
if (discordUser is not null)
{
string status = discordUser.Presence?.Status.ToString();
status ??= "N/A";
string infoString =
$"Username: {discordUser.Username}#{discordUser.Discriminator}" + Environment.NewLine +
$"Status: {discordUser.Presence?.Status}" + Environment.NewLine +
$"Status: {status}" + Environment.NewLine +
$"Created at: {discordUser.CreationTimestamp}" + Environment.NewLine +
$"ID: {discordUser.Id}" + Environment.NewLine +
$"Bot: {discordUser.IsBot}";
@@ -228,5 +230,11 @@ namespace DiscordCLI
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 Stone_Red_Utilities.ColorConsole;
using Stone_Red_Utilities.ConsoleExtentions;
using System.Collections.Generic;
using System.Linq;
using System;
@@ -23,13 +23,14 @@ namespace DiscordCLI
{
{ "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:<user name>", UserInfo) },
{ "userinfo", ("gets information about a user args:<username>", UserInfo) },
};
Timer cooldownTimer = new Timer(1000);
+3 -1
View File
@@ -3,11 +3,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<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>
+29
View File
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
using System;
using DSharpPlus.Entities;
using System.Linq;
using System.Collections.Generic;
namespace DiscordCLI
{
@@ -10,6 +11,7 @@ namespace DiscordCLI
{
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;
@@ -21,6 +23,7 @@ namespace DiscordCLI
public async Task ReadInput()
{
int inputListIndex = 0;
bool exit = false;
bool printOverride = false;
string lastInput = prefix;
@@ -44,6 +47,26 @@ namespace DiscordCLI
{
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);
if (keyInfo.Key == ConsoleKey.Backspace)
@@ -53,8 +76,14 @@ namespace DiscordCLI
} while (keyInfo.Key != ConsoleKey.Enter);
if (GlobalInformation.currentTextChannel == null && !Input.StartsWith(prefix))
{
if (previousInputs.Count > 10)
previousInputs.RemoveAt(0);
previousInputs.Add(new string(Input));
Input = prefix + Input;
}
inputListIndex = 0;
lastInput = new string(Input);
Input = string.Empty;
+1 -3
View File
@@ -2,7 +2,7 @@
using ColorMine.ColorSpaces;
using DSharpPlus.Entities;
using DSharpPlus;
using Stone_Red_Utilities.ColorConsole;
using Stone_Red_Utilities.ConsoleExtentions;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
@@ -122,8 +122,6 @@ namespace DiscordCLI
string part2 = words[i].Substring(index1, index2 - index1 + 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;
if (!string.IsNullOrEmpty(part1))
{
+5 -3
View File
@@ -1,8 +1,9 @@
using DSharpPlus;
using Stone_Red_Utilities.ColorConsole;
using System.IO;
using System.Threading.Tasks;
using System;
using DSharpPlus.Exceptions;
using Stone_Red_Utilities.ConsoleExtentions;
namespace DiscordCLI
{
@@ -46,12 +47,13 @@ namespace DiscordCLI
client.MessageCreated += Client_MessageCreated;
await client.ConnectAsync();
ConsoleExt.WriteLine("Welcome to DiscordCLI", ConsoleColor.Green);
}
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);
token = string.Empty;
@@ -10,7 +10,7 @@
"dependencies": {
"ColorMineStandard": "1.0.0",
"DSharpPlus": "3.2.3",
"Stone_Red-C-Sharp-Utilities": "1.0.0.2"
"Stone_Red-C-Sharp-Utilities": "1.0.2.1"
},
"runtime": {
"DiscordCLI.dll": {}
@@ -186,11 +186,11 @@
"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.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": {
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll": {
"assemblyVersion": "1.0.0.2",
"fileVersion": "1.0.0.2"
"assemblyVersion": "1.0.2.1",
"fileVersion": "1.0.2.1"
}
}
},
@@ -1173,12 +1173,12 @@
"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"
},
"Stone_Red-C-Sharp-Utilities/1.0.0.2": {
"Stone_Red-C-Sharp-Utilities/1.0.2.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-/oH1XweI6G2VjeXuutq3XhHAPiSpotfPnsRMK0n8BXFOqG85y0AXQGaKiEdhCZZOpLHFrNY8rtLepMgLJrsY9w==",
"path": "stone_red-c-sharp-utilities/1.0.0.2",
"hashPath": "stone_red-c-sharp-utilities.1.0.0.2.nupkg.sha512"
"sha512": "sha512-QzwH0QvsDiBvCJTFroZBhN/pMEIiz0C8TNkQci+pxCbnjfTtVkxAYsgmlshCl5oHFJh7VYDLcGAULcMBARSb+w==",
"path": "stone_red-c-sharp-utilities/1.0.2.1",
"hashPath": "stone_red-c-sharp-utilities.1.0.2.1.nupkg.sha512"
},
"System.AppContext/4.3.0": {
"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": {
"target": "Package",
"version": "[1.0.0.2, )"
"version": "[1.0.2.1, )"
}
},
"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",
"compile": {
"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"
]
},
"Stone_Red-C-Sharp-Utilities/1.0.0.2": {
"sha512": "/oH1XweI6G2VjeXuutq3XhHAPiSpotfPnsRMK0n8BXFOqG85y0AXQGaKiEdhCZZOpLHFrNY8rtLepMgLJrsY9w==",
"Stone_Red-C-Sharp-Utilities/1.0.2.1": {
"sha512": "QzwH0QvsDiBvCJTFroZBhN/pMEIiz0C8TNkQci+pxCbnjfTtVkxAYsgmlshCl5oHFJh7VYDLcGAULcMBARSb+w==",
"type": "package",
"path": "stone_red-c-sharp-utilities/1.0.0.2",
"path": "stone_red-c-sharp-utilities/1.0.2.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE",
"lib/netstandard2.1/Stone_Red-C-Sharp-Utilities.dll",
"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"
]
},
@@ -5871,7 +5871,7 @@
"net5.0": [
"ColorMineStandard >= 1.0.0",
"DSharpPlus >= 3.2.3",
"Stone_Red-C-Sharp-Utilities >= 1.0.0.2"
"Stone_Red-C-Sharp-Utilities >= 1.0.2.1"
]
},
"packageFolders": {
@@ -5931,7 +5931,7 @@
},
"Stone_Red-C-Sharp-Utilities": {
"target": "Package",
"version": "[1.0.0.2, )"
"version": "[1.0.2.1, )"
}
},
"imports": [
+2 -2
View File
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "XLOvAlY87TySZurLo7RL2ezpJBE2tGd1+FsXFkZDwV1NittIw9rcMhOKE+zQq9a72LifKd0qtXSCJ9fmOFQBgA==",
"dgSpecHash": "Sd5hpdPX468vitJPajPRcSMeE6uWNGkfdaCwfOPZjTBB+77H8fvWa+ejKX0QBCdfNu4FyA2bZOqgsxhGYcKcVA==",
"success": true,
"projectFilePath": "C:\\Users\\David\\Google Drive\\Programmieren\\DiscordCLI\\src\\DiscordCLI\\DiscordCLI.csproj",
"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.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\\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.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",