alvarocastro/diamondbot

View on GitHub

Showing 400 of 400 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    async getNonsense () {
        const res = await fetch('https://generatorfun.com/code/model/generatorcontent.php?recordtable=generator&recordkey=650&gen=Y&itemnumber=1&randomoption=undefined&genimage=No&nsfw=No&keyword=undefined&tone=Normal');
        const data = await res.text();
        let nonsense = data.replace(/.*<p>(.+?)<\/p>.*/ims, '$1').trim();

Severity: Major
Found in commands/fortune/src/index.js and 1 other location - About 3 hrs to fix
commands/fortune/src/index.js on lines 51..61

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 108.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    async getCommandment () {
        const res = await fetch('https://generatorfun.com/code/model/generatorcontent.php?recordtable=generator&recordkey=76&gen=Y&itemnumber=1&randomoption=undefined&genimage=No&nsfw=No&keyword=undefined&tone=Normal');
        const data = await res.text();
        let nonsense = data.replace(/.*<p>(.+?)<\/p>.*/ims, '$1').trim();

Severity: Major
Found in commands/fortune/src/index.js and 1 other location - About 3 hrs to fix
commands/fortune/src/index.js on lines 39..49

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 108.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Consider simplifying this complex logical expression.
Open

        if (
            args[0] === 'h' ||
            args[0] === 'help' ||
            args.length > 3 ||
            (year && isNaN(year)) ||
Severity: Critical
Found in commands/history/src/index.js - About 3 hrs to fix

    Function exec has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        async exec ({member, channel, guild}, [user]) {
            let target;
            if (!user) {
                target = member;
            } else if (Discord.MessageMentions.USERS_PATTERN.test(user)) {
    Severity: Minor
    Found in commands/memberage/src/index.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            if (this.categoriesChance) {
                this.weightedCategories = this.categories.map((c, i) => [c, this.categoriesChance[i]]);
            } else {
                this.weightedCategories = this.categories.map((c, i) => [c, 1]);
            }
    Severity: Major
    Found in commands/joke/src/index.js and 1 other location - About 2 hrs to fix
    commands/fortune/src/index.js on lines 21..25

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 85.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            if (this.categoriesChance) {
                this.weightedCategories = this.categories.map((c, i) => [c, this.categoriesChance[i]]);
            } else {
                this.weightedCategories = this.categories.map((c, i) => [c, 1]);
            }
    Severity: Major
    Found in commands/fortune/src/index.js and 1 other location - About 2 hrs to fix
    commands/joke/src/index.js on lines 20..24

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 85.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function exec has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        async exec ({channel}, args) {
            const now = new Date;
            let month;
            let day;
            let year;
    Severity: Major
    Found in commands/history/src/index.js - About 2 hrs to fix

      Function exec has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          async exec ({channel}, args) {
              const now = new Date;
              let month;
              let day;
              let year;
      Severity: Minor
      Found in commands/history/src/index.js - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function exec has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async exec ({member, channel, guild}, [user]) {
              let target;
              if (!user) {
                  target = member;
              } else if (Discord.MessageMentions.USERS_PATTERN.test(user)) {
      Severity: Minor
      Found in commands/memberage/src/index.js - About 1 hr to fix

        Function exec has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            exec ({channel}, [level = 'normal']) {
                level = level.toLowerCase();
                const levels = ['dumb', 'easy', 'normal', 'hard', 'extreme'];
        
                if (!levels.includes(level)) {
        Severity: Minor
        Found in commands/minesweeper/src/index.js - About 1 hr to fix

          Function exec has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              async exec (message, args) {
                  const [options, ...rest] = args;
          
                  let type = 'pics';
                  let command = 'category';
          Severity: Minor
          Found in commands/porn/src/index.js - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function handleMessage has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async handleMessage (message) {
                  // Prevent bots talk
                  if (message.author.bot) {
                      return;
                  }
          Severity: Minor
          Found in core/src/bot.js - About 1 hr to fix

            Function check has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                check (message, args, memory) {
                    if (this.nsfw && !message.channel.nsfw) {
                        return false;
                    }
            
            
            Severity: Minor
            Found in core/src/chat-command.js - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function exec has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async exec (message, args) {
                    const [options, ...rest] = args;
            
                    let type = 'pics';
                    let command = 'category';
            Severity: Minor
            Found in commands/porn/src/index.js - About 1 hr to fix

              Function exec has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async exec ({channel}) {
                      const reddit = randomItem([
                          'cat',
                          'cats',
                          'whatswrongwithyourcat',
              Severity: Minor
              Found in commands/cats/src/index.js - About 1 hr to fix

                Function handleMessage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    async handleMessage (message) {
                        // Prevent bots talk
                        if (message.author.bot) {
                            return;
                        }
                Severity: Minor
                Found in core/src/bot.js - About 45 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function constructor has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    constructor (options = {}) {
                        super(Object.assign({
                            name: 'joke',
                            description: 'Get some bot humor'
                        }, options));
                Severity: Minor
                Found in commands/joke/src/index.js - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Similar blocks of code found in 5 locations. Consider refactoring.
                Open

                    constructor (options = {}) {
                        super(Object.assign({
                            name: 'ping',
                            alias: 'pong',
                            description: 'Measures the latency of the bot'
                Severity: Major
                Found in commands/ping/src/index.js and 4 other locations - About 35 mins to fix
                commands/cats/src/index.js on lines 6..12
                commands/memberage/src/index.js on lines 19..25
                commands/minesweeper/src/index.js on lines 5..11
                commands/roll/src/index.js on lines 5..11

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 46.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 5 locations. Consider refactoring.
                Open

                    constructor (options = {}) {
                        super(Object.assign({
                            name: 'cats',
                            alias: 'cat',
                            description: 'Get an image of our overlords'
                Severity: Major
                Found in commands/cats/src/index.js and 4 other locations - About 35 mins to fix
                commands/memberage/src/index.js on lines 19..25
                commands/minesweeper/src/index.js on lines 5..11
                commands/ping/src/index.js on lines 4..10
                commands/roll/src/index.js on lines 5..11

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 46.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 5 locations. Consider refactoring.
                Open

                    constructor (options = {}) {
                        super(Object.assign({
                            name: 'minesweeper',
                            format: '[level=normal]',
                            description: 'Play minesweeper'
                Severity: Major
                Found in commands/minesweeper/src/index.js and 4 other locations - About 35 mins to fix
                commands/cats/src/index.js on lines 6..12
                commands/memberage/src/index.js on lines 19..25
                commands/ping/src/index.js on lines 4..10
                commands/roll/src/index.js on lines 5..11

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 46.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Severity
                Category
                Status
                Source
                Language