Giter Site home page Giter Site logo

General Code Audit about sisbase HOT 8 OPEN

siscodeorg avatar siscodeorg commented on June 10, 2024
General Code Audit

from sisbase.

Comments (8)

roridev avatar roridev commented on June 10, 2024

CQ | API - Behaviours class works like a namespace, unnecessary nesting.

public static class Behaviours
{
/// <summary>
/// The counting behaviour for ListEmbeds
/// </summary>
public enum CountingBehaviour

This makes the calling side to have the following code:

using static sisbase.Utils.Behaviours;

Proposed solution

Remove the nesting and move said enums to their own namespace so the calling side would be this instead:

using sisbase.Utils.Enums;

from sisbase.

roridev avatar roridev commented on June 10, 2024

CQ | API - EmbedBase.ListEmbed uses IEnumerable<T> which is inconsistent with the api name, and likely could cause issues since IEnumerable can be anything that provides an enumerator.

Eg : Dictionary<T> ConcurrentDictionary<T> ConcurrentBag<T>...

public static DiscordEmbed ListEmbed<T>(IEnumerable<T> list, string name)

Proposed Solution

Change the function declaration to use an List<T> or IList<T>.

from sisbase.

roridev avatar roridev commented on June 10, 2024

CQ - Complex nested code could be made into a function

sisbase/Utils/EmbedBase.cs

Lines 182 to 204 in 64c33b8

if (command.Overloads?.Any() == true)
{
string use = "";
var o = command.Overloads.ToList();
var arguments = new List<CommandArgument>();
o.RemoveAll(x => x.Arguments.Count == 0);
foreach (var overload in o)
{
string inner = "";
var args = overload.Arguments.ToList();
foreach (var argument in args)
{
if (!arguments.Contains(argument))
{
arguments.Add(argument);
}
inner += $"`{argument.Name}` ";
}
use += $"[{command.Name} {inner}] ";
}
string argumentExplanation = "";
arguments.ForEach(x => argumentExplanation += $"{x.Name} - {x.Description}\n");

from sisbase.

roridev avatar roridev commented on June 10, 2024

CQ - Manual foreach be simplified by a linq expression
var RegisteredCommands = cne.RegisteredCommands.Values.ToList();
var groups = new List<CommandGroup>();
foreach (var command in RegisteredCommands)
{
if (command is CommandGroup group)
{
if (groups.Contains(group)) continue;

Proposed expression

var groups = RegisteredCommands.Where(x => x is CommandGroup).Distinct();

from sisbase.

roridev avatar roridev commented on June 10, 2024

CQ - Duplicated code that should be made into a function
if ((await group.RunChecksAsync(ctx, true)).Count() > 0) continue;
if (group.IsHidden && !showHidden) continue;

if ((await command.RunChecksAsync(ctx, true)).Count() > 0) continue;
if (command.IsHidden && !showHidden) continue;

Proposed function

/* public? */ async Task<bool> IsValidAsync(/*this?*/ Command c, bool hidden);

from sisbase.

roridev avatar roridev commented on June 10, 2024

CQ | API - Unused inferface. Should be deprecated/removed.

/// <summary>
/// Interface for systems that don't require connection to <see cref="DSharpPlus"/>
/// </summary>
public interface IStaticSystem : ISystem
{
}

from sisbase.

roridev avatar roridev commented on June 10, 2024

CQ - Poor variable names

sisbase/Utils/SMC.cs

Lines 34 to 35 in 64c33b8

var Ts = assembly.ExportedTypes.Where(T => T.GetTypeInfo().IsSystemCandidate());
foreach (var T in Ts)

from sisbase.

roridev avatar roridev commented on June 10, 2024

BUG | EXC - Non-exaustive call to string.Join which generates null once a list is empty. Embed fields can't have null values leading to an invalid embed generation.

.AddField("Permanently disabled systems [Systems.json]",
string.Join("\n",
SisbaseBot.Instance.SystemCfg.Systems.Where(kvp => !kvp.Value.Enabled)
.Select(kvp => kvp.Key))));

from sisbase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.