guimc233/lgz-bot

View on GitHub

Showing 38 of 38 total issues

Method filter has a Cognitive Complexity of 79 (exceeds 20 allowed). Consider refactoring.
Open

    suspend fun filter(e: GroupMessageEvent) {
        var muted = false
        // 检查权限

        val textMessage = e.message.getPlainText()
Severity: Minor
Found in src/main/kotlin/ltd/guimc/lgzbot/listener/message/MessageFilter.kt - About 1 day 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 2 locations. Consider refactoring.
Open

    @SubCommand("spam")
    @Description("开/关刷屏检查")
    suspend fun CommandSender.iI1I1i11ii1I1i1I1i() {
        if (getGroupOrNull() == null) {
            sendMessage("请在群聊中执行该命令")
src/main/kotlin/ltd/guimc/lgzbot/command/ToggleCheckCommand.kt on lines 42..63

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 317.

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

    @SubCommand("ad")
    @Description("开/关广告检测")
    suspend fun CommandSender.iiI11i1I1i1II1i1I1ii1I1i1I1() {
        if (getGroupOrNull() == null) {
            sendMessage("请在群聊中执行该命令")
src/main/kotlin/ltd/guimc/lgzbot/command/ToggleCheckCommand.kt on lines 19..40

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 317.

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

Method filter has 111 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    suspend fun filter(e: GroupMessageEvent) {
        var muted = false
        // 检查权限

        val textMessage = e.message.getPlainText()
Severity: Major
Found in src/main/kotlin/ltd/guimc/lgzbot/listener/message/MessageFilter.kt - About 4 hrs to fix

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

        fun getJsonArray(url: String, auth: String? = null): JSONArray {
            val connection = java.net.URL(url).openConnection() as java.net.HttpURLConnection
            connection.requestMethod = "GET"
            if (auth != null) {
                val basicAuth = "Basic : " + String(Base64.getEncoder().encode(auth.toByteArray()))
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/utils/HttpUtils.kt and 1 other location - About 4 hrs to fix
    src/main/kotlin/ltd/guimc/lgzbot/utils/HttpUtils.kt on lines 17..28

    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 275.

    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

        fun getJsonObject(url: String, auth: String? = null): JSONObject {
            val connection = java.net.URL(url).openConnection() as java.net.HttpURLConnection
            connection.requestMethod = "GET"
            if (auth != null) {
                val basicAuth = "Basic : " + String(Base64.getEncoder().encode(auth.toByteArray()))
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/utils/HttpUtils.kt and 1 other location - About 4 hrs to fix
    src/main/kotlin/ltd/guimc/lgzbot/utils/HttpUtils.kt on lines 30..41

    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 275.

    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

    Method iiIiIIiII1i1I1i1I1i1II1i1I1i1I1 has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
    Open

        @Handler
        fun CommandSender.iiIiIIiII1i1I1i1I1i1II1i1I1i1I1(id: Long) = launch {
            try {
                if (bot == null) {
                    throw IllegalAccessError("请勿在控制台运行")
    Severity: Minor
    Found in src/main/kotlin/ltd/guimc/lgzbot/command/ReviewCommand.kt - About 3 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

    Method specialCheck has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        suspend fun specialCheck(e: GroupMessageEvent, textMessage: String) {
            val name = PinyinUtils.convertToPinyin(textMessage).lowercase().replace(" ", "")
            when {
                (((name.contains("chen") || name.contains("cheng") || name.contains("cen")) &&
                    (name.contains("zi") || name.contains("zhi")) &&
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/special/CZXTeacher.kt - About 2 hrs to fix

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

          @EventHandler
          suspend fun MemberUnmuteEvent.unmute() {
              if (this.operator == null) return
              this.group.sendMessage(format(UNMUTE.random(), this.member.id, this.operator!!.id))
          }
      src/main/kotlin/ltd/guimc/lgzbot/listener/multi/BakaListener.kt on lines 67..71

      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 139.

      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

          @EventHandler
          suspend fun MemberMuteEvent.mute() {
              if (this.operator == null) return
              this.group.sendMessage(format(MUTE.random(), this.member.id, this.operator!!.id))
          }
      src/main/kotlin/ltd/guimc/lgzbot/listener/multi/BakaListener.kt on lines 73..77

      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 139.

      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

      Method specialCheck has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
      Open

          suspend fun specialCheck(e: GroupMessageEvent, textMessage: String) {
              val name = PinyinUtils.convertToPinyin(textMessage).lowercase().replace(" ", "")
              when {
                  (((name.contains("chen") || name.contains("cheng") || name.contains("cen")) &&
                      (name.contains("zi") || name.contains("zhi")) &&
      Severity: Minor
      Found in src/main/kotlin/ltd/guimc/lgzbot/special/CZXTeacher.kt - 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

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

                  for (regex in regexList) {
                      i++
                      if (regex.containsMatchIn(unPeekText)) {
                          logger.info("匹配成功 在第${i}行 ${regex.find(unPeekText)?.value}")
                          return true
      Severity: Major
      Found in src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt and 1 other location - About 1 hr to fix
      src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt on lines 73..79

      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 112.

      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

                  for (regex in regexList) {
                      i++
                      if (regex.containsMatchIn(unPeekText)) {
                          logger.info("匹配成功 在第${i}行 ${regex.find(unPeekText)?.value}")
                          return true
      Severity: Major
      Found in src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt and 1 other location - About 1 hr to fix
      src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt on lines 55..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 112.

      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

      Method onMessage has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          suspend fun onMessage(event: GroupMessageEvent) {
              when(event.message.getPlainText()) {
                  "摸鱼", "摸鱼!", "摸鱼.",
                  "摸鱼!", "摸鱼。" -> {
                      try {
      Severity: Minor
      Found in src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt - About 1 hr to fix

        Method onNudge has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            suspend fun onNudge(e: NudgeEvent) {
                val from = e.from as User
                val timestamp = Instant.now().epochSecond
        
                if (e.target != e.bot) return    // 只处理对机器人的戳一戳
        Severity: Minor
        Found in src/main/kotlin/ltd/guimc/lgzbot/listener/nudge/AntiNudgeSpam.kt - About 1 hr to fix

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

                          } catch (e: Throwable) {
                              event.subject.sendMessage("处理时发生异常... \nStackTrace:")
                              event.subject.sendMessage(build2forwardMessage(e.stackTraceToString(), event.subject))
                          }
          src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt on lines 19..22
          src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt on lines 38..41

          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 97.

          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 3 locations. Consider refactoring.
          Open

                          } catch (e: Throwable) {
                              event.subject.sendMessage("处理时发生异常... \nStackTrace:")
                              event.subject.sendMessage(build2forwardMessage(e.stackTraceToString(), event.subject))
                          }
          src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt on lines 19..22
          src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt on lines 29..32

          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 97.

          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 3 locations. Consider refactoring.
          Open

                          } catch (e: Throwable) {
                              event.subject.sendMessage("处理时发生异常... \nStackTrace:")
                              event.subject.sendMessage(build2forwardMessage(e.stackTraceToString(), event.subject))
                          }
          src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt on lines 29..32
          src/main/kotlin/ltd/guimc/lgzbot/listener/message/FunListener.kt on lines 38..41

          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 97.

          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

              private fun apiObject(url: String): JSONObject = HttpUtils.getJsonObject("https://api.github.com$url", if (GithubSubConfig.key != "" ) GithubSubConfig.key else null)
          Severity: Major
          Found in src/main/kotlin/ltd/guimc/lgzbot/utils/GithubUtils.kt and 1 other location - About 1 hr to fix
          src/main/kotlin/ltd/guimc/lgzbot/utils/GithubUtils.kt on lines 32..32

          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 90.

          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

              private fun apiArray(url: String): JSONArray = HttpUtils.getJsonArray("https://api.github.com$url", if (GithubSubConfig.key != "" ) GithubSubConfig.key else null)
          Severity: Major
          Found in src/main/kotlin/ltd/guimc/lgzbot/utils/GithubUtils.kt and 1 other location - About 1 hr to fix
          src/main/kotlin/ltd/guimc/lgzbot/utils/GithubUtils.kt on lines 30..30

          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 90.

          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