guimc233/lgz-bot

View on GitHub

Showing 148 of 148 total issues

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

    private suspend fun filterImage(e: GroupMessageEvent, m: Image): Boolean {
        var muted = false
        try {
            var content = sbc2dbcCase(recognizeAndStoreImage(m.cast<Image>().queryUrl()))
                .lowercase()
Severity: Minor
Found in src/main/kotlin/ltd/guimc/lgzbot/listener/message/ImageOCRFilter.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

File MessageFilter.kt has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
 * THIS FILE IS PART OF lgz-bot PROJECT
 *
 * You must disclose the source code of your modified work and the source code you took from this project. This means you are not allowed to use code from this project (even partially) in a closed-source (or even obfuscated) application.
 * Your modified application must also be licensed under the AGPLv3.
Severity: Minor
Found in src/main/kotlin/ltd/guimc/lgzbot/listener/message/MessageFilter.kt - About 3 hrs to fix

    Method onPush has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
    Open

        suspend fun onPush(event: JSONObject) {
            val repo = event.getJSONObject("repository").getString("full_name")
            event.getJSONArray("commits").forEach { rawcommit ->
                val commit = rawcommit as JSONObject
                val author = commit.getJSONObject("author")
    Severity: Minor
    Found in src/main/kotlin/ltd/guimc/lgzbot/webhook/GithubWebHookReciver.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

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

                if (!muted && riskList.indexOf(e.sender) != -1 && RegexUtils.matchRegexPinyin(adPinyinRegex, content)) {
                    try {
                        recalledMessage++
                        e.message.recall()
                        e.group.mute(e.sender, "非法发言内容 (Risk) (图片OCR识别)")
    src/main/kotlin/ltd/guimc/lgzbot/listener/message/MessageFilter.kt on lines 195..205

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

    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

                if (!muted && riskList.indexOf(e.sender) != -1 && RegexUtils.matchRegexPinyin(adPinyinRegex, textMessage)) {
                    try {
                        recalledMessage++
                        e.message.recall()
                        e.group.mute(e.sender, "非法发言内容")
    src/main/kotlin/ltd/guimc/lgzbot/listener/message/ImageOCRFilter.kt on lines 154..164

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

    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 MemberUnmuteEvent.unmute() {
            if (!ModuleStateConfig.grouplistener) return
            if (this.group.permitteeId.hasPermission(PluginMain.quiet)) return
            if (this.operator == null) return
    src/main/kotlin/ltd/guimc/lgzbot/listener/multi/BakaListener.kt on lines 71..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 206.

    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 (!ModuleStateConfig.grouplistener) return
            if (this.group.permitteeId.hasPermission(PluginMain.quiet)) return
            if (this.operator == null) return
    src/main/kotlin/ltd/guimc/lgzbot/listener/multi/BakaListener.kt on lines 79..85

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

    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 getSeriousRegex(): Array<Regex> {
            // Read from resources regex.txt
            val regexFile = RegexUtils::class.java.getResourceAsStream("/serious.txt")
            val regexList = mutableListOf<Regex>()
            regexFile?.bufferedReader()?.use { reader ->
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt and 1 other location - About 2 hrs to fix
    src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt on lines 18..31

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

    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 getDefaultRegex(): Array<Regex> {
            // Read from resources regex.txt
            val regexFile = RegexUtils::class.java.getResourceAsStream("/regex.txt")
            val regexList = mutableListOf<Regex>()
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt and 1 other location - About 2 hrs to fix
    src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt on lines 47..59

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

    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 copyFileFromJar has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        public static synchronized void copyFileFromJar(String filePath, String aimDir, boolean load, boolean deleteOnExit) throws IOException {
    
            // 获取文件名并校验
            String[] parts = filePath.split("/");
            String filename = (parts.length > 1) ? parts[parts.length - 1] : null;
    Severity: Minor
    Found in src/main/java/io/github/mymonstercat/JarFileUtil.java - 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

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

        @EventHandler
        suspend fun MemberJoinEvent.newMember() {
            if (!ModuleStateConfig.grouplistener) return
            if (this.group.permitteeId.hasPermission(PluginMain.quiet)) return
            this.group.sendMessage(format(NEW_MEMBER.random(), this.member.id))
    src/main/kotlin/ltd/guimc/lgzbot/listener/multi/BakaListener.kt on lines 101..106

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

    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 findLibLoader has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        static LibraryLoader findLibLoader(String engine) {
            Properties props = new Properties();
            try {
                props.load(new StringReader(loaders));
    
    
    Severity: Minor
    Found in src/main/java/io/github/mymonstercat/ocr/LoadUtil.java - 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

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

        @EventHandler
        suspend fun BotUnmuteEvent.unmuteBot() {
            if (!ModuleStateConfig.grouplistener) return
            if (this.group.permitteeId.hasPermission(PluginMain.quiet)) return
            this.group.sendMessage(format(UNMUTE_TO_BOT.random(), this.operator.id))
    src/main/kotlin/ltd/guimc/lgzbot/listener/multi/BakaListener.kt on lines 87..92

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

    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

            return this.replace(" ", "")
                .replace(",", "")
                .replace(".", "")
                .replace("!", "")
                .replace("?", "")
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/utils/TextUtils.kt and 1 other location - About 1 hr to fix
    src/main/kotlin/ltd/guimc/lgzbot/utils/MojangAPIUtils.kt on lines 12..18

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

    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

            return this.replace("§0", "")
                .replace("§1", "")
                .replace("§2", "")
                .replace("§3", "")
                .replace("§4", "")
    Severity: Major
    Found in src/main/kotlin/ltd/guimc/lgzbot/utils/MojangAPIUtils.kt and 1 other location - About 1 hr to fix
    src/main/kotlin/ltd/guimc/lgzbot/utils/TextUtils.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 145.

    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 trainOn has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        public Pair<Integer, Integer> trainOn(DataSet dataSet, double learningRate) {
            int t = 0, f = 0;
            if (!(layers[layers.length - 1] instanceof JudgeLayer)) {
                throw new RuntimeException("Last layer is not output layer");
            }
    Severity: Minor
    Found in src/main/java/huzpsb/ll4j/model/Model.java - 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

    Method update has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public void update(String text) {
            text = CharUtils.regularize(text);
            LinkedList<String> engStr = new LinkedList<>();
            if (smartEnglishContext) {
                int[] charArray = text.codePoints().toArray();
    Severity: Minor
    Found in src/main/java/huzpsb/ll4j/nlp/token/TokenizerBuilder.java - About 1 hr to fix

      Method recognizeAndStoreImage has 44 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          fun recognizeAndStoreImage(imageUrl: String): String {
              try {
                  // 获取图片数据
                  val imageRaw = HttpUtils.getBytesResponse(imageUrl)
                  if (imageRaw == null) {
      Severity: Minor
      Found in src/main/kotlin/ltd/guimc/lgzbot/listener/message/ImageOCRFilter.kt - About 1 hr to fix

        Method trainAndGetWA has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public List<DataEntry> trainAndGetWA(DataSet dataSet, double learningRate) {
                LinkedList<DataEntry> entries = new LinkedList<>();
                if (!(layers[layers.length - 1] instanceof JudgeLayer)) {
                    throw new RuntimeException("Last layer is not output layer");
                }
        Severity: Minor
        Found in src/main/java/huzpsb/ll4j/model/Model.java - 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 3 locations. Consider refactoring.
        Open

                if (!cooldown.isTimePassed(user!!)) {
                    if (cooldown.shouldSendCooldownNotice(user!!)) sendMessage("你可以在 ${cooldown.getLeftTime(user!!) / 1000} 秒后继续使用该指令")
                    return@launch
                }
        Severity: Major
        Found in src/main/kotlin/ltd/guimc/lgzbot/command/FbCommand.kt and 2 other locations - About 1 hr to fix
        src/main/kotlin/ltd/guimc/lgzbot/command/HttpCatCommand.kt on lines 35..38
        src/main/kotlin/ltd/guimc/lgzbot/command/HypixelCommand.kt on lines 44..47

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

        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