mirror of
https://github.com/Stone-Red-Code/DiscordCLI.git
synced 2026-09-04 00:55:58 +02:00
Make userinfo command more reliable and some bug fixes
This commit is contained in:
Binary file not shown.
Binary file not shown.
+34
-21
@@ -134,7 +134,7 @@ namespace DiscordCLI
|
||||
{
|
||||
foreach (DiscordMessage message in (textChannel.GetMessagesAsync(10).Result).Reverse())
|
||||
{
|
||||
await outputManager.WriteMessage(message, textChannel, GlobalInformation.currentGuild, false);
|
||||
await outputManager.WriteMessage(message, textChannel, false);
|
||||
}
|
||||
Console.CursorTop--;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ namespace DiscordCLI
|
||||
{
|
||||
foreach (DiscordMessage message in (await dmChannel.GetMessagesAsync(10)).Reverse())
|
||||
{
|
||||
await outputManager.WriteMessage(message, dmChannel, GlobalInformation.currentGuild, false);
|
||||
await outputManager.WriteMessage(message, dmChannel, false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -206,28 +206,25 @@ namespace DiscordCLI
|
||||
return;
|
||||
}
|
||||
|
||||
DiscordUser discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => user.Username.EqualsIgnoreSpacesAndCase(userName));
|
||||
DiscordUser discordUser = await GetDiscordUser(userName);
|
||||
|
||||
if (discordUser is null)
|
||||
string status = discordUser?.Presence?.Status.ToString();
|
||||
status ??= "N/A";
|
||||
|
||||
if (discordUser is DiscordMember discordMember)
|
||||
{
|
||||
discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}#{user.Discriminator}".EqualsIgnoreSpacesAndCase(userName));
|
||||
string infoString =
|
||||
$"Username: {discordMember.Username}#{discordMember.Discriminator}" + Environment.NewLine +
|
||||
$"Nickname: {discordMember.Nickname ?? "N/A"}" + Environment.NewLine +
|
||||
$"Roles: {string.Join(", ", discordMember.Roles.Select(x => x.Name))}" + Environment.NewLine +
|
||||
$"Status: {status}" + Environment.NewLine +
|
||||
$"Created at: {discordMember.CreationTimestamp}" + Environment.NewLine +
|
||||
$"ID: {discordMember.Id}" + Environment.NewLine +
|
||||
$"Bot: {discordMember.IsBot}";
|
||||
Console.WriteLine(infoString);
|
||||
}
|
||||
|
||||
if (discordUser is null)
|
||||
else if (discordUser is not null)
|
||||
{
|
||||
discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}".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 +
|
||||
@@ -241,7 +238,23 @@ namespace DiscordCLI
|
||||
ConsoleExt.WriteLine("User not found!", ConsoleColor.Red);
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
async Task<DiscordUser> GetDiscordUser(string name)
|
||||
{
|
||||
DiscordUser discordUser = GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => user.Username.EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}#{user.Discriminator}".EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Username}".EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= GlobalInformation.currentGuild?.Members?.FirstOrDefault(user => $"{user.Nickname}".EqualsIgnoreSpacesAndCase(userName));
|
||||
|
||||
if (discordUser is null)
|
||||
{
|
||||
IReadOnlyList<DiscordUser> users = await GlobalInformation.currentGuild.GetAllMembersAsync();
|
||||
discordUser ??= users.FirstOrDefault(user => user.Username.EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= users.FirstOrDefault(user => $"{user.Username}#{user.Discriminator}".EqualsIgnoreSpacesAndCase(userName));
|
||||
discordUser ??= users.FirstOrDefault(user => $"{user.Username}".EqualsIgnoreSpacesAndCase(userName));
|
||||
}
|
||||
|
||||
return discordUser;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task Clear(string args)
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace DiscordCLI
|
||||
try
|
||||
{
|
||||
await GlobalInformation.currentTextChannel.SendMessageAsync(rawInput);
|
||||
Console.CursorTop--;
|
||||
Console.Write("\r" + new string(' ', Console.WindowWidth));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -75,15 +75,17 @@ namespace DiscordCLI
|
||||
Console.CursorLeft = infoString.Length + Input.Length - 1;
|
||||
} while (keyInfo.Key != ConsoleKey.Enter);
|
||||
|
||||
if (GlobalInformation.currentTextChannel == null && !Input.StartsWith(Prefix))
|
||||
if (GlobalInformation.currentTextChannel == null)
|
||||
{
|
||||
Input = Input.Trim();
|
||||
if (!Input.StartsWith(Prefix))
|
||||
Input = Prefix + Input;
|
||||
|
||||
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;
|
||||
|
||||
@@ -23,18 +23,18 @@ namespace DiscordCLI
|
||||
client = discordClient;
|
||||
}
|
||||
|
||||
public async Task WriteMessage(DiscordMessage message, DiscordChannel channel, DiscordGuild guild, bool writeInfo = true)
|
||||
public async Task WriteMessage(DiscordMessage message, DiscordChannel channel, bool writeInfo = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (channel?.Id != GlobalInformation.currentTextChannel?.Id)
|
||||
if (message.ChannelId != GlobalInformation.currentTextChannel?.Id)
|
||||
return;
|
||||
|
||||
DiscordUser user = message.Author;
|
||||
|
||||
if (GlobalInformation.currentGuild is not null)
|
||||
{
|
||||
DiscordMember discordMember = await guild.GetMemberAsync(user.Id);
|
||||
DiscordMember discordMember = await channel.Guild.GetMemberAsync(user.Id);
|
||||
DiscordColor discordColor = discordMember.Color;
|
||||
Color color = Color.FromArgb(discordColor.R, discordColor.G, discordColor.B);
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace DiscordCLI
|
||||
{
|
||||
if (user?.Mention is not null)
|
||||
{
|
||||
if (match.Value == user.Mention)
|
||||
if (match.Value == user.Mention.Replace("!", string.Empty))
|
||||
{
|
||||
message = message.Replace(match.Value, $"\0<C{(int)ConsoleColor.Blue}C>@{user.Username}#{user.Discriminator}\0");
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ using System.Threading.Tasks;
|
||||
using System;
|
||||
using DSharpPlus.Exceptions;
|
||||
using Stone_Red_Utilities.ConsoleExtentions;
|
||||
using System.Reflection;
|
||||
using AlwaysUpToDate;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace DiscordCLI
|
||||
@@ -64,7 +62,6 @@ namespace DiscordCLI
|
||||
Token = token,
|
||||
TokenType = TokenType.User,
|
||||
});
|
||||
|
||||
client.MessageCreated += Client_MessageCreated;
|
||||
|
||||
await client.ConnectAsync();
|
||||
@@ -119,7 +116,7 @@ namespace DiscordCLI
|
||||
{
|
||||
try
|
||||
{
|
||||
await outputManager.WriteMessage(e.Message, e.Channel, e.Guild);
|
||||
await outputManager.WriteMessage(e.Message, e.Channel);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
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,10 +1,10 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -19,5 +19,5 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("DiscordCLI")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("0.0.4.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
// Von der MSBuild WriteCodeFragment-Klasse generiert.
|
||||
|
||||
|
||||
Binary file not shown.
@@ -55,7 +55,6 @@ C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\bin\Debug\net5.0\DSharpPl
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\bin\Debug\net5.0\Newtonsoft.Json.dll
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\bin\Debug\net5.0\Stone_Red-C-Sharp-Utilities.dll
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\bin\Debug\net5.0\System.Text.Json.dll
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.csproj.AssemblyReference.cache
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.GeneratedMSBuildEditorConfig.editorconfig
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.AssemblyInfoInputs.cache
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.AssemblyInfo.cs
|
||||
@@ -65,3 +64,4 @@ C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordC
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\ref\DiscordCLI.dll
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.pdb
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.genruntimeconfig.cache
|
||||
C:\Users\David\Programmieren\DiscordCLI\src\DiscordCLI\obj\Debug\net5.0\DiscordCLI.csproj.AssemblyReference.cache
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user